refactor: rename to app theme type
This commit is contained in:
parent
fb4c12d1a5
commit
cd87829b30
|
@ -136,7 +136,7 @@ class _HomeState extends State<Home> {
|
|||
}
|
||||
|
||||
switch (Provider.of<ThemeModel>(context).theme) {
|
||||
case AppThemeMap.cupertino:
|
||||
case AppThemeType.cupertino:
|
||||
return CupertinoApp(
|
||||
home: CupertinoTheme(
|
||||
data: CupertinoThemeData(
|
||||
|
|
|
@ -16,10 +16,10 @@ class PickerItem<T> {
|
|||
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<bool> 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<T>(
|
||||
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<T>(
|
||||
case AppThemeType.cupertino:
|
||||
await showCupertinoModalPopup<void>(
|
||||
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<T>(
|
||||
context: context,
|
||||
|
|
|
@ -184,7 +184,7 @@ class _ListScaffoldState<T, K> extends State<ListScaffold<T, K>> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
switch (Provider.of<ThemeModel>(context).theme) {
|
||||
case AppThemeMap.cupertino:
|
||||
case AppThemeType.cupertino:
|
||||
List<Widget> slivers = [
|
||||
CupertinoSliverRefreshControl(onRefresh: _refresh)
|
||||
];
|
||||
|
|
|
@ -181,7 +181,7 @@ class _LongListScaffoldState<T, K> extends State<LongListScaffold<T, K>> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
switch (Provider.of<ThemeModel>(context).theme) {
|
||||
case AppThemeMap.cupertino:
|
||||
case AppThemeType.cupertino:
|
||||
List<Widget> slivers = [
|
||||
CupertinoSliverRefreshControl(onRefresh: _refresh)
|
||||
];
|
||||
|
|
|
@ -80,7 +80,7 @@ class _RefreshScaffoldState<T> extends State<RefreshScaffold<T>> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
switch (Provider.of<ThemeModel>(context).theme) {
|
||||
case AppThemeMap.cupertino:
|
||||
case AppThemeType.cupertino:
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
middle: widget.title,
|
||||
|
|
|
@ -41,7 +41,7 @@ class RefreshStatelessScaffold extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
switch (Provider.of<ThemeModel>(context).theme) {
|
||||
case AppThemeMap.cupertino:
|
||||
case AppThemeType.cupertino:
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar:
|
||||
CupertinoNavigationBar(middle: title, trailing: trailing),
|
||||
|
|
|
@ -22,7 +22,7 @@ class SimpleScaffold extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
switch (Provider.of<ThemeModel>(context).theme) {
|
||||
case AppThemeMap.cupertino:
|
||||
case AppThemeType.cupertino:
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar:
|
||||
CupertinoNavigationBar(middle: title, trailing: trailing),
|
||||
|
|
|
@ -28,20 +28,21 @@ class CodeSettingsScreen extends StatelessWidget {
|
|||
TableView(
|
||||
items: [
|
||||
TableViewItem(
|
||||
text: Text('Syntax Highlighting'),
|
||||
rightWidget: Text(codeProvider.theme),
|
||||
onTap: () {
|
||||
Provider.of<ThemeModel>(context).showPicker(
|
||||
context,
|
||||
items: CodeModel.themes
|
||||
.map((t) => PickerItem(t, text: t))
|
||||
.toList(),
|
||||
initialValue: codeProvider.theme,
|
||||
onChange: (String value) {
|
||||
Provider.of<CodeModel>(context).setTheme(value);
|
||||
},
|
||||
);
|
||||
}),
|
||||
text: Text('Syntax Highlighting'),
|
||||
rightWidget: Text(codeProvider.theme),
|
||||
onTap: () {
|
||||
Provider.of<ThemeModel>(context).showPicker(
|
||||
context,
|
||||
items: CodeModel.themes
|
||||
.map((t) => PickerItem(t, text: t))
|
||||
.toList(),
|
||||
initialValue: codeProvider.theme,
|
||||
onChange: (String value) {
|
||||
Provider.of<CodeModel>(context).setTheme(value);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
TableViewItem(
|
||||
text: Text('Font Size'),
|
||||
rightWidget: Text(codeProvider.fontSize.toString()),
|
||||
|
|
|
@ -184,7 +184,7 @@ $key: pullRequest(number: ${item.number}) {
|
|||
|
||||
Widget _buildTitle() {
|
||||
switch (Provider.of<ThemeModel>(context).theme) {
|
||||
case AppThemeMap.cupertino:
|
||||
case AppThemeType.cupertino:
|
||||
// var textStyle = DefaultTextStyle.of(context).style;
|
||||
return DefaultTextStyle(
|
||||
style: TextStyle(fontSize: 16),
|
||||
|
|
|
@ -46,7 +46,7 @@ class _SearchScreenState extends State<SearchScreen> {
|
|||
|
||||
Widget _buildInput() {
|
||||
switch (Provider.of<ThemeModel>(context).theme) {
|
||||
case AppThemeMap.cupertino:
|
||||
case AppThemeType.cupertino:
|
||||
return CupertinoTextField(
|
||||
// padding: EdgeInsets.all(10),
|
||||
placeholder: 'Type to search',
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -30,7 +30,7 @@ class ActionButton extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
switch (Provider.of<ThemeModel>(context).theme) {
|
||||
case AppThemeMap.cupertino:
|
||||
case AppThemeType.cupertino:
|
||||
return GestureDetector(
|
||||
child: Icon(iconData, size: 24),
|
||||
onTap: () async {
|
||||
|
|
|
@ -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),
|
||||
),
|
||||
),
|
||||
|
|
|
@ -12,7 +12,7 @@ class Loading extends StatelessWidget {
|
|||
// return Image.asset('images/loading.webp');
|
||||
|
||||
switch (Provider.of<ThemeModel>(context).theme) {
|
||||
case AppThemeMap.cupertino:
|
||||
case AppThemeType.cupertino:
|
||||
return CupertinoActivityIndicator(radius: 12);
|
||||
default:
|
||||
return Center(
|
||||
|
|
Loading…
Reference in New Issue