Skip to content

Commit

Permalink
add search section
Browse files Browse the repository at this point in the history
  • Loading branch information
ksh-b committed Mar 10, 2024
1 parent 31c5506 commit 535a75b
Showing 1 changed file with 159 additions and 98 deletions.
257 changes: 159 additions & 98 deletions lib/pages/settings.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -13,6 +15,156 @@ class SettingsPage extends StatefulWidget {

class _SettingsPageState extends State<SettingsPage> {

List<Widget> 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<String>(
value: Store.themeColorSetting,
onChanged: (String? color) {
if(color!=null) {
Store.themeColorSetting = color;
}
},
items: ThemeProvider.colors.keys.map<DropdownMenuItem<String>>((String color) {
return DropdownMenuItem<String>(
value: color,
child: Text(color),
);
}).toList(),
),
),
SizedBox(height: 20),
];
}

List<Widget> articleSection() {
return [
Text(
'Article',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
ListTile(
title: Text('Load images'),
trailing: DropdownButton<String>(
value: Store.loadImagesSetting,
onChanged: (String? option) {
if(option!=null) {
Store.loadImagesSetting = option;
}
},
items: Store.loadImagesValues.map<DropdownMenuItem<String>>((String option) {
return DropdownMenuItem<String>(
value: option,
child: Text(option),
);
}).toList(),
),
),
ListTile(
title: Text('Redirection'),
subtitle: Text('Alternate URLs (Long tap)'),
trailing: DropdownButton<String>(
value: Store.ladderSetting,
onChanged: (String? option) {
if(option!=null) {
Store.ladderSetting = option;
}
},
items: Store.ladders.keys.map<DropdownMenuItem<String>>((String option) {
return DropdownMenuItem<String>(
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<String>(
value: Store.language,
onChanged: Store.translate? (String? option) {
if(option!=null) {
Store.languageSetting = option;
}
}:null,
items: SimplyTranslate().languages.keys.map<DropdownMenuItem<String>>((String option) {
return DropdownMenuItem<String>(
value: option,
child: Text(option),
);
}).toList(),
),
),
SizedBox(height: 20),
];
}


List<Widget> searchSection() {
return [
Text(
'Search',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
ListTile(
title: Text('Suggestions provider'),
trailing: DropdownButton<String>(
value: Store.trendsProviderSetting,
onChanged: (String? option) {
if(option!=null) {
Store.trendsProviderSetting = option;
}
},
items: trends.keys.map<DropdownMenuItem<String>>((String option) {
return DropdownMenuItem<String>(
value: option,
child: Text(option),
);
}).toList(),
),
),
Store.trendsProviderSetting=="Google"?ListTile(
leading: Icon(Icons.location_on_rounded),
trailing: DropdownButton<String>(
value: Store.countrySetting,
onChanged: (String? option) {
if(option!=null) {
Store.countrySetting = option;
}
},
items: countryCodes.keys.map<DropdownMenuItem<String>>((String option) {
return DropdownMenuItem<String>(
value: option,
child: Text(option),
);
}).toList(),
),
):SizedBox.shrink(),
SizedBox(height: 20),
];
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -24,104 +176,13 @@ class _SettingsPageState extends State<SettingsPage> {
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<String>(
value: Store.themeColorSetting,
onChanged: (String? color) {
if(color!=null) {
Store.themeColorSetting = color;
}
},
items: ThemeProvider.colors.keys.map<DropdownMenuItem<String>>((String color) {
return DropdownMenuItem<String>(
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<String>(
value: Store.loadImagesSetting,
onChanged: (String? option) {
if(option!=null) {
Store.loadImagesSetting = option;
}
},
items: Store.loadImagesValues.map<DropdownMenuItem<String>>((String option) {
return DropdownMenuItem<String>(
value: option,
child: Text(option),
);
}).toList(),
),
),
ListTile(
title: Text('Redirection'),
subtitle: Text('Alternate URLs (Long tap)'),
trailing: DropdownButton<String>(
value: Store.ladderSetting,
onChanged: (String? option) {
if(option!=null) {
Store.ladderSetting = option;
}
},
items: Store.ladders.keys.map<DropdownMenuItem<String>>((String option) {
return DropdownMenuItem<String>(
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<String>(
value: Store.language,
onChanged: Store.translate? (String? option) {
if(option!=null) {
Store.languageSetting = option;
}
}:null,
items: SimplyTranslate().languages.keys.map<DropdownMenuItem<String>>((String option) {
return DropdownMenuItem<String>(
value: option,
child: Text(option),
);
}).toList(),
),
),
],
return ListView(
children: List<Widget>.of(
themeSection() +
articleSection() +
searchSection() +
[]
),
);
},
),
Expand Down

0 comments on commit 535a75b

Please sign in to comment.