settings.dart 6.6 KB

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