step 12 : add proteksi login di tiap page

This commit is contained in:
sindhu
2024-01-15 16:29:28 +07:00
parent 24353ba729
commit ee702da5c7
7 changed files with 209 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
import 'package:app_petty_cash/widget/sankbar_widget.dart';
import '../../widget/sankbar_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
@@ -6,6 +6,8 @@ import 'package:intl/intl.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../app/constant.dart';
import '../../app/route.dart';
import '../../provider/current_user_provider.dart';
import '../../widget/custom_drawer.dart';
class ReportScreen extends HookConsumerWidget {
@@ -24,6 +26,21 @@ class ReportScreen extends HookConsumerWidget {
final tglAkhir = useState<DateTime>(DateTime.now());
final tglAkhirTmp = useState<String>("");
useEffect(() {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
final userID = ref.read(currentUserProvider)?.model.M_UserID ?? "0";
if (userID == "0") {
//not login
Navigator.of(context)
.pushNamedAndRemoveUntil(loginRoute, (route) => true);
// Navigator.popAndPushNamed(context, loginRoute);
return;
}
});
return () {};
}, []);
return Padding(
padding: EdgeInsets.only(
top: Constant.getActualYPhone(context: context, y: 30),
@@ -245,7 +262,8 @@ class ReportScreen extends HookConsumerWidget {
String url = "https://pub.dev/packages?q=url+launcher";
if (!await launchUrl(Uri.parse(url))) {
// throw Exception('Could not launch $url');
SanckbarWidget(context, 'Could not launch $url', snackbarType.error);
SanckbarWidget(context, 'Could not launch $url',
snackbarType.error);
}
},
),