Skip to content

Instantly share code, notes, and snippets.

@podcoder
Last active April 1, 2020 08:06
Show Gist options
  • Save podcoder/5b3dee6db87b842a7155b67327ba7dfd to your computer and use it in GitHub Desktop.
Save podcoder/5b3dee6db87b842a7155b67327ba7dfd to your computer and use it in GitHub Desktop.
Home page
import 'package:flutter/material.dart';
import 'package:flutter_localization_master/classes/language.dart';
import 'package:flutter_localization_master/localization/language_constants.dart';
import 'package:flutter_localization_master/main.dart';
import 'package:flutter_localization_master/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);
},
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment