first commit
This commit is contained in:
91
lib/ui/views/app_index_tracking/app_index_tracking_view.dart
Normal file
91
lib/ui/views/app_index_tracking/app_index_tracking_view.dart
Normal file
@ -0,0 +1,91 @@
|
||||
import 'package:curreny_exchange/app/app.router.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
import 'package:stylish_bottom_bar/model/bar_items.dart';
|
||||
import 'package:stylish_bottom_bar/stylish_bottom_bar.dart';
|
||||
|
||||
import '../../../app/themes/app_colors.dart';
|
||||
import '../../../app/themes/app_text.dart';
|
||||
import './app_index_tracking_view_model.dart';
|
||||
|
||||
class AppIndexTrackingView extends StatelessWidget {
|
||||
const AppIndexTrackingView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<AppIndexTrackingViewModel>.reactive(
|
||||
viewModelBuilder: () => AppIndexTrackingViewModel(),
|
||||
onViewModelReady: (AppIndexTrackingViewModel model) async {
|
||||
await model.init();
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
AppIndexTrackingViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Center(
|
||||
child: Text(
|
||||
model.header,
|
||||
style: boldTextStyle.copyWith(
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
backgroundColor: mainColor,
|
||||
elevation: 0,
|
||||
automaticallyImplyLeading: false,
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 15),
|
||||
child: ExtendedNavigator(
|
||||
navigatorKey: StackedService.nestedNavigationKey(3),
|
||||
router: AppIndexTrackingViewRouter(),
|
||||
// initialRoute: AppIndexTrackingViewRoutes.danaSosialAdminView,
|
||||
),
|
||||
),
|
||||
bottomNavigationBar: StylishBottomBar(
|
||||
items: [
|
||||
for (var item in model.bottomNavBarList)
|
||||
BottomBarItem(
|
||||
icon: Icon(item['icon'],
|
||||
color: model.currentIndex ==
|
||||
model.bottomNavBarList.indexOf(item)
|
||||
? mainColor
|
||||
: backgroundColor),
|
||||
title: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
item['name'],
|
||||
style: regularTextStyle.copyWith(
|
||||
color: model.currentIndex ==
|
||||
model.bottomNavBarList.indexOf(item)
|
||||
? mainColor
|
||||
: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
backgroundColor:
|
||||
model.currentIndex == model.bottomNavBarList.indexOf(item)
|
||||
? Colors.white
|
||||
: Colors.grey,
|
||||
),
|
||||
],
|
||||
currentIndex: model.currentIndex,
|
||||
hasNotch: true,
|
||||
backgroundColor: mainColor,
|
||||
onTap: (value) {
|
||||
model.handleNavigation(value);
|
||||
},
|
||||
option: BubbleBarOptions(
|
||||
barStyle: BubbleBarStyle.horizotnal,
|
||||
bubbleFillStyle: BubbleFillStyle.fill,
|
||||
opacity: 0.3),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
|
||||
import '../../../app/app.locator.dart';
|
||||
import '../../../app/app.logger.dart';
|
||||
import '../../../app/app.router.dart';
|
||||
import '../../../services/my_easyloading.dart';
|
||||
|
||||
class AppIndexTrackingViewModel extends IndexTrackingViewModel {
|
||||
final log = getLogger('AppIndexTrackingViewModel');
|
||||
final _navigationService = locator<NavigationService>();
|
||||
final _easyLoading = locator<MyEasyLoading>();
|
||||
|
||||
final _bottomNavBarList = [
|
||||
{
|
||||
'name': 'Tukaran Global',
|
||||
// money icon
|
||||
'icon': Icons.attach_money,
|
||||
'header': 'TUKARAN UANG GLOBAL'
|
||||
},
|
||||
{'name': 'Input Tukaran', 'icon': Icons.money, 'header': 'INPUT TUKARAN'},
|
||||
];
|
||||
|
||||
List<Map<String, dynamic>> get bottomNavBarList => _bottomNavBarList;
|
||||
|
||||
final List<String> _views = [
|
||||
AppIndexTrackingViewRoutes.todayCurrencyView,
|
||||
AppIndexTrackingViewRoutes.customCurrencyView,
|
||||
];
|
||||
|
||||
String header = 'TUKARAN UANG GLOBAL';
|
||||
|
||||
Future<void> init() async {
|
||||
_easyLoading.showLoading();
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
_navigationService.navigateTo(
|
||||
_views[0],
|
||||
id: 3,
|
||||
);
|
||||
_easyLoading.dismissLoading();
|
||||
}
|
||||
|
||||
void handleNavigation(int index) {
|
||||
log.d("handleNavigation: $index");
|
||||
log.d("currentIndex: $currentIndex");
|
||||
|
||||
if (currentIndex == index) return;
|
||||
|
||||
setIndex(index);
|
||||
header = _bottomNavBarList[index]['header'] as String;
|
||||
_navigationService.navigateTo(
|
||||
_views[index],
|
||||
id: 3,
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,233 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
import '../../../../app/themes/app_colors.dart';
|
||||
import '../../../../app/themes/app_text.dart';
|
||||
import './custom_currency_view_model.dart';
|
||||
|
||||
class CustomCurrencyView extends StatelessWidget {
|
||||
const CustomCurrencyView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<CustomCurrencyViewModel>.reactive(
|
||||
viewModelBuilder: () => CustomCurrencyViewModel(),
|
||||
onViewModelReady: (CustomCurrencyViewModel model) async {
|
||||
await model.init();
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
CustomCurrencyViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return WillPopScope(
|
||||
onWillPop: () async {
|
||||
// model.navigationService.back();
|
||||
if (model.globalVar.backPressed == 'backNormal') {
|
||||
model.quitApp(context);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
child: Scaffold(
|
||||
body: model.conversionResultModel == null
|
||||
? const Center(
|
||||
child: Text(
|
||||
'Sila Klik Icon Untuk\nKonversi Tukaran Mata Uang',
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
)
|
||||
: const TheDataWidget(),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () {
|
||||
// model.navigationService.back();
|
||||
model.myDialog();
|
||||
},
|
||||
// icon exchange currency
|
||||
child: const Icon(Icons.swap_horiz),
|
||||
)),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TheDataWidget extends ViewModelWidget<CustomCurrencyViewModel> {
|
||||
const TheDataWidget({
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, CustomCurrencyViewModel viewModel) {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
text: 'Terakhir diperbarui : ',
|
||||
style: regularTextStyle,
|
||||
children: [
|
||||
TextSpan(
|
||||
text: viewModel.otherFunction.timeStampConverter(
|
||||
viewModel.conversionResultModel!.timeLastUpdateUnix!),
|
||||
style: boldTextStyle.copyWith(
|
||||
color: greenColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
text: 'Update berikutnya : ',
|
||||
style: regularTextStyle,
|
||||
children: [
|
||||
TextSpan(
|
||||
text: viewModel.otherFunction.timeStampConverter(
|
||||
viewModel.conversionResultModel!.timeNextUpdateUnix!),
|
||||
style: boldTextStyle.copyWith(
|
||||
color: mainColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
const Text('Mata Uang : ', style: regularTextStyle),
|
||||
const SizedBox(
|
||||
width: 3,
|
||||
),
|
||||
Image.asset(
|
||||
'assets/flags/${viewModel.currencyInfoModel!.alphabeticCode!.toLowerCase()}.png',
|
||||
width: 30,
|
||||
height: 30,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 5,
|
||||
),
|
||||
Text(
|
||||
viewModel.currencyInfoModel!.entity!,
|
||||
style: boldTextStyle.copyWith(
|
||||
color: redColor,
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
width: 3,
|
||||
),
|
||||
Text(
|
||||
'( ${viewModel.currencyInfoModel!.alphabeticCode} )',
|
||||
style: italicTextStyle.copyWith(
|
||||
color: redColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
text: 'Jumlah Tukaran : ',
|
||||
style: regularTextStyle,
|
||||
children: [
|
||||
TextSpan(
|
||||
text:
|
||||
'${viewModel.currencyInfoModel!.alphabeticCode} ${viewModel.otherFunction.commaFormat(int.parse(viewModel.nilaiTukaran!))}',
|
||||
style: boldTextStyle.copyWith(
|
||||
color: redColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
text: 'Konversi Tukaran : ',
|
||||
style: regularTextStyle,
|
||||
children: [
|
||||
TextSpan(
|
||||
text: '1 ${viewModel.currencyInfoModel!.alphabeticCode}',
|
||||
style: boldTextStyle.copyWith(
|
||||
color: redColor,
|
||||
),
|
||||
),
|
||||
const TextSpan(
|
||||
text: ' = ',
|
||||
style: regularTextStyle,
|
||||
),
|
||||
TextSpan(
|
||||
text:
|
||||
'${viewModel.conversionResultModel!.conversionRate} ${viewModel.konversiInfoModel!.alphabeticCode}',
|
||||
style: boldTextStyle.copyWith(
|
||||
color: orangeColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
const Text('Uang Konversi: ', style: regularTextStyle),
|
||||
const SizedBox(
|
||||
width: 3,
|
||||
),
|
||||
Image.asset(
|
||||
'assets/flags/${viewModel.konversiInfoModel!.alphabeticCode!.toLowerCase()}.png',
|
||||
width: 30,
|
||||
height: 30,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 5,
|
||||
),
|
||||
Text(
|
||||
viewModel.konversiInfoModel!.entity!,
|
||||
style: boldTextStyle.copyWith(
|
||||
color: orangeColor,
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
width: 3,
|
||||
),
|
||||
Text(
|
||||
'( ${viewModel.konversiInfoModel!.alphabeticCode} )',
|
||||
style: italicTextStyle.copyWith(
|
||||
color: orangeColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
text: 'Nilai Konversi : ',
|
||||
style: regularTextStyle,
|
||||
children: [
|
||||
TextSpan(
|
||||
text:
|
||||
'${viewModel.konversiInfoModel!.alphabeticCode} ${viewModel.conversionResultModel!.conversionResult}',
|
||||
style: boldTextStyle.copyWith(
|
||||
color: orangeColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
import '../../../../app/app.dialogs.dart';
|
||||
import '../../../../app/app.logger.dart';
|
||||
import '../../../../app/core/custom_base_view_model.dart';
|
||||
import '../../../../models/all_info_model.dart';
|
||||
import '../../../../models/conversion_result_model.dart';
|
||||
|
||||
class CustomCurrencyViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('CustomCurrencyViewModel');
|
||||
ConversionResultModel? conversionResultModel;
|
||||
AllInfoModel? currencyInfoModel;
|
||||
AllInfoModel? konversiInfoModel;
|
||||
String? nilaiTukaran;
|
||||
Future<void> init() async {}
|
||||
|
||||
myDialog() async {
|
||||
final res = await dialogService.showCustomDialog(
|
||||
variant: DialogType.konversiDialogView,
|
||||
);
|
||||
|
||||
if (res!.confirmed) {
|
||||
setBusy(true);
|
||||
globalVar.backPressed = 'cantBack';
|
||||
easyLoading.customLoading('Loading Konversi Tukaran ...');
|
||||
log.i(res.data);
|
||||
String currencyCountry = res.data['currencyCountry'];
|
||||
String nilaiTukaran = res.data['nilaiTukaran'];
|
||||
String konversiCountry = res.data['konversiCountry'];
|
||||
|
||||
this.nilaiTukaran = nilaiTukaran;
|
||||
|
||||
String api = '/pair/$currencyCountry/$konversiCountry/$nilaiTukaran';
|
||||
|
||||
try {
|
||||
var response = await httpService.get(api);
|
||||
log.i(response.data);
|
||||
|
||||
for (var item in globalVar.allInfoModel) {
|
||||
if (item.alphabeticCode == currencyCountry) {
|
||||
currencyInfoModel = item;
|
||||
}
|
||||
if (item.alphabeticCode == konversiCountry) {
|
||||
konversiInfoModel = item;
|
||||
}
|
||||
}
|
||||
|
||||
log.i(currencyInfoModel!.entity);
|
||||
log.i(konversiInfoModel!.entity);
|
||||
|
||||
conversionResultModel = ConversionResultModel.fromJson(response.data);
|
||||
} catch (e) {
|
||||
snackbarService.showSnackbar(message: e.toString());
|
||||
log.e(e);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
globalVar.backPressed = 'backNormal';
|
||||
easyLoading.dismissLoading();
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
import 'package:curreny_exchange/app/themes/app_colors.dart';
|
||||
import 'package:curreny_exchange/ui/widgets/my_textformfield.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
|
||||
import './konversi_dialog_view_model.dart';
|
||||
|
||||
class KonversiDialogView extends StatelessWidget {
|
||||
// final bool isKonversi;
|
||||
final DialogRequest? request;
|
||||
final Function(DialogResponse)? completer;
|
||||
|
||||
const KonversiDialogView({
|
||||
Key? key,
|
||||
// this.isKonversi = false,
|
||||
this.request,
|
||||
this.completer,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<KonversiDialogViewModel>.reactive(
|
||||
viewModelBuilder: () => KonversiDialogViewModel(),
|
||||
onViewModelReady: (KonversiDialogViewModel model) async {
|
||||
await model.init();
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
KonversiDialogViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return Dialog(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Expanded(
|
||||
child: model.currencyWidget == null
|
||||
? const Text('- Pilih Mata Uang -')
|
||||
: model.currencyWidget!,
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
model.pilihNegara(true);
|
||||
},
|
||||
icon: const Icon(Icons.edit, color: mainColor),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
MyTextFormField(
|
||||
hintText: model.hintText ?? 'Pilih Mata Uang Konversi',
|
||||
keyboardType: TextInputType.number,
|
||||
controller: model.nilaiTukaranController,
|
||||
focusNode: model.nilaiTukaranFocusNode,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Expanded(
|
||||
child: model.konversiWidget == null
|
||||
? const Text('- Pilih Mata Uang -')
|
||||
: model.konversiWidget!),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
model.pilihNegara(false);
|
||||
},
|
||||
icon: const Icon(Icons.edit, color: mainColor),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
model.konversi(completer);
|
||||
},
|
||||
child: const Text('Konversi'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,153 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
|
||||
import '../../../../../app/app.bottomsheets.dart';
|
||||
import '../../../../../app/app.logger.dart';
|
||||
import '../../../../../app/core/custom_base_view_model.dart';
|
||||
import '../../../../../app/themes/app_colors.dart';
|
||||
import '../../../../../app/themes/app_text.dart';
|
||||
import '../../../../../models/all_info_model.dart';
|
||||
|
||||
class KonversiDialogViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('KonversiDialogViewModel');
|
||||
String? currencyCountry;
|
||||
Widget? currencyWidget;
|
||||
String? hintText;
|
||||
String? konversiCountry;
|
||||
Widget? konversiWidget;
|
||||
|
||||
TextEditingController nilaiTukaranController = TextEditingController();
|
||||
FocusNode nilaiTukaranFocusNode = FocusNode();
|
||||
|
||||
Future<void> init() async {}
|
||||
|
||||
pilihNegara(bool bool) async {
|
||||
// FocusScope.of(StackedService.navigatorKey!.currentContext!).unfocus();
|
||||
final res = await bottomSheetService.showCustomSheet(
|
||||
variant: BottomSheetType.pilihNegaraBottomSheetView,
|
||||
data: {
|
||||
'bool': bool,
|
||||
'currencyCountry': bool == true ? currencyCountry : konversiCountry,
|
||||
},
|
||||
);
|
||||
|
||||
if (res!.confirmed == true) {
|
||||
log.i('${res.data} ini res.data');
|
||||
// if (res.data !=
|
||||
AllInfoModel? allInfoModel = res.data;
|
||||
|
||||
if (bool == true) {
|
||||
currencyCountry = allInfoModel!.alphabeticCode;
|
||||
log.i(allInfoModel.entity);
|
||||
hintText = 'Tukaran ${allInfoModel.alphabeticCode}';
|
||||
currencyWidget = Row(
|
||||
children: [
|
||||
Image.asset(
|
||||
'assets/flags/${allInfoModel.alphabeticCode!.toLowerCase()}.png',
|
||||
width: 30,
|
||||
),
|
||||
const SizedBox(width: 15),
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
text: allInfoModel.entity,
|
||||
style: regularTextStyle.copyWith(
|
||||
color: greenColor,
|
||||
),
|
||||
children: [
|
||||
TextSpan(
|
||||
text: ' (${allInfoModel.alphabeticCode})',
|
||||
style: italicTextStyle.copyWith(
|
||||
color: greenColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
)),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
// log.i(allInfoModel!.entity);
|
||||
|
||||
konversiCountry = (res.data == 'all'
|
||||
? 'Semua Mata Uang'
|
||||
: allInfoModel!.alphabeticCode)!;
|
||||
|
||||
// hintText = 'Tukaran ${allInfoModel.alphabeticCode}';
|
||||
konversiWidget = Row(
|
||||
children: [
|
||||
res.data == 'all'
|
||||
? const Icon(
|
||||
Icons.all_inclusive,
|
||||
color: redColor,
|
||||
)
|
||||
: Image.asset(
|
||||
'assets/flags/${allInfoModel!.alphabeticCode!.toLowerCase()}.png',
|
||||
width: 30,
|
||||
),
|
||||
const SizedBox(width: 15),
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
text:
|
||||
res.data == 'all' ? 'Semua Mata Uang' : allInfoModel!.entity,
|
||||
style: regularTextStyle.copyWith(
|
||||
color: redColor,
|
||||
),
|
||||
children: [
|
||||
TextSpan(
|
||||
text: res.data == 'all'
|
||||
? '*'
|
||||
: ' (${allInfoModel!.alphabeticCode})',
|
||||
style: italicTextStyle.copyWith(
|
||||
color: redColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
)),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
konversi(Function(DialogResponse p1)? completer) async {
|
||||
if (currencyCountry == null) {
|
||||
snackbarService.showSnackbar(
|
||||
message: 'Pilih Mata Uang',
|
||||
title: 'Pilih Negara',
|
||||
);
|
||||
pilihNegara(true);
|
||||
return;
|
||||
}
|
||||
if (nilaiTukaranController.text == '') {
|
||||
snackbarService.showSnackbar(
|
||||
message: 'Masukkan Nilai Tukaran',
|
||||
title: 'Nilai Tukaran',
|
||||
);
|
||||
|
||||
// focus on textfield
|
||||
FocusScope.of(StackedService.navigatorKey!.currentContext!)
|
||||
.requestFocus(nilaiTukaranFocusNode);
|
||||
return;
|
||||
}
|
||||
|
||||
if (konversiCountry == null) {
|
||||
snackbarService.showSnackbar(
|
||||
message: 'Pilih Mata Uang Koversi',
|
||||
title: 'Pilih Negara',
|
||||
);
|
||||
pilihNegara(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// remove keyboard
|
||||
FocusScope.of(StackedService.navigatorKey!.currentContext!).unfocus();
|
||||
|
||||
completer!(
|
||||
DialogResponse(confirmed: true, data: {
|
||||
'currencyCountry': currencyCountry,
|
||||
'nilaiTukaran': nilaiTukaranController.text,
|
||||
'konversiCountry': konversiCountry,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
import 'package:curreny_exchange/app/themes/app_colors.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
|
||||
import '../../../../../../app/themes/app_text.dart';
|
||||
import './pilih_negara_bottom_sheet_view_model.dart';
|
||||
|
||||
// class PilihNegaraData {
|
||||
// final bool? isKonversi;
|
||||
// final String? alphabeticCode;
|
||||
|
||||
// PilihNegaraData({
|
||||
// this.isKonversi,
|
||||
// this.alphabeticCode,
|
||||
// });
|
||||
// }
|
||||
|
||||
class PilihNegaraBottomSheetView extends StatelessWidget {
|
||||
final SheetRequest? request;
|
||||
final Function(SheetResponse)? completer;
|
||||
|
||||
const PilihNegaraBottomSheetView({
|
||||
Key? key,
|
||||
this.request,
|
||||
this.completer,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<PilihNegaraBottomSheetViewModel>.reactive(
|
||||
viewModelBuilder: () => PilihNegaraBottomSheetViewModel(),
|
||||
onViewModelReady: (PilihNegaraBottomSheetViewModel model) async {
|
||||
await model.init(request!.data);
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
PilihNegaraBottomSheetViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(15),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(15),
|
||||
topRight: Radius.circular(15),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'Pilih Negara',
|
||||
style: italicTextStyle.copyWith(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
for (var item in model.globalVar.allInfoModel)
|
||||
Card(
|
||||
// creata a checkbox at the e
|
||||
color: request!.data['currencyCountry'] ==
|
||||
item.alphabeticCode
|
||||
? mainColor
|
||||
: Colors.white,
|
||||
child: ListTile(
|
||||
onTap: () {
|
||||
// if (isKonversi) {
|
||||
completer!(
|
||||
SheetResponse(confirmed: true, data: item));
|
||||
// }
|
||||
},
|
||||
leading: Image.asset(
|
||||
'assets/flags/${item.alphabeticCode!.toLowerCase()}.png',
|
||||
width: 30,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return const Icon(Icons.error);
|
||||
},
|
||||
),
|
||||
title: Text(
|
||||
item.entity!,
|
||||
style: italicTextStyle.copyWith(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: request!.data['currencyCountry'] ==
|
||||
item.alphabeticCode
|
||||
? Colors.white
|
||||
: Colors.black,
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
item.currency!,
|
||||
style: italicTextStyle.copyWith(
|
||||
fontSize: 15,
|
||||
// fontWeight: FontWeight.bold,
|
||||
color: request!.data['currencyCountry'] ==
|
||||
item.alphabeticCode
|
||||
? Colors.white
|
||||
: Colors.black,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
import '../../../../../../app/app.logger.dart';
|
||||
import '../../../../../../app/core/custom_base_view_model.dart';
|
||||
|
||||
class PilihNegaraBottomSheetViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('PilihNegaraBottomSheetViewModel');
|
||||
Future<void> init(data) async {
|
||||
// log.i(globalVar.allInfoModel);
|
||||
log.i(data['bool']);
|
||||
}
|
||||
}
|
@ -0,0 +1,157 @@
|
||||
import 'package:curreny_exchange/app/themes/app_colors.dart';
|
||||
import 'package:curreny_exchange/app/themes/app_text.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
import './today_currency_view_model.dart';
|
||||
|
||||
class TodayCurrencyView extends StatelessWidget {
|
||||
const TodayCurrencyView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<TodayCurrencyViewModel>.reactive(
|
||||
viewModelBuilder: () => TodayCurrencyViewModel(),
|
||||
onViewModelReady: (TodayCurrencyViewModel model) async {
|
||||
await model.init();
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
TodayCurrencyViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return WillPopScope(
|
||||
onWillPop: () async {
|
||||
// model.navigationService.back();
|
||||
if (model.globalVar.backPressed == 'backNormal') {
|
||||
model.quitApp(context);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
child: Scaffold(
|
||||
body: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
text: 'Terakhir diperbarui : ',
|
||||
style: regularTextStyle,
|
||||
children: [
|
||||
TextSpan(
|
||||
text: model.otherFunction.timeStampConverter(model
|
||||
.globalVar.myResponseModel!.timeLastUpdateUnix!),
|
||||
style: boldTextStyle.copyWith(
|
||||
color: greenColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
text: 'Update berikutnya : ',
|
||||
style: regularTextStyle,
|
||||
children: [
|
||||
TextSpan(
|
||||
text: model.otherFunction.timeStampConverter(model
|
||||
.globalVar.myResponseModel!.timeNextUpdateUnix!),
|
||||
style: boldTextStyle.copyWith(
|
||||
color: mainColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
text: 'Tukaran : ',
|
||||
style: regularTextStyle,
|
||||
children: [
|
||||
TextSpan(
|
||||
text: 'Rp . ${model.globalVar.allCurrencyModel!.iDR}',
|
||||
style: boldTextStyle.copyWith(
|
||||
color: redColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
Expanded(
|
||||
child: model.globalVar.jsonAllCurrency != null
|
||||
? SingleChildScrollView(
|
||||
child: Column(
|
||||
children: model.globalVar.allCurrencyModel!
|
||||
.toJson()
|
||||
.entries
|
||||
.map(
|
||||
(e) {
|
||||
// make e.key to be uppercase
|
||||
String key = e.key.toString().toUpperCase();
|
||||
String lowerKey =
|
||||
e.key.toString().toLowerCase();
|
||||
var row = model.globalVar.jsonAllCurrency
|
||||
.firstWhere(
|
||||
(currency) =>
|
||||
currency['AlphabeticCode'] == key,
|
||||
orElse: () => null);
|
||||
// Map<String, dynamic> rowMap = row;
|
||||
if (row != null) {
|
||||
// model.log.i(row['Currency']);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 10),
|
||||
// add icon to card
|
||||
child: Card(
|
||||
child: ListTile(
|
||||
leading: Image.asset(
|
||||
'assets/flags/$lowerKey.png',
|
||||
width: 50,
|
||||
height: 50,
|
||||
errorBuilder:
|
||||
(context, error, stackTrace) {
|
||||
return const Icon(Icons.error);
|
||||
},
|
||||
),
|
||||
title: Text(
|
||||
row['Entity'],
|
||||
style: boldTextStyle,
|
||||
),
|
||||
subtitle: Text(
|
||||
row['Currency'],
|
||||
style: regularTextStyle,
|
||||
),
|
||||
trailing: Text(
|
||||
e.value.toString(),
|
||||
style: boldTextStyle.copyWith(
|
||||
color: redColor,
|
||||
),
|
||||
),
|
||||
)),
|
||||
);
|
||||
} else {
|
||||
return const SizedBox();
|
||||
}
|
||||
},
|
||||
).toList(),
|
||||
),
|
||||
)
|
||||
: const Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
import '../../../../app/app.logger.dart';
|
||||
import '../../../../app/core/custom_base_view_model.dart';
|
||||
|
||||
class TodayCurrencyViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('TodayCurrencyViewModel');
|
||||
// dynamic jsonAllCurrency;
|
||||
Future<void> init() async {}
|
||||
}
|
29
lib/ui/views/loading_screen/loading_screen_view.dart
Normal file
29
lib/ui/views/loading_screen/loading_screen_view.dart
Normal file
@ -0,0 +1,29 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
import './loading_screen_view_model.dart';
|
||||
|
||||
class LoadingScreenView extends StatelessWidget {
|
||||
const LoadingScreenView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<LoadingScreenViewModel>.reactive(
|
||||
viewModelBuilder: () => LoadingScreenViewModel(),
|
||||
onViewModelReady: (LoadingScreenViewModel model) async {
|
||||
await model.init();
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
LoadingScreenViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return const Scaffold(
|
||||
body: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
import '../../../app/core/custom_base_view_model.dart';
|
||||
|
||||
class LoadingScreenViewModel extends CustomBaseViewModel {
|
||||
Future<void> init() async {}
|
||||
}
|
62
lib/ui/views/splash_screen/splash_screen_view.dart
Normal file
62
lib/ui/views/splash_screen/splash_screen_view.dart
Normal file
@ -0,0 +1,62 @@
|
||||
import 'package:curreny_exchange/app/themes/app_text.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
import './splash_screen_view_model.dart';
|
||||
|
||||
class SplashScreenView extends StatelessWidget {
|
||||
const SplashScreenView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<SplashScreenViewModel>.reactive(
|
||||
viewModelBuilder: () => SplashScreenViewModel(),
|
||||
onViewModelReady: (SplashScreenViewModel model) async {
|
||||
await model.init();
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
SplashScreenViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return WillPopScope(
|
||||
onWillPop: () async {
|
||||
return false;
|
||||
},
|
||||
child: Scaffold(
|
||||
body: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const Expanded(child: SizedBox(height: 20)),
|
||||
Center(
|
||||
child: Image.asset(
|
||||
'assets/exchange.png',
|
||||
width: 200,
|
||||
height: 200,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
"Aplikasi\nTukaran Mata Wang",
|
||||
style: italicTextStyle.copyWith(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const Expanded(child: SizedBox(height: 20)),
|
||||
Text(
|
||||
"Created by : Marlina & Andi Wafiah",
|
||||
style: regularTextStyle.copyWith(fontSize: 12),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
52
lib/ui/views/splash_screen/splash_screen_view_model.dart
Normal file
52
lib/ui/views/splash_screen/splash_screen_view_model.dart
Normal file
@ -0,0 +1,52 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../../../app/app.logger.dart';
|
||||
import '../../../app/app.router.dart';
|
||||
import '../../../app/core/custom_base_view_model.dart';
|
||||
import '../../../models/all_currency.dart';
|
||||
import '../../../models/all_info_model.dart';
|
||||
import '../../../models/my_response.dart';
|
||||
|
||||
class SplashScreenViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('SplashScreenViewModel');
|
||||
MyResponseModel? myResponseModel;
|
||||
Future<void> init() async {
|
||||
globalVar.backPressed = 'cantBack';
|
||||
getData();
|
||||
}
|
||||
|
||||
getData() async {
|
||||
setBusy(true);
|
||||
|
||||
try {
|
||||
var response = await httpService.get('/latest/IDR');
|
||||
// log.i(response.data);
|
||||
myResponseModel = MyResponseModel.fromJson(response.data);
|
||||
globalVar.myResponseModel = myResponseModel;
|
||||
// log.i(myResponseModel!.conversionRates);
|
||||
AllCurrencyModel allCurrencyModel =
|
||||
AllCurrencyModel.fromJson(myResponseModel!.conversionRates!);
|
||||
globalVar.allCurrencyModel = allCurrencyModel;
|
||||
final String jsonData =
|
||||
await rootBundle.loadString('assets/codes-all.json');
|
||||
globalVar.jsonAllCurrency = jsonDecode(jsonData);
|
||||
// log.i(globalVar.jsonAllCurrency);
|
||||
// conver jsonData to Map<String, dynamic>
|
||||
for (var item in globalVar.jsonAllCurrency) {
|
||||
// log.i(item);
|
||||
globalVar.allInfoModel.add(AllInfoModel.fromJson(item));
|
||||
}
|
||||
Future.delayed(const Duration(seconds: 1), () {
|
||||
navigationService.replaceWith(Routes.appIndexTrackingView);
|
||||
});
|
||||
} catch (e) {
|
||||
snackbarService.showSnackbar(message: e.toString());
|
||||
log.e(e);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
globalVar.backPressed = 'backNormal';
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user