settings.dart 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. import 'package:dynamic_theme/dynamic_theme.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/widgets.dart';
  4. import 'package:font_awesome_flutter/font_awesome_flutter.dart';
  5. import 'package:shared_preferences/shared_preferences.dart';
  6. import 'package:trpp/data/theme.dart';
  7. import 'package:trpp/screens/note.dart';
  8. import 'package:trpp/widgets/toolbar.dart';
  9. import 'package:url_launcher/url_launcher.dart';
  10. class SettingsScreen extends StatefulWidget {
  11. SettingsScreen({Key key, this.title}) : super(key: key);
  12. final TupleTheme title;
  13. @override
  14. SettingsScreenState createState() => SettingsScreenState(title);
  15. }
  16. class SettingsScreenState extends State<SettingsScreen> {
  17. TupleTheme dropdownValue;
  18. SettingsScreenState(TupleTheme theme) {
  19. for (int i = 0; i < ThemeNames.length; ++i)
  20. if (ThemeNames[i].name == theme.name) dropdownValue = ThemeNames[i];
  21. }
  22. @override
  23. void initState() {
  24. super.initState();
  25. }
  26. saveTheme(String name) async {
  27. SharedPreferences prefs = await SharedPreferences.getInstance();
  28. await prefs.setString('theme', name);
  29. }
  30. @override
  31. Widget build(BuildContext context) {
  32. return Scaffold(
  33. body: SafeArea(
  34. child: Column(
  35. mainAxisSize: MainAxisSize.max,
  36. //physics: BouncingScrollPhysics(), ListView
  37. children: <Widget>[
  38. Column(
  39. //crossAxisAlignment: CrossAxisAlignment.start,
  40. mainAxisSize: MainAxisSize.min,
  41. children: <Widget>[
  42. //toolBar(),
  43. CustomToolbar(
  44. title: "Settings",
  45. ),
  46. topCard(),
  47. ],
  48. ),
  49. Align(
  50. child: Column(
  51. mainAxisSize: MainAxisSize.max,
  52. mainAxisAlignment: MainAxisAlignment.end,
  53. children: [
  54. buildCardWidget(
  55. Column(
  56. //crossAxisAlignment: CrossAxisAlignment.stretch,
  57. mainAxisSize: MainAxisSize.min,
  58. children: <Widget>[
  59. Align(
  60. child: Text('About app',
  61. style: TextStyle(
  62. fontSize: 24,
  63. color: Theme.of(context).primaryColor)),
  64. alignment: Alignment.topLeft,
  65. ),
  66. Container(
  67. height: 40,
  68. ),
  69. gitButton(),
  70. flutterLogo(),
  71. ],
  72. ),
  73. ),
  74. ],
  75. ),
  76. alignment: Alignment.bottomCenter,
  77. )
  78. ],
  79. ),
  80. ),
  81. backgroundColor: Theme.of(context).backgroundColor,
  82. );
  83. }
  84. Widget buildCardWidget(Widget child) {
  85. return Container(
  86. decoration: BoxDecoration(
  87. color: Theme.of(context).dialogBackgroundColor,
  88. borderRadius: BorderRadius.circular(16),
  89. boxShadow: [
  90. BoxShadow(
  91. offset: Offset(0, 8),
  92. color: Colors.black.withAlpha(20),
  93. blurRadius: 16)
  94. ]),
  95. margin: EdgeInsets.all(24),
  96. padding: EdgeInsets.all(16),
  97. child: child,
  98. );
  99. }
  100. Widget dropDownItem() {
  101. return DropdownButton<TupleTheme>(
  102. value: dropdownValue,
  103. icon: Icon(
  104. FontAwesomeIcons.caretDown,
  105. color: Theme.of(context).accentColor,
  106. ),
  107. iconSize: 16,
  108. elevation: 16,
  109. style: TextStyle(color: Theme.of(context).primaryColor),
  110. underline: Container(
  111. height: 2,
  112. color: Theme.of(context).accentColor,
  113. ),
  114. onChanged: (TupleTheme newValue) {
  115. setState(() {
  116. dropdownValue = newValue;
  117. DynamicTheme.of(context).setThemeData(newValue.theme);
  118. });
  119. saveTheme(newValue.name);
  120. },
  121. items: ThemeNames.map<DropdownMenuItem<TupleTheme>>((TupleTheme value) {
  122. return DropdownMenuItem<TupleTheme>(
  123. value: value,
  124. child: Text(value.name,
  125. style: TextStyle(
  126. fontSize: 16, color: Theme.of(context).primaryColor)),
  127. );
  128. }).toList(),
  129. );
  130. }
  131. Widget topCard() {
  132. return buildCardWidget(
  133. Column(
  134. crossAxisAlignment: CrossAxisAlignment.start,
  135. children: <Widget>[
  136. Text('App Theme',
  137. style: TextStyle(
  138. fontSize: 24, color: Theme.of(context).primaryColor)),
  139. Container(
  140. height: 20,
  141. ),
  142. Align(
  143. alignment: Alignment.center,
  144. child: dropDownItem(),
  145. ),
  146. ],
  147. ),
  148. );
  149. }
  150. Widget gitButton() {
  151. return Column(children: <Widget>[
  152. Center(
  153. child: Text('This app is open source!'.toUpperCase(),
  154. style: TextStyle(
  155. color: Colors.grey,
  156. fontWeight: FontWeight.w500,
  157. letterSpacing: 1)),
  158. ),
  159. Padding(
  160. padding: EdgeInsets.only(top: 4),
  161. child: Container(
  162. alignment: Alignment.center,
  163. child: OutlineButton.icon(
  164. icon: Icon(FontAwesomeIcons.link),
  165. label: Text('GITHUB',
  166. style: TextStyle(
  167. fontWeight: FontWeight.w500,
  168. letterSpacing: 1,
  169. color: Colors.grey)),
  170. shape:
  171. RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
  172. onPressed: openGitHub,
  173. ),
  174. ),
  175. ),
  176. ]);
  177. }
  178. Widget flutterLogo() {
  179. return Padding(
  180. child: Column(
  181. children: <Widget>[
  182. Center(
  183. child: Text('Made With'.toUpperCase(),
  184. style: TextStyle(
  185. color: Colors.grey,
  186. fontWeight: FontWeight.w500,
  187. letterSpacing: 1)),
  188. ),
  189. Padding(
  190. padding: const EdgeInsets.all(8.0),
  191. child: Center(
  192. child: Row(
  193. mainAxisAlignment: MainAxisAlignment.center,
  194. children: <Widget>[
  195. FlutterLogo(
  196. size: 40,
  197. ),
  198. Padding(
  199. padding: const EdgeInsets.all(8.0),
  200. child: Text(
  201. 'Flutter',
  202. ),
  203. )
  204. ],
  205. ),
  206. ),
  207. ),
  208. ],
  209. ),
  210. padding: EdgeInsets.only(top: 30.0),
  211. );
  212. }
  213. void openGitHub() {
  214. launch('https://github.com/L3odr0id/flutter_notes_app');
  215. }
  216. }