diff --git a/lib/pages/settings.dart b/lib/pages/settings.dart index 63afb9a..24bf12c 100644 --- a/lib/pages/settings.dart +++ b/lib/pages/settings.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:hive_flutter/adapters.dart'; import 'package:whapp/api/simplytranslate.dart'; +import 'package:whapp/model/country.dart'; +import 'package:whapp/model/trends.dart'; import 'package:whapp/utils/store.dart'; import 'package:whapp/utils/theme_provider.dart'; @@ -13,6 +15,156 @@ class SettingsPage extends StatefulWidget { class _SettingsPageState extends State { + List themeSection() { + return [ + Text( + 'Theme', + style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), + ), + SwitchListTile( + title: Text('Dark Mode'), + value: Store.darkThemeSetting, + onChanged: (value) { + Store.darkThemeSetting = value; + }, + ), + ListTile( + title: Text('Color'), + trailing: DropdownButton( + value: Store.themeColorSetting, + onChanged: (String? color) { + if(color!=null) { + Store.themeColorSetting = color; + } + }, + items: ThemeProvider.colors.keys.map>((String color) { + return DropdownMenuItem( + value: color, + child: Text(color), + ); + }).toList(), + ), + ), + SizedBox(height: 20), + ]; + } + + List articleSection() { + return [ + Text( + 'Article', + style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), + ), + ListTile( + title: Text('Load images'), + trailing: DropdownButton( + value: Store.loadImagesSetting, + onChanged: (String? option) { + if(option!=null) { + Store.loadImagesSetting = option; + } + }, + items: Store.loadImagesValues.map>((String option) { + return DropdownMenuItem( + value: option, + child: Text(option), + ); + }).toList(), + ), + ), + ListTile( + title: Text('Redirection'), + subtitle: Text('Alternate URLs (Long tap)'), + trailing: DropdownButton( + value: Store.ladderSetting, + onChanged: (String? option) { + if(option!=null) { + Store.ladderSetting = option; + } + }, + items: Store.ladders.keys.map>((String option) { + return DropdownMenuItem( + value: option, + child: Text(option), + ); + }).toList(), + ), + ), + SwitchListTile( + title: Text('Translate'), + value: Store.translate, + onChanged: (value) { + setState(() { + Store.translate = value; + }); + }, + ), + ListTile( + title: Text('Translate language'), + trailing: DropdownButton( + value: Store.language, + onChanged: Store.translate? (String? option) { + if(option!=null) { + Store.languageSetting = option; + } + }:null, + items: SimplyTranslate().languages.keys.map>((String option) { + return DropdownMenuItem( + value: option, + child: Text(option), + ); + }).toList(), + ), + ), + SizedBox(height: 20), + ]; + } + + + List searchSection() { + return [ + Text( + 'Search', + style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), + ), + ListTile( + title: Text('Suggestions provider'), + trailing: DropdownButton( + value: Store.trendsProviderSetting, + onChanged: (String? option) { + if(option!=null) { + Store.trendsProviderSetting = option; + } + }, + items: trends.keys.map>((String option) { + return DropdownMenuItem( + value: option, + child: Text(option), + ); + }).toList(), + ), + ), + Store.trendsProviderSetting=="Google"?ListTile( + leading: Icon(Icons.location_on_rounded), + trailing: DropdownButton( + value: Store.countrySetting, + onChanged: (String? option) { + if(option!=null) { + Store.countrySetting = option; + } + }, + items: countryCodes.keys.map>((String option) { + return DropdownMenuItem( + value: option, + child: Text(option), + ); + }).toList(), + ), + ):SizedBox.shrink(), + SizedBox(height: 20), + ]; + } + @override Widget build(BuildContext context) { return Scaffold( @@ -24,104 +176,13 @@ class _SettingsPageState extends State { child: ValueListenableBuilder( valueListenable: Store.settings.listenable(), builder: (context, box, child) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - 'Theme', - style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), - ), - SwitchListTile( - title: Text('Dark Mode'), - value: Store.darkThemeSetting, - onChanged: (value) { - Store.darkThemeSetting = value; - }, - ), - ListTile( - title: Text('Color'), - trailing: DropdownButton( - value: Store.themeColorSetting, - onChanged: (String? color) { - if(color!=null) { - Store.themeColorSetting = color; - } - }, - items: ThemeProvider.colors.keys.map>((String color) { - return DropdownMenuItem( - value: color, - child: Text(color), - ); - }).toList(), - ), - ), - SizedBox(height: 20), - Text( - 'Article', - style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), - ), - ListTile( - title: Text('Load images'), - trailing: DropdownButton( - value: Store.loadImagesSetting, - onChanged: (String? option) { - if(option!=null) { - Store.loadImagesSetting = option; - } - }, - items: Store.loadImagesValues.map>((String option) { - return DropdownMenuItem( - value: option, - child: Text(option), - ); - }).toList(), - ), - ), - ListTile( - title: Text('Redirection'), - subtitle: Text('Alternate URLs (Long tap)'), - trailing: DropdownButton( - value: Store.ladderSetting, - onChanged: (String? option) { - if(option!=null) { - Store.ladderSetting = option; - } - }, - items: Store.ladders.keys.map>((String option) { - return DropdownMenuItem( - value: option, - child: Text(option), - ); - }).toList(), - ), - ), - SwitchListTile( - title: Text('Translate'), - value: Store.translate, - onChanged: (value) { - setState(() { - Store.translate = value; - }); - }, - ), - ListTile( - title: Text('Translate language'), - trailing: DropdownButton( - value: Store.language, - onChanged: Store.translate? (String? option) { - if(option!=null) { - Store.languageSetting = option; - } - }:null, - items: SimplyTranslate().languages.keys.map>((String option) { - return DropdownMenuItem( - value: option, - child: Text(option), - ); - }).toList(), - ), - ), - ], + return ListView( + children: List.of( + themeSection() + + articleSection() + + searchSection() + + [] + ), ); }, ),