Merge pull request #143 from cypherstack/ui-fixes

UI fixes
This commit is contained in:
Rylee Davis 2022-10-17 14:31:06 -06:00 committed by GitHub
commit 1b69b601cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 217 additions and 240 deletions

View file

@ -16,15 +16,13 @@ import 'package:stackwallet/providers/ui/unread_notifications_provider.dart';
import 'package:stackwallet/services/exchange/exchange_data_loading_service.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/utilities/prefs.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/stack_dialog.dart';
import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/utilities/prefs.dart';
class HomeView extends ConsumerStatefulWidget {
const HomeView({Key? key}) : super(key: key);
@ -45,7 +43,7 @@ class _HomeViewState extends ConsumerState<HomeView> {
bool _exitEnabled = false;
final _cnLoadingService = ExchangeDataLoadingService();
final _exchangeDataLoadingService = ExchangeDataLoadingService();
Future<bool> _onWillPop() async {
// go to home view when tapping back on the main exchange view
@ -88,7 +86,7 @@ class _HomeViewState extends ConsumerState<HomeView> {
//
final externalCalls = Prefs.instance.externalCalls;
if (externalCalls) {
_cnLoadingService.loadAll(ref);
_exchangeDataLoadingService.loadAll(ref);
} else {
Logging.instance.log("User does not want to use external calls",
level: LogLevel.Info);
@ -290,6 +288,9 @@ class _HomeViewState extends ConsumerState<HomeView> {
_ref.listen(homeViewPageIndexStateProvider,
(previous, next) {
if (next is int) {
if (next == 1) {
_loadCNData();
}
if (next >= 0 && next <= 1) {
_pageController.animateToPage(
next,

View file

@ -1,5 +1,3 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/providers/providers.dart';
@ -8,8 +6,6 @@ import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/stack_dialog.dart';
import 'package:stackwallet/utilities/prefs.dart';
class HomeViewButtonBar extends ConsumerStatefulWidget {
const HomeViewButtonBar({Key? key}) : super(key: key);
@ -18,8 +14,8 @@ class HomeViewButtonBar extends ConsumerStatefulWidget {
}
class _HomeViewButtonBarState extends ConsumerState<HomeViewButtonBar> {
final DateTime _lastRefreshed = DateTime.now();
final Duration _refreshInterval = const Duration(hours: 1);
// final DateTime _lastRefreshed = DateTime.now();
// final Duration _refreshInterval = const Duration(hours: 1);
@override
void initState() {
@ -104,34 +100,14 @@ class _HomeViewButtonBarState extends ConsumerState<HomeViewButtonBar> {
if (selectedIndex != 1) {
ref.read(homeViewPageIndexStateProvider.state).state = 1;
}
DateTime now = DateTime.now();
final _cnLoadingService = ExchangeDataLoadingService();
final externalCalls = Prefs.instance.externalCalls;
if (!externalCalls) {
// DateTime now = DateTime.now();
if (ref.read(prefsChangeNotifierProvider).externalCalls) {
print("loading?");
unawaited(_cnLoadingService.loadAll(ref));
}
if (now.difference(_lastRefreshed) > _refreshInterval) {
// bool okPressed = false;
// showDialog<dynamic>(
// context: context,
// barrierDismissible: false,
// builder: (_) => const StackDialog(
// // builder: (_) => StackOkDialog(
// title: "Refreshing ChangeNOW data",
// message: "This may take a while",
// // onOkPressed: (value) {
// // if (value == "OK") {
// // okPressed = true;
// // }
// // },
// ),
// );
await ExchangeDataLoadingService().loadAll(ref);
// if (!okPressed && mounted) {
// Navigator.of(context).pop();
// }
}
// if (now.difference(_lastRefreshed) > _refreshInterval) {
// await ExchangeDataLoadingService().loadAll(ref);
// }
},
child: Text(
"Exchange",

View file

@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart';
import 'package:stackwallet/hive/db.dart';
import 'package:stackwallet/pages/pinpad_views/create_pin_view.dart';
import 'package:stackwallet/pages_desktop_specific/create_password/create_password_view.dart';
import 'package:stackwallet/providers/global/prefs_provider.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart';
@ -12,9 +12,6 @@ import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart';
import 'package:stackwallet/providers/global/prefs_provider.dart';
import 'package:stackwallet/utilities/prefs.dart';
class StackPrivacyCalls extends ConsumerStatefulWidget {
const StackPrivacyCalls({
Key? key,
@ -31,19 +28,19 @@ class StackPrivacyCalls extends ConsumerStatefulWidget {
class _StackPrivacyCalls extends ConsumerState<StackPrivacyCalls> {
late final bool isDesktop;
bool isEasy = Prefs.instance.externalCalls;
final PageController _pageController =
PageController(initialPage: 0, keepPage: true);
late bool isEasy;
late bool infoToggle;
@override
void initState() {
isDesktop = Util.isDesktop;
isEasy = ref.read(prefsChangeNotifierProvider).externalCalls;
infoToggle = isEasy;
super.initState();
}
@override
void dispose() {
_pageController.dispose();
super.dispose();
}
@ -59,11 +56,7 @@ class _StackPrivacyCalls extends ConsumerState<StackPrivacyCalls> {
),
),
body: SafeArea(
child: PageView(
controller: _pageController,
physics: const NeverScrollableScrollPhysics(),
children: [
Padding(
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 40, 0, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
@ -82,11 +75,19 @@ class _StackPrivacyCalls extends ConsumerState<StackPrivacyCalls> {
const SizedBox(
height: 36,
),
const Padding(
padding: EdgeInsets.symmetric(
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16,
),
child: PrivacyToggle(),
child: PrivacyToggle(
externalCallsEnabled: isEasy,
onChanged: (externalCalls) {
isEasy = externalCalls;
setState(() {
infoToggle = isEasy;
});
},
),
),
const SizedBox(
height: 36,
@ -98,13 +99,9 @@ class _StackPrivacyCalls extends ConsumerState<StackPrivacyCalls> {
child: RichText(
textAlign: TextAlign.left,
text: TextSpan(
style: STextStyles.label(context)
.copyWith(fontSize: 12.0),
children: ref.watch(
prefsChangeNotifierProvider.select(
(value) => value.externalCalls,
),
)
style:
STextStyles.label(context).copyWith(fontSize: 12.0),
children: infoToggle
? [
const TextSpan(
text:
@ -159,12 +156,24 @@ class _StackPrivacyCalls extends ConsumerState<StackPrivacyCalls> {
Expanded(
child: ContinueButton(
isDesktop: isDesktop,
isSettings: widget.isSettings,
isEasy: ref.watch(
prefsChangeNotifierProvider.select(
(value) => value.externalCalls,
),
),
label: !widget.isSettings ? "Continue" : "Save changes",
onPressed: () {
ref.read(prefsChangeNotifierProvider).externalCalls =
isEasy;
if (!widget.isSettings) {
if (isDesktop) {
Navigator.of(context).pushNamed(
CreatePasswordView.routeName,
);
} else {
Navigator.of(context).pushNamed(
CreatePinView.routeName,
);
}
} else {
Navigator.pop(context);
}
},
),
),
],
@ -173,21 +182,35 @@ class _StackPrivacyCalls extends ConsumerState<StackPrivacyCalls> {
],
),
),
],
),
),
);
}
}
class PrivacyToggle extends ConsumerStatefulWidget {
const PrivacyToggle({Key? key}) : super(key: key);
class PrivacyToggle extends StatefulWidget {
const PrivacyToggle({
Key? key,
required this.externalCallsEnabled,
this.onChanged,
}) : super(key: key);
final bool externalCallsEnabled;
final void Function(bool)? onChanged;
@override
ConsumerState<PrivacyToggle> createState() => _PrivacyToggleState();
State<PrivacyToggle> createState() => _PrivacyToggleState();
}
class _PrivacyToggleState extends ConsumerState<PrivacyToggle> {
class _PrivacyToggleState extends State<PrivacyToggle> {
late bool externalCallsEnabled;
@override
void initState() {
// initial toggle state
externalCallsEnabled = widget.externalCallsEnabled;
super.initState();
}
@override
Widget build(BuildContext context) {
return Row(
@ -196,11 +219,7 @@ class _PrivacyToggleState extends ConsumerState<PrivacyToggle> {
child: RawMaterialButton(
fillColor: Theme.of(context).extension<StackColors>()!.popupBG,
shape: RoundedRectangleBorder(
side: !ref.watch(
prefsChangeNotifierProvider.select(
(value) => value.externalCalls,
),
)
side: !externalCallsEnabled
? BorderSide.none
: BorderSide(
color: Theme.of(context)
@ -213,7 +232,12 @@ class _PrivacyToggleState extends ConsumerState<PrivacyToggle> {
),
),
onPressed: () {
ref.read(prefsChangeNotifierProvider).externalCalls = true;
setState(() {
// update toggle state
externalCallsEnabled = true;
});
// call callback with newly set value
widget.onChanged?.call(externalCallsEnabled);
},
child: Padding(
padding: const EdgeInsets.all(
@ -244,11 +268,7 @@ class _PrivacyToggleState extends ConsumerState<PrivacyToggle> {
),
],
),
if (ref.watch(
prefsChangeNotifierProvider.select(
(value) => value.externalCalls,
),
))
if (externalCallsEnabled)
Positioned(
top: 4,
right: 4,
@ -261,11 +281,7 @@ class _PrivacyToggleState extends ConsumerState<PrivacyToggle> {
.infoItemIcons,
),
),
if (!ref.watch(
prefsChangeNotifierProvider.select(
(value) => value.externalCalls,
),
))
if (!externalCallsEnabled)
Positioned(
top: 4,
right: 4,
@ -293,11 +309,7 @@ class _PrivacyToggleState extends ConsumerState<PrivacyToggle> {
elevation: 0,
fillColor: Theme.of(context).extension<StackColors>()!.popupBG,
shape: RoundedRectangleBorder(
side: ref.watch(
prefsChangeNotifierProvider.select(
(value) => value.externalCalls,
),
)
side: externalCallsEnabled
? BorderSide.none
: BorderSide(
color: Theme.of(context)
@ -310,7 +322,12 @@ class _PrivacyToggleState extends ConsumerState<PrivacyToggle> {
),
),
onPressed: () {
ref.read(prefsChangeNotifierProvider).externalCalls = false;
setState(() {
// update toggle state
externalCallsEnabled = false;
});
// call callback with newly set value
widget.onChanged?.call(externalCallsEnabled);
},
child: Padding(
padding: const EdgeInsets.all(
@ -342,11 +359,7 @@ class _PrivacyToggleState extends ConsumerState<PrivacyToggle> {
),
],
),
if (!ref.watch(
prefsChangeNotifierProvider.select(
(value) => value.externalCalls,
),
))
if (!externalCallsEnabled)
Positioned(
top: 4,
right: 4,
@ -359,11 +372,7 @@ class _PrivacyToggleState extends ConsumerState<PrivacyToggle> {
.infoItemIcons,
),
),
if (ref.watch(
prefsChangeNotifierProvider.select(
(value) => value.externalCalls,
),
))
if (externalCallsEnabled)
Positioned(
top: 4,
right: 4,
@ -388,58 +397,47 @@ class _PrivacyToggleState extends ConsumerState<PrivacyToggle> {
}
}
class ContinueButton extends StatelessWidget {
const ContinueButton(
{Key? key,
class ContinueButton extends ConsumerWidget {
const ContinueButton({
Key? key,
required this.isDesktop,
required this.isSettings,
required this.isEasy})
: super(key: key);
required this.onPressed,
required this.label,
}) : super(key: key);
final String label;
final bool isDesktop;
final bool isSettings;
final bool isEasy;
final VoidCallback onPressed;
@override
Widget build(BuildContext context) {
return !isDesktop
? TextButton(
style: Theme.of(context)
.extension<StackColors>()!
.getPrimaryEnabledButtonColor(context),
onPressed: () {
Prefs.instance.externalCalls = isEasy;
if (!isSettings) {
Navigator.of(context).pushNamed(CreatePinView.routeName);
} else {
Navigator.pop(context);
}
},
child: Text(
!isSettings ? "Continue" : "Save changes",
style: STextStyles.button(context),
),
)
: SizedBox(
Widget build(BuildContext context, WidgetRef ref) {
if (isDesktop) {
return SizedBox(
width: 328,
height: 70,
child: TextButton(
style: Theme.of(context)
.extension<StackColors>()!
.getPrimaryEnabledButtonColor(context),
onPressed: () {
Prefs.instance.externalCalls = isEasy;
if (!isSettings) {
Navigator.of(context).pushNamed(CreatePinView.routeName);
}
},
onPressed: onPressed,
child: Text(
!isSettings ? "Continue" : "Save changes",
label,
style: STextStyles.button(context).copyWith(fontSize: 20),
),
),
);
} else {
return TextButton(
style: Theme.of(context)
.extension<StackColors>()!
.getPrimaryEnabledButtonColor(context),
onPressed: onPressed,
child: Text(
label,
style: STextStyles.button(context),
),
);
}
}
}

View file

@ -546,6 +546,8 @@ class Prefs extends ChangeNotifier {
boxName: DB.boxNamePrefs, key: "startupWalletId") as String?;
}
// incognito mode off by default
// allow external network calls such as exchange data and price info
bool _externalCalls = true;
bool get externalCalls => _externalCalls;