Skip to content

Commit

Permalink
fix: click bottom icon for home
Browse files Browse the repository at this point in the history
  • Loading branch information
popoway committed Feb 6, 2024
1 parent 1496fc9 commit 73fed66
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(
Expand All @@ -99,6 +110,7 @@ class CupertinoTabBarDemo extends StatelessWidget {
),
);
},
controller: tabController,
),
),
);
Expand Down Expand Up @@ -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});
Expand Down Expand Up @@ -489,6 +503,8 @@ class _MyHomePageState extends State<MyHomePage> {

@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;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 73fed66

Please sign in to comment.