Files
fcs/lib/pages/profile_edit.dart

114 lines
3.3 KiB
Dart
Raw Normal View History

2020-05-29 07:45:27 +06:30
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:fcs/model/language_model.dart';
import 'package:fcs/model/main_model.dart';
2020-09-04 15:30:10 +06:30
import 'package:fcs/fcs/common/pages/util.dart';
2020-05-29 07:45:27 +06:30
import 'package:fcs/widget/localization/app_translations.dart';
import 'package:fcs/widget/progress.dart';
2020-09-04 15:30:10 +06:30
import '../fcs/common/helpers/theme.dart';
2020-05-29 07:45:27 +06:30
typedef void ProfileCallback();
class ProfileEdit extends StatefulWidget {
@override
_ProfileEditState createState() => _ProfileEditState();
}
class _ProfileEditState extends State<ProfileEdit> {
final TextEditingController nameController = new TextEditingController();
bool _loading = false;
@override
void initState() {
super.initState();
MainModel mainModel = Provider.of<MainModel>(context, listen: false);
nameController.text = mainModel.user.name;
}
@override
Widget build(BuildContext context) {
var languageModel = Provider.of<LanguageModel>(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: <Widget>[
name,
saveBtn,
],
),
),
);
}
_save() async {
setState(() {
_loading = true;
});
try {
await Provider.of<MainModel>(context, listen: false)
.updateProfile(nameController.text);
Navigator.pop(context);
setState(() {
_loading = false;
});
} catch (e) {
showMsgDialog(context, "Error", e.toString());
}
}
}