import 'package:flutter/material.dart'; import '../classes/language.dart'; import '../localization/language_constants.dart'; import '../routes/translation.dart'; import '../router/route_constants.dart'; class HomePage extends StatefulWidget { HomePage({Key key}) : super(key: key); @override _HomePageState createState() => _HomePageState(); } class _HomePageState extends State { final GlobalKey _key = GlobalKey(); void _changeLanguage(Language language) async { Locale _locale = await setLocale(language.languageCode); translation.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: [ Padding( padding: const EdgeInsets.all(8.0), child: DropdownButton( underline: SizedBox(), icon: Icon( Icons.language, color: Colors.white, ), onChanged: (Language language) { _changeLanguage(language); }, items: Language.languageList() .map>( (e) => DropdownMenuItem( value: e, child: Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ 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: [ 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: [ 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); }, ), ], ), ); } }