Files
fcs/lib/pages/profile/profile_currency_edit.dart
2024-01-25 17:40:35 +06:30

115 lines
3.2 KiB
Dart

import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/main/model/main_model.dart';
import 'package:fcs/pages/widgets/local_app_bar.dart';
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);
if (mainModel.user!.preferCurrency == "MMK") {
_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(
appBar: LocalAppBar(
labelKey: 'profile.edit.currency.title',
backgroundColor: Colors.white,
labelColor: primaryColor,
arrowColor: primaryColor),
body: Column(
children: <Widget>[
InkWell(
onTap: () => setState(() {
_currency = Currency.USD;
}),
child: ListTile(
title: Text('USD'),
leading: Radio(
activeColor: primaryColor,
value: Currency.USD,
groupValue: _currency,
onChanged: (Currency? value) {
if (value != null)
setState(() {
_currency = value;
});
},
),
),
),
InkWell(
onTap: () => setState(() {
_currency = Currency.MMK;
}),
child: ListTile(
title: const Text('MMK'),
leading: Radio(
activeColor: primaryColor,
value: Currency.MMK,
groupValue: _currency,
onChanged: (Currency? value) {
if (value != null)
setState(() {
_currency = value;
});
},
),
),
),
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;
});
}
}
}