Skip to content

Instantly share code, notes, and snippets.

@azeek

azeek/main.dart Secret

Created July 1, 2021 01:46
Show Gist options
  • Save azeek/0dcacd0f08025ce278f25de714ce6dd1 to your computer and use it in GitHub Desktop.
Save azeek/0dcacd0f08025ce278f25de714ce6dd1 to your computer and use it in GitHub Desktop.
Nested Navigation iOS Status bar Tap example
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