fix back button nav
This commit is contained in:
@@ -1,4 +1,8 @@
|
|||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
|
import 'package:ken_logger/ken_logger.dart';
|
||||||
import 'package:mzansi_innovation_hub/main.dart';
|
import 'package:mzansi_innovation_hub/main.dart';
|
||||||
|
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_scack_bar.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_packages/mih_home/components/mih_app_drawer.dart';
|
import 'package:mzansi_innovation_hub/mih_packages/mih_home/components/mih_app_drawer.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tools.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tools.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -31,6 +35,7 @@ class _MihPackageState extends State<MihPackage>
|
|||||||
with SingleTickerProviderStateMixin {
|
with SingleTickerProviderStateMixin {
|
||||||
late PageController _pageController;
|
late PageController _pageController;
|
||||||
late AnimationController _animationController;
|
late AnimationController _animationController;
|
||||||
|
DateTime? lastPressedAt;
|
||||||
|
|
||||||
void unfocusAll() {
|
void unfocusAll() {
|
||||||
FocusScope.of(context).unfocus();
|
FocusScope.of(context).unfocus();
|
||||||
@@ -113,69 +118,96 @@ class _MihPackageState extends State<MihPackage>
|
|||||||
Size screenSize = MediaQuery.of(context).size;
|
Size screenSize = MediaQuery.of(context).size;
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: unfocusAll,
|
onTap: unfocusAll,
|
||||||
child: Scaffold(
|
child: PopScope(
|
||||||
drawer: widget.actionDrawer,
|
canPop: false,
|
||||||
body: SafeArea(
|
onPopInvokedWithResult: (bool didPop, Object? result) {
|
||||||
bottom: false,
|
if (GoRouterState.of(context).name == 'mihHome') {
|
||||||
minimum: EdgeInsets.only(bottom: 0),
|
if (lastPressedAt == null ||
|
||||||
child: Container(
|
DateTime.now().difference(lastPressedAt!) >
|
||||||
width: screenSize.width,
|
const Duration(seconds: 2)) {
|
||||||
height: screenSize.height,
|
// First press: show a message and update the timestamp.
|
||||||
//color: Colors.black,
|
lastPressedAt = DateTime.now();
|
||||||
padding: const EdgeInsets.only(top: 5),
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
child: Column(
|
MihSnackBar(
|
||||||
children: [
|
child: Text("Press back again to exit"),
|
||||||
Row(
|
),
|
||||||
mainAxisSize: MainAxisSize.min,
|
);
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
} else {
|
||||||
children: [
|
// Second press within 2 seconds: exit the app.
|
||||||
widget.appActionButton,
|
KenLogger.warning('Exiting app...'); // Your custom logger
|
||||||
const SizedBox(
|
SystemChannels.platform.invokeMethod('SystemNavigator.pop');
|
||||||
width: 10,
|
}
|
||||||
),
|
} else {
|
||||||
Expanded(
|
context.goNamed(
|
||||||
child: Container(
|
'mihHome',
|
||||||
// alignment: Alignment.center,
|
extra: true,
|
||||||
// alignment: Alignment.centerRight,
|
);
|
||||||
alignment: Alignment.centerLeft,
|
}
|
||||||
// color: Colors.black,
|
},
|
||||||
child: FittedBox(
|
child: Scaffold(
|
||||||
child: Text(
|
drawer: widget.actionDrawer,
|
||||||
widget.appToolTitles != null
|
body: SafeArea(
|
||||||
? widget
|
bottom: false,
|
||||||
.appToolTitles![widget.selectedbodyIndex]
|
minimum: EdgeInsets.only(bottom: 0),
|
||||||
: "",
|
child: Container(
|
||||||
style: const TextStyle(
|
width: screenSize.width,
|
||||||
fontSize: 23,
|
height: screenSize.height,
|
||||||
fontWeight: FontWeight.w600,
|
//color: Colors.black,
|
||||||
|
padding: const EdgeInsets.only(top: 5),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
widget.appActionButton,
|
||||||
|
const SizedBox(
|
||||||
|
width: 10,
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Container(
|
||||||
|
// alignment: Alignment.center,
|
||||||
|
// alignment: Alignment.centerRight,
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
// color: Colors.black,
|
||||||
|
child: FittedBox(
|
||||||
|
child: Text(
|
||||||
|
widget.appToolTitles != null
|
||||||
|
? widget
|
||||||
|
.appToolTitles![widget.selectedbodyIndex]
|
||||||
|
: "",
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 23,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(
|
||||||
const SizedBox(
|
width: 5,
|
||||||
width: 5,
|
),
|
||||||
),
|
widget.appTools,
|
||||||
widget.appTools,
|
],
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 5),
|
|
||||||
Expanded(
|
|
||||||
child: PageView.builder(
|
|
||||||
controller: _pageController,
|
|
||||||
itemCount: widget.appBody.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
return widget.appBody[index];
|
|
||||||
},
|
|
||||||
onPageChanged: (index) {
|
|
||||||
setState(() {
|
|
||||||
widget.selectedbodyIndex = index;
|
|
||||||
widget.onIndexChange(widget.selectedbodyIndex);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(height: 5),
|
||||||
],
|
Expanded(
|
||||||
|
child: PageView.builder(
|
||||||
|
controller: _pageController,
|
||||||
|
itemCount: widget.appBody.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
return widget.appBody[index];
|
||||||
|
},
|
||||||
|
onPageChanged: (index) {
|
||||||
|
setState(() {
|
||||||
|
widget.selectedbodyIndex = index;
|
||||||
|
widget.onIndexChange(widget.selectedbodyIndex);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
SnackBar MihSnackBar({
|
||||||
|
required Widget child,
|
||||||
|
}) {
|
||||||
|
return SnackBar(
|
||||||
|
content: child,
|
||||||
|
shape: StadiumBorder(),
|
||||||
|
behavior: SnackBarBehavior.floating,
|
||||||
|
duration: Duration(seconds: 2),
|
||||||
|
width: null,
|
||||||
|
action: SnackBarAction(
|
||||||
|
label: "Dismiss",
|
||||||
|
onPressed: () {},
|
||||||
|
),
|
||||||
|
// elevation: 30,
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user