From 73fed66ee6d4b4dc6c37b0bab734c67ae765eb46 Mon Sep 17 00:00:00 2001 From: Ming Lei <31576265+popoway@users.noreply.github.com> Date: Tue, 6 Feb 2024 04:19:39 -0500 Subject: [PATCH] fix: click bottom icon for home --- lib/home.dart | 16 ++++++++++++++++ pubspec.yaml | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/home.dart b/lib/home.dart index a27016d..792b019 100644 --- a/lib/home.dart +++ b/lib/home.dart @@ -65,6 +65,9 @@ class CupertinoTabBarDemo extends StatelessWidget { ); SystemChrome.setSystemUIOverlayStyle(mySystemTheme); + var tabController = CupertinoTabController(initialIndex: 0); + var currentTabIndex = 0; + return WillPopScope( // forbidden swipe in iOS(my ThemeData(platform: TargetPlatform.iOS,) from onboarding.dart) onWillPop: () async { @@ -88,6 +91,14 @@ class CupertinoTabBarDemo extends StatelessWidget { icon: Icon(tabInfo.icon), ), ], + onTap: (tappedIndex) { + if (currentTabIndex == 0 && tappedIndex == 0) { + if (Navigator.of(myHomePageContext).canPop()) { + Navigator.of(myHomePageContext).pop(); + } + } + currentTabIndex = tappedIndex; + }, ), tabBuilder: (context, index) { return CupertinoTabView( @@ -99,6 +110,7 @@ class CupertinoTabBarDemo extends StatelessWidget { ), ); }, + controller: tabController, ), ), ); @@ -135,6 +147,8 @@ class _CupertinoDemoTab extends StatelessWidget { } } +var myHomePageContext; + /// This is the stateless widget that the main application instantiates. class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); @@ -489,6 +503,8 @@ class _MyHomePageState extends State { @override Widget build(BuildContext context) { + myHomePageContext = context; + // if landscape, show 5 icons per row; if portrait, show 3 icons per row final columnCount = MediaQuery.of(context).orientation == Orientation.landscape ? 5 : 3; diff --git a/pubspec.yaml b/pubspec.yaml index 863aa72..de8611f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -17,7 +17,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 2.2.1+48 +version: 2.2.1+49 environment: sdk: '>=3.1.0 <4.0.0'