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

115 lines
3.2 KiB
Dart
Raw Normal View History

2020-10-11 02:17:23 +06:30
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/main/model/main_model.dart';
2024-01-25 17:40:35 +06:30
import 'package:fcs/pages/widgets/local_app_bar.dart';
2020-10-11 02:17:23 +06:30
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:fcs/pages/main/util.dart';
typedef void ProfileCallback();
enum Currency { USD, MMK }
class ProfileCurrencyEdit extends StatefulWidget {
@override
_ProfileCurrencyEditState createState() => _ProfileCurrencyEditState();
}
class _ProfileCurrencyEditState extends State<ProfileCurrencyEdit> {
final TextEditingController nameController = new TextEditingController();
bool _loading = false;
@override
void initState() {
super.initState();
MainModel mainModel = Provider.of<MainModel>(context, listen: false);
2021-09-10 16:48:21 +06:30
if (mainModel.user!.preferCurrency == "MMK") {
2020-10-11 02:17:23 +06:30
_currency = Currency.MMK;
} else {
_currency = Currency.USD;
}
}
Currency _currency = Currency.USD;
@override
Widget build(BuildContext context) {
final saveBtn =
fcsButton(context, getLocalString(context, "btn.save"), callack: _save);
return LocalProgress(
inAsyncCall: _loading,
child: Scaffold(
2024-01-25 17:40:35 +06:30
appBar: LocalAppBar(
labelKey: 'profile.edit.currency.title',
backgroundColor: Colors.white,
labelColor: primaryColor,
arrowColor: primaryColor),
2020-10-11 02:17:23 +06:30
body: Column(
children: <Widget>[
InkWell(
onTap: () => setState(() {
_currency = Currency.USD;
}),
child: ListTile(
title: Text('USD'),
leading: Radio(
activeColor: primaryColor,
value: Currency.USD,
groupValue: _currency,
2021-09-10 12:00:08 +06:30
onChanged: (Currency? value) {
2024-01-25 17:40:35 +06:30
if (value != null)
setState(() {
_currency = value;
});
2020-10-11 02:17:23 +06:30
},
),
),
),
InkWell(
onTap: () => setState(() {
_currency = Currency.MMK;
}),
child: ListTile(
title: const Text('MMK'),
leading: Radio(
activeColor: primaryColor,
value: Currency.MMK,
groupValue: _currency,
2021-09-10 12:00:08 +06:30
onChanged: (Currency? value) {
2024-01-25 17:40:35 +06:30
if (value != null)
setState(() {
_currency = value;
});
2020-10-11 02:17:23 +06:30
},
),
),
),
Padding(
padding: const EdgeInsets.all(18.0),
child: saveBtn,
),
],
),
),
);
}
_save() async {
setState(() {
_loading = true;
});
try {
await Provider.of<MainModel>(context, listen: false)
.updatePreferredCurrency(_currency.toString().split(".").last);
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_loading = false;
});
}
}
}