-
-
Save azeek/0dcacd0f08025ce278f25de714ce6dd1 to your computer and use it in GitHub Desktop.
Nested Navigation iOS Status bar Tap example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: MainPage(), | |
); | |
} | |
} | |
class MainPage extends StatefulWidget { | |
const MainPage({Key? key}) : super(key: key); | |
@override | |
_MainPageState createState() => _MainPageState(); | |
} | |
class _MainPageState extends State<MainPage> { | |
final _navigatorKey = GlobalKey<NavigatorState>(); | |
int currentIndex = 0; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(), | |
body: IndexedStack( | |
index: currentIndex, | |
children: [ | |
TapBodyWidget(listName: 'Tap 1'), | |
Navigator( | |
key: _navigatorKey, | |
initialRoute: '/', | |
onGenerateRoute: (settings) => MaterialPageRoute<dynamic>( | |
builder: (context) { | |
return TapBodyWidget(listName: 'Tap2'); | |
}, | |
settings: settings, | |
), | |
) | |
], | |
), | |
bottomNavigationBar: BottomNavigationBar( | |
type: BottomNavigationBarType.fixed, | |
unselectedItemColor: Colors.black, | |
selectedItemColor: Colors.blue, | |
selectedLabelStyle: TextStyle( | |
color: Colors.blue, | |
fontWeight: FontWeight.bold, | |
), | |
unselectedLabelStyle: TextStyle( | |
color: Colors.black, | |
fontWeight: FontWeight.bold, | |
), | |
currentIndex: currentIndex, | |
onTap: (index) => setState(() => currentIndex = index), | |
items: [ | |
BottomNavigationBarItem( | |
icon: Icon(Icons.favorite_border), label: 'tab 1'), | |
BottomNavigationBarItem(icon: Icon(Icons.bookmark), label: 'tab 2'), | |
], | |
), | |
); | |
} | |
} | |
class TapBodyWidget extends StatelessWidget { | |
const TapBodyWidget({Key? key, required this.listName}) : super(key: key); | |
final String listName; | |
@override | |
Widget build(BuildContext context) { | |
return ListView.separated( | |
itemBuilder: (context, index) => Text('$listName : $index'), | |
separatorBuilder: (context, index) => Divider(), | |
itemCount: 100); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment