import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:fcs/model/language_model.dart'; import 'package:fcs/model/main_model.dart'; import 'package:fcs/fcs/common/pages/util.dart'; import 'package:fcs/widget/localization/app_translations.dart'; import 'package:fcs/widget/progress.dart'; import '../fcs/common/helpers/theme.dart'; typedef void ProfileCallback(); class ProfileEdit extends StatefulWidget { @override _ProfileEditState createState() => _ProfileEditState(); } class _ProfileEditState extends State { final TextEditingController nameController = new TextEditingController(); bool _loading = false; @override void initState() { super.initState(); MainModel mainModel = Provider.of(context, listen: false); nameController.text = mainModel.user.name; } @override Widget build(BuildContext context) { var languageModel = Provider.of(context); final name = Container( padding: EdgeInsets.only(top: 0, left: 20, right: 15, bottom: 30), child: TextFormField( controller: nameController, autofocus: true, cursorColor: primaryColor, style: textStyle, decoration: new InputDecoration( labelText: AppTranslations.of(context).text("profile.name"), labelStyle: languageModel.isEng ? labelStyle : labelStyleMM, icon: Icon( Icons.account_box, color: primaryColor, ), enabledBorder: UnderlineInputBorder( borderSide: BorderSide(color: primaryColor, width: 1.0)), focusedBorder: UnderlineInputBorder( borderSide: BorderSide(color: primaryColor, width: 1.0)), ), )); final saveBtn = Card( elevation: 23, child: ButtonTheme( minWidth: 200.0, height: 50.0, child: FlatButton.icon( onPressed: () => _save(), label: Text(AppTranslations.of(context).text("btn.save"), style: languageModel.isEng ? TextStyle( fontSize: 18.0, fontWeight: FontWeight.bold, fontStyle: FontStyle.normal) : TextStyle( fontSize: 18.0, fontWeight: FontWeight.bold, fontStyle: FontStyle.normal, fontFamily: "MyanmarUnicode")), icon: Icon( Icons.save, ), ), ), ); return LocalProgress( inAsyncCall: _loading, child: Scaffold( appBar: AppBar( title: Text( AppTranslations.of(context).text("profile.edit_title"), ), backgroundColor: primaryColor, ), body: Column( children: [ name, saveBtn, ], ), ), ); } _save() async { setState(() { _loading = true; }); try { await Provider.of(context, listen: false) .updateProfile(nameController.text); Navigator.pop(context); setState(() { _loading = false; }); } catch (e) { showMsgDialog(context, "Error", e.toString()); } } }