first commit
This commit is contained in:
59
lib/app/core/custom_base_view_model.dart
Executable file
59
lib/app/core/custom_base_view_model.dart
Executable file
@ -0,0 +1,59 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
|
||||
import '../../services/global_var.dart';
|
||||
import '../../services/http_services.dart';
|
||||
import '../../services/my_easyloading.dart';
|
||||
import '../app.locator.dart';
|
||||
import '../themes/app_colors.dart';
|
||||
|
||||
class CustomBaseViewModel extends BaseViewModel {
|
||||
final dialogService = locator<DialogService>();
|
||||
final navigationService = locator<NavigationService>();
|
||||
final bottomSheetService = locator<BottomSheetService>();
|
||||
final snackbarService = locator<SnackbarService>();
|
||||
final easyLoading = locator<MyEasyLoading>();
|
||||
final httpService = locator<MyHttpServices>();
|
||||
final globalVar = locator<GlobalVar>();
|
||||
|
||||
// late bool backPressed;
|
||||
|
||||
void back() {
|
||||
navigationService.back();
|
||||
}
|
||||
|
||||
quitApp(BuildContext context) {
|
||||
globalVar.backPressed = 'cantBack';
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Keluar'),
|
||||
content: const Text('Apakah Anda yakin ingin keluar?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
globalVar.backPressed = 'exitApp';
|
||||
Navigator.of(context).pop(false);
|
||||
},
|
||||
child: const Text('Batal'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: const Text(
|
||||
'Keluar',
|
||||
style: TextStyle(color: dangerColor),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
).then((value) {
|
||||
if (value == true) {
|
||||
SystemNavigator.pop();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user