Aucune description

home_page.dart 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. import 'package:flutter/material.dart';
  2. import 'package:userstory2translate/classes/language.dart';
  3. import 'package:userstory2translate/localization/language_constants.dart';
  4. import 'package:userstory2translate/main.dart';
  5. import 'package:userstory2translate/router/route_constants.dart';
  6. class HomePage extends StatefulWidget {
  7. HomePage({Key key}) : super(key: key);
  8. @override
  9. _HomePageState createState() => _HomePageState();
  10. }
  11. class _HomePageState extends State<HomePage> {
  12. final GlobalKey<FormState> _key = GlobalKey<FormState>();
  13. void _changeLanguage(Language language) async {
  14. Locale _locale = await setLocale(language.languageCode);
  15. MyApp.setLocale(context, _locale);
  16. }
  17. void _showSuccessDialog() {
  18. showTimePicker(context: context, initialTime: TimeOfDay.now());
  19. }
  20. @override
  21. Widget build(BuildContext context) {
  22. return Scaffold(
  23. appBar: AppBar(
  24. title: Text(getTranslated(context, 'home_page')),
  25. actions: <Widget>[
  26. Padding(
  27. padding: const EdgeInsets.all(8.0),
  28. child: DropdownButton<Language>(
  29. underline: SizedBox(),
  30. icon: Icon(
  31. Icons.language,
  32. color: Colors.white,
  33. ),
  34. onChanged: (Language language) {
  35. _changeLanguage(language);
  36. },
  37. items: Language.languageList()
  38. .map<DropdownMenuItem<Language>>(
  39. (e) => DropdownMenuItem<Language>(
  40. value: e,
  41. child: Row(
  42. mainAxisAlignment: MainAxisAlignment.spaceAround,
  43. children: <Widget>[
  44. Text(
  45. e.flag,
  46. style: TextStyle(fontSize: 30),
  47. ),
  48. Text(e.name)
  49. ],
  50. ),
  51. ),
  52. )
  53. .toList(),
  54. ),
  55. ),
  56. ],
  57. ),
  58. drawer: Drawer(
  59. child: _drawerList(),
  60. ),
  61. body: Container(
  62. padding: EdgeInsets.all(20),
  63. child: _mainForm(context),
  64. ),
  65. );
  66. }
  67. Form _mainForm(BuildContext context) {
  68. return Form(
  69. key: _key,
  70. child: Column(
  71. children: <Widget>[
  72. Container(
  73. height: MediaQuery.of(context).size.height / 4,
  74. child: Center(
  75. child: Text(
  76. getTranslated(context, 'personal_information'),
  77. // DemoLocalization.of(context).translate('personal_information'),
  78. textAlign: TextAlign.center,
  79. style: TextStyle(
  80. fontSize: 30,
  81. fontWeight: FontWeight.bold,
  82. ),
  83. ),
  84. ),
  85. ),
  86. TextFormField(
  87. validator: (val) {
  88. if (val.isEmpty) {
  89. return getTranslated(context, 'required_field');
  90. // return DemoLocalization.of(context).translate('required_fiedl');
  91. }
  92. return null;
  93. },
  94. decoration: InputDecoration(
  95. border: OutlineInputBorder(),
  96. labelText: getTranslated(context, 'name'),
  97. hintText: getTranslated(context, 'name_hint'),
  98. ),
  99. ),
  100. SizedBox(
  101. height: 10,
  102. ),
  103. TextFormField(
  104. validator: (val) {
  105. if (val.isEmpty) {
  106. return getTranslated(context, 'required_field');
  107. }
  108. return null;
  109. },
  110. decoration: InputDecoration(
  111. border: OutlineInputBorder(),
  112. labelText: getTranslated(context, 'email'),
  113. hintText: getTranslated(context, 'email_hint'),
  114. ),
  115. ),
  116. SizedBox(
  117. height: 10,
  118. ),
  119. TextFormField(
  120. decoration: InputDecoration(
  121. border: OutlineInputBorder(),
  122. hintText: getTranslated(context, 'date_of_birth')),
  123. onTap: () async {
  124. FocusScope.of(context).requestFocus(FocusNode());
  125. await showDatePicker(
  126. context: context,
  127. initialDate: DateTime.now(),
  128. firstDate: DateTime(DateTime.now().year),
  129. lastDate: DateTime(DateTime.now().year + 20),
  130. );
  131. },
  132. ),
  133. SizedBox(
  134. height: 10,
  135. ),
  136. MaterialButton(
  137. onPressed: () {
  138. if (_key.currentState.validate()) {
  139. _showSuccessDialog();
  140. }
  141. },
  142. height: 50,
  143. shape: StadiumBorder(),
  144. color: Theme.of(context).primaryColor,
  145. child: Center(
  146. child: Text(
  147. getTranslated(context, 'submit_info'),
  148. style: TextStyle(color: Colors.white, fontSize: 20),
  149. ),
  150. ),
  151. )
  152. ],
  153. ),
  154. );
  155. }
  156. Container _drawerList() {
  157. TextStyle _textStyle = TextStyle(
  158. color: Colors.white,
  159. fontSize: 24,
  160. );
  161. return Container(
  162. color: Theme.of(context).primaryColor,
  163. child: ListView(
  164. padding: EdgeInsets.zero,
  165. children: <Widget>[
  166. DrawerHeader(
  167. child: Container(
  168. height: 100,
  169. child: CircleAvatar(),
  170. ),
  171. ),
  172. ListTile(
  173. leading: Icon(
  174. Icons.info,
  175. color: Colors.white,
  176. size: 30,
  177. ),
  178. title: Text(
  179. getTranslated(context, 'about_us'),
  180. style: _textStyle,
  181. ),
  182. onTap: () {
  183. // To close the Drawer
  184. Navigator.pop(context);
  185. // Navigating to About Page
  186. Navigator.pushNamed(context, aboutRoute);
  187. },
  188. ),
  189. ListTile(
  190. leading: Icon(
  191. Icons.settings,
  192. color: Colors.white,
  193. size: 30,
  194. ),
  195. title: Text(
  196. getTranslated(context, 'settings'),
  197. style: _textStyle,
  198. ),
  199. onTap: () {
  200. // To close the Drawer
  201. Navigator.pop(context);
  202. // Navigating to About Page
  203. Navigator.pushNamed(context, settingsRoute);
  204. },
  205. ),
  206. ],
  207. ),
  208. );
  209. }
  210. }