Files
fcs/lib/pages/profile/profile_edit.dart

114 lines
3.3 KiB
Dart
Raw Normal View History

2020-10-07 02:33:06 +06:30
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/localization/app_translations.dart';
import 'package:fcs/pages/main/model/language_model.dart';
import 'package:fcs/pages/main/model/main_model.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/progress.dart';
2020-09-13 21:49:39 +06:30
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/pages/main/util.dart';
2020-09-13 21:49:39 +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.person,
color: primaryColor,
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: primaryColor, width: 1.0)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: primaryColor, width: 1.0)),
),
));
final saveBtn =
fcsButton(context, getLocalString(context, "btn.save"), callack: _save);
return LocalProgress(
inAsyncCall: _loading,
child: Scaffold(
appBar: AppBar(
centerTitle: true,
2020-09-18 04:04:21 +06:30
title: LocalText(
context,
"profile.edit_title",
fontSize: 20,
color: primaryColor,
2020-09-13 21:49:39 +06:30
),
backgroundColor: Colors.white,
shadowColor: Colors.transparent,
leading: IconButton(
icon: Icon(
CupertinoIcons.back,
size: 35,
color: primaryColor,
),
onPressed: () {
showConfirmDialog(context, "back.button_confirm", () {
Navigator.of(context).pop();
});
},
2020-09-13 21:49:39 +06:30
),
),
body: Column(
children: <Widget>[
Expanded(child: name),
Padding(
padding: const EdgeInsets.all(18.0),
child: saveBtn,
),
],
),
),
);
}
_save() async {
setState(() {
_loading = true;
});
try {
await Provider.of<MainModel>(context, listen: false)
2020-10-11 02:17:23 +06:30
.updateProfileName(nameController.text);
2020-09-13 21:49:39 +06:30
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_loading = false;
});
}
}
}