Skip to content

Commit e25911d

Browse files
committed
Add MainPage with bottom navigation and update app entry point
1 parent 3691865 commit e25911d

File tree

3 files changed

+50
-24
lines changed

3 files changed

+50
-24
lines changed

lib/app/app.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_bloc/flutter_bloc.dart';
3+
import 'package:tmdb_flutter/app/view/main_page.dart';
34
import 'api/movie_api.dart';
45
import 'cubit/home_cubit.dart';
56
import 'view/home_page.dart';
@@ -17,7 +18,7 @@ class App extends StatelessWidget {
1718
),
1819
home: BlocProvider(
1920
create: (context) => HomeCubit(MovieAPI()),
20-
child: const HomePage(),
21+
child: const MainPage(),
2122
),
2223
);
2324
}

lib/app/view/app.dart

Lines changed: 0 additions & 23 deletions
This file was deleted.

lib/app/view/main_page.dart

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:tmdb_flutter/app/view/favorites_page.dart';
3+
import 'package:tmdb_flutter/app/view/home_page.dart';
4+
5+
class MainPage extends StatefulWidget {
6+
const MainPage({super.key});
7+
8+
@override
9+
State<MainPage> createState() => _MainPageState();
10+
}
11+
12+
class _MainPageState extends State<MainPage> {
13+
int _selectedIndex = 0;
14+
15+
final List<Widget> _pages = const [
16+
HomePage(),
17+
FavoritesPage(),
18+
];
19+
20+
void _onItemTapped(int index) {
21+
setState(() {
22+
_selectedIndex = index;
23+
});
24+
}
25+
26+
@override
27+
Widget build(BuildContext context) {
28+
return Scaffold(
29+
body: _pages[_selectedIndex],
30+
bottomNavigationBar: BottomNavigationBar(
31+
items: const <BottomNavigationBarItem>[
32+
BottomNavigationBarItem(
33+
icon: Icon(Icons.home),
34+
label: 'Home',
35+
),
36+
BottomNavigationBarItem(
37+
icon: Icon(Icons.favorite),
38+
label: 'Favorites',
39+
),
40+
],
41+
currentIndex: _selectedIndex,
42+
selectedItemColor: Colors.pinkAccent,
43+
unselectedItemColor: Colors.grey,
44+
onTap: _onItemTapped,
45+
),
46+
);
47+
}
48+
}

0 commit comments

Comments
 (0)