diff --git a/lib/main.dart b/lib/main.dart index f2386ec..160af43 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -136,7 +136,7 @@ class _HomeState extends State { } switch (Provider.of(context).theme) { - case AppThemeMap.cupertino: + case AppThemeType.cupertino: return CupertinoApp( home: CupertinoTheme( data: CupertinoThemeData( diff --git a/lib/models/theme.dart b/lib/models/theme.dart index a5a9c41..cd33b26 100644 --- a/lib/models/theme.dart +++ b/lib/models/theme.dart @@ -16,10 +16,10 @@ class PickerItem { PickerItem(this.value, {@required this.text}); } -class AppThemeMap { +class AppThemeType { static const material = 0; static const cupertino = 1; - static const values = [AppThemeMap.material, AppThemeMap.cupertino]; + static const values = [AppThemeType.material, AppThemeType.cupertino]; } class ThemeModel with ChangeNotifier { @@ -34,12 +34,12 @@ class ThemeModel with ChangeNotifier { int v = prefs.getInt(storageKey); print('read theme: $v'); - if (AppThemeMap.values.contains(v)) { + if (AppThemeType.values.contains(v)) { _theme = v; } else if (Platform.isIOS) { - _theme = AppThemeMap.cupertino; + _theme = AppThemeType.cupertino; } else { - _theme = AppThemeMap.material; + _theme = AppThemeType.material; } notifyListeners(); @@ -61,7 +61,7 @@ class ThemeModel with ChangeNotifier { bool fullscreenDialog = false, }) { switch (theme) { - case AppThemeMap.cupertino: + case AppThemeType.cupertino: Navigator.of(context).push(CupertinoPageRoute( builder: builder, fullscreenDialog: fullscreenDialog, @@ -77,7 +77,7 @@ class ThemeModel with ChangeNotifier { Future showConfirm(BuildContext context, String text) { switch (theme) { - case AppThemeMap.cupertino: + case AppThemeType.cupertino: return showCupertinoDialog( context: context, builder: (context) { @@ -136,7 +136,7 @@ class ThemeModel with ChangeNotifier { var cancelWidget = Text('Cancel'); switch (theme) { - case AppThemeMap.cupertino: + case AppThemeType.cupertino: return showCupertinoDialog( context: context, builder: (BuildContext context) { @@ -197,28 +197,30 @@ class ThemeModel with ChangeNotifier { @required Function(T item) onChange, }) async { switch (theme) { - case AppThemeMap.cupertino: - return showCupertinoModalPopup( + case AppThemeType.cupertino: + await showCupertinoModalPopup( context: context, builder: (context) { return Container( height: 300, child: CupertinoPicker( - backgroundColor: CupertinoColors.white, - children: items.map((item) => Text(item.text)).toList(), - itemExtent: 40, - scrollController: FixedExtentScrollController( - initialItem: items - .indexWhere((item) => item.value == initialValue)), - onSelectedItemChanged: (index) { - if (_debounce?.isActive ?? false) _debounce.cancel(); - _debounce = Timer(const Duration(milliseconds: 500), () { - return onChange(items[index].value); - }); - }), + backgroundColor: CupertinoColors.white, + children: items.map((item) => Text(item.text)).toList(), + itemExtent: 40, + scrollController: FixedExtentScrollController( + initialItem: + items.indexWhere((item) => item.value == initialValue)), + onSelectedItemChanged: (index) { + if (_debounce?.isActive ?? false) _debounce.cancel(); + _debounce = Timer(const Duration(milliseconds: 500), () { + return onChange(items[index].value); + }); + }, + ), ); }, ); + break; default: final value = await showMenu( context: context, diff --git a/lib/scaffolds/list.dart b/lib/scaffolds/list.dart index e3e8a08..06c9c83 100644 --- a/lib/scaffolds/list.dart +++ b/lib/scaffolds/list.dart @@ -184,7 +184,7 @@ class _ListScaffoldState extends State> { @override Widget build(BuildContext context) { switch (Provider.of(context).theme) { - case AppThemeMap.cupertino: + case AppThemeType.cupertino: List slivers = [ CupertinoSliverRefreshControl(onRefresh: _refresh) ]; diff --git a/lib/scaffolds/long_list.dart b/lib/scaffolds/long_list.dart index df98502..e6d255b 100644 --- a/lib/scaffolds/long_list.dart +++ b/lib/scaffolds/long_list.dart @@ -181,7 +181,7 @@ class _LongListScaffoldState extends State> { @override Widget build(BuildContext context) { switch (Provider.of(context).theme) { - case AppThemeMap.cupertino: + case AppThemeType.cupertino: List slivers = [ CupertinoSliverRefreshControl(onRefresh: _refresh) ]; diff --git a/lib/scaffolds/refresh.dart b/lib/scaffolds/refresh.dart index 2fc4f4e..b04325f 100644 --- a/lib/scaffolds/refresh.dart +++ b/lib/scaffolds/refresh.dart @@ -80,7 +80,7 @@ class _RefreshScaffoldState extends State> { @override Widget build(BuildContext context) { switch (Provider.of(context).theme) { - case AppThemeMap.cupertino: + case AppThemeType.cupertino: return CupertinoPageScaffold( navigationBar: CupertinoNavigationBar( middle: widget.title, diff --git a/lib/scaffolds/refresh_stateless.dart b/lib/scaffolds/refresh_stateless.dart index 7e214e8..8e47431 100644 --- a/lib/scaffolds/refresh_stateless.dart +++ b/lib/scaffolds/refresh_stateless.dart @@ -41,7 +41,7 @@ class RefreshStatelessScaffold extends StatelessWidget { @override Widget build(BuildContext context) { switch (Provider.of(context).theme) { - case AppThemeMap.cupertino: + case AppThemeType.cupertino: return CupertinoPageScaffold( navigationBar: CupertinoNavigationBar(middle: title, trailing: trailing), diff --git a/lib/scaffolds/simple.dart b/lib/scaffolds/simple.dart index 0c7861b..df9f354 100644 --- a/lib/scaffolds/simple.dart +++ b/lib/scaffolds/simple.dart @@ -22,7 +22,7 @@ class SimpleScaffold extends StatelessWidget { @override Widget build(BuildContext context) { switch (Provider.of(context).theme) { - case AppThemeMap.cupertino: + case AppThemeType.cupertino: return CupertinoPageScaffold( navigationBar: CupertinoNavigationBar(middle: title, trailing: trailing), diff --git a/lib/screens/code_settings.dart b/lib/screens/code_settings.dart index 4ab48f5..3dc94f6 100644 --- a/lib/screens/code_settings.dart +++ b/lib/screens/code_settings.dart @@ -28,20 +28,21 @@ class CodeSettingsScreen extends StatelessWidget { TableView( items: [ TableViewItem( - text: Text('Syntax Highlighting'), - rightWidget: Text(codeProvider.theme), - onTap: () { - Provider.of(context).showPicker( - context, - items: CodeModel.themes - .map((t) => PickerItem(t, text: t)) - .toList(), - initialValue: codeProvider.theme, - onChange: (String value) { - Provider.of(context).setTheme(value); - }, - ); - }), + text: Text('Syntax Highlighting'), + rightWidget: Text(codeProvider.theme), + onTap: () { + Provider.of(context).showPicker( + context, + items: CodeModel.themes + .map((t) => PickerItem(t, text: t)) + .toList(), + initialValue: codeProvider.theme, + onChange: (String value) { + Provider.of(context).setTheme(value); + }, + ); + }, + ), TableViewItem( text: Text('Font Size'), rightWidget: Text(codeProvider.fontSize.toString()), diff --git a/lib/screens/notifications.dart b/lib/screens/notifications.dart index 80fdf78..c3c386d 100644 --- a/lib/screens/notifications.dart +++ b/lib/screens/notifications.dart @@ -184,7 +184,7 @@ $key: pullRequest(number: ${item.number}) { Widget _buildTitle() { switch (Provider.of(context).theme) { - case AppThemeMap.cupertino: + case AppThemeType.cupertino: // var textStyle = DefaultTextStyle.of(context).style; return DefaultTextStyle( style: TextStyle(fontSize: 16), diff --git a/lib/screens/search.dart b/lib/screens/search.dart index 16ef9f6..8d93136 100644 --- a/lib/screens/search.dart +++ b/lib/screens/search.dart @@ -46,7 +46,7 @@ class _SearchScreenState extends State { Widget _buildInput() { switch (Provider.of(context).theme) { - case AppThemeMap.cupertino: + case AppThemeType.cupertino: return CupertinoTextField( // padding: EdgeInsets.all(10), placeholder: 'Type to search', diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart index e0569c0..8767910 100644 --- a/lib/screens/settings.dart +++ b/lib/screens/settings.dart @@ -38,10 +38,10 @@ class SettingsScreen extends StatelessWidget { TableViewItem( text: Text('Material'), rightWidget: _buildRightWidget( - themeProvider.theme == AppThemeMap.material), + themeProvider.theme == AppThemeType.material), onTap: () { - if (themeProvider.theme != AppThemeMap.material) { - themeProvider.setTheme(AppThemeMap.material); + if (themeProvider.theme != AppThemeType.material) { + themeProvider.setTheme(AppThemeType.material); } }, hideRightChevron: true, @@ -49,10 +49,10 @@ class SettingsScreen extends StatelessWidget { TableViewItem( text: Text('Cupertino'), rightWidget: _buildRightWidget( - themeProvider.theme == AppThemeMap.cupertino), + themeProvider.theme == AppThemeType.cupertino), onTap: () { - if (themeProvider.theme != AppThemeMap.cupertino) { - themeProvider.setTheme(AppThemeMap.cupertino); + if (themeProvider.theme != AppThemeType.cupertino) { + themeProvider.setTheme(AppThemeType.cupertino); } }, hideRightChevron: true, diff --git a/lib/widgets/action.dart b/lib/widgets/action.dart index 0aac5be..eabb981 100644 --- a/lib/widgets/action.dart +++ b/lib/widgets/action.dart @@ -30,7 +30,7 @@ class ActionButton extends StatelessWidget { @override Widget build(BuildContext context) { switch (Provider.of(context).theme) { - case AppThemeMap.cupertino: + case AppThemeType.cupertino: return GestureDetector( child: Icon(iconData, size: 24), onTap: () async { diff --git a/lib/widgets/link.dart b/lib/widgets/link.dart index 7967418..6dce28e 100644 --- a/lib/widgets/link.dart +++ b/lib/widgets/link.dart @@ -67,7 +67,7 @@ class Link extends StatelessWidget { child: InkWell( child: child, splashColor: - theme == AppThemeMap.cupertino ? Colors.transparent : null, + theme == AppThemeType.cupertino ? Colors.transparent : null, onTap: () => _onTap(context, theme), ), ), diff --git a/lib/widgets/loading.dart b/lib/widgets/loading.dart index 3d829c1..5c75462 100644 --- a/lib/widgets/loading.dart +++ b/lib/widgets/loading.dart @@ -12,7 +12,7 @@ class Loading extends StatelessWidget { // return Image.asset('images/loading.webp'); switch (Provider.of(context).theme) { - case AppThemeMap.cupertino: + case AppThemeType.cupertino: return CupertinoActivityIndicator(radius: 12); default: return Center(