123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- import 'package:flutter/material.dart';
- import 'package:userstory2translate/classes/language.dart';
- import 'package:userstory2translate/localization/language_constants.dart';
- import 'package:userstory2translate/main.dart';
- import 'package:userstory2translate/router/route_constants.dart';
-
- class HomePage extends StatefulWidget {
- HomePage({Key key}) : super(key: key);
-
- @override
- _HomePageState createState() => _HomePageState();
- }
-
- class _HomePageState extends State<HomePage> {
- final GlobalKey<FormState> _key = GlobalKey<FormState>();
- void _changeLanguage(Language language) async {
- Locale _locale = await setLocale(language.languageCode);
- MyApp.setLocale(context, _locale);
- }
-
- void _showSuccessDialog() {
- showTimePicker(context: context, initialTime: TimeOfDay.now());
- }
-
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text(getTranslated(context, 'home_page')),
- actions: <Widget>[
- Padding(
- padding: const EdgeInsets.all(8.0),
- child: DropdownButton<Language>(
- underline: SizedBox(),
- icon: Icon(
- Icons.language,
- color: Colors.white,
- ),
- onChanged: (Language language) {
- _changeLanguage(language);
- },
- items: Language.languageList()
- .map<DropdownMenuItem<Language>>(
- (e) => DropdownMenuItem<Language>(
- value: e,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceAround,
- children: <Widget>[
- Text(
- e.flag,
- style: TextStyle(fontSize: 30),
- ),
- Text(e.name)
- ],
- ),
- ),
- )
- .toList(),
- ),
- ),
- ],
- ),
- drawer: Drawer(
- child: _drawerList(),
- ),
- body: Container(
- padding: EdgeInsets.all(20),
- child: _mainForm(context),
- ),
- );
- }
-
- Form _mainForm(BuildContext context) {
- return Form(
- key: _key,
- child: Column(
- children: <Widget>[
- Container(
- height: MediaQuery.of(context).size.height / 4,
- child: Center(
- child: Text(
- getTranslated(context, 'personal_information'),
- // DemoLocalization.of(context).translate('personal_information'),
- textAlign: TextAlign.center,
- style: TextStyle(
- fontSize: 30,
- fontWeight: FontWeight.bold,
- ),
- ),
- ),
- ),
- TextFormField(
- validator: (val) {
- if (val.isEmpty) {
- return getTranslated(context, 'required_field');
- // return DemoLocalization.of(context).translate('required_fiedl');
- }
- return null;
- },
- decoration: InputDecoration(
- border: OutlineInputBorder(),
- labelText: getTranslated(context, 'name'),
- hintText: getTranslated(context, 'name_hint'),
- ),
- ),
- SizedBox(
- height: 10,
- ),
- TextFormField(
- validator: (val) {
- if (val.isEmpty) {
- return getTranslated(context, 'required_field');
- }
- return null;
- },
- decoration: InputDecoration(
- border: OutlineInputBorder(),
- labelText: getTranslated(context, 'email'),
- hintText: getTranslated(context, 'email_hint'),
- ),
- ),
- SizedBox(
- height: 10,
- ),
- TextFormField(
- decoration: InputDecoration(
- border: OutlineInputBorder(),
- hintText: getTranslated(context, 'date_of_birth')),
- onTap: () async {
- FocusScope.of(context).requestFocus(FocusNode());
- await showDatePicker(
- context: context,
- initialDate: DateTime.now(),
- firstDate: DateTime(DateTime.now().year),
- lastDate: DateTime(DateTime.now().year + 20),
- );
- },
- ),
- SizedBox(
- height: 10,
- ),
- MaterialButton(
- onPressed: () {
- if (_key.currentState.validate()) {
- _showSuccessDialog();
- }
- },
- height: 50,
- shape: StadiumBorder(),
- color: Theme.of(context).primaryColor,
- child: Center(
- child: Text(
- getTranslated(context, 'submit_info'),
- style: TextStyle(color: Colors.white, fontSize: 20),
- ),
- ),
- )
- ],
- ),
- );
- }
-
- Container _drawerList() {
- TextStyle _textStyle = TextStyle(
- color: Colors.white,
- fontSize: 24,
- );
- return Container(
- color: Theme.of(context).primaryColor,
- child: ListView(
- padding: EdgeInsets.zero,
- children: <Widget>[
- DrawerHeader(
- child: Container(
- height: 100,
- child: CircleAvatar(),
- ),
- ),
- ListTile(
- leading: Icon(
- Icons.info,
- color: Colors.white,
- size: 30,
- ),
- title: Text(
- getTranslated(context, 'about_us'),
- style: _textStyle,
- ),
- onTap: () {
- // To close the Drawer
- Navigator.pop(context);
- // Navigating to About Page
- Navigator.pushNamed(context, aboutRoute);
- },
- ),
- ListTile(
- leading: Icon(
- Icons.settings,
- color: Colors.white,
- size: 30,
- ),
- title: Text(
- getTranslated(context, 'settings'),
- style: _textStyle,
- ),
- onTap: () {
- // To close the Drawer
- Navigator.pop(context);
- // Navigating to About Page
- Navigator.pushNamed(context, settingsRoute);
- },
- ),
- ],
- ),
- );
- }
- }
|