first commit
This commit is contained in:
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