You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.3 KiB
Dart
55 lines
1.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_navigation/screens/categories.dart';
|
|
import 'package:flutter_navigation/screens/meals.dart';
|
|
|
|
class TabsScreen extends StatefulWidget {
|
|
const TabsScreen({super.key});
|
|
|
|
@override
|
|
State<StatefulWidget> createState() {
|
|
return _TabsScreenState();
|
|
}
|
|
}
|
|
|
|
class _TabsScreenState extends State<TabsScreen> {
|
|
int _selectedPageIndex = 0;
|
|
|
|
void _selectPage(int index) {
|
|
setState(() {
|
|
_selectedPageIndex = index;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Widget activePage = const CategoriesScreen();
|
|
var activePageTitle = 'Categories';
|
|
|
|
if (_selectedPageIndex == 1) {
|
|
activePage = const MealsScreen(meals: []);
|
|
activePageTitle = 'Your Favorites';
|
|
}
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(activePageTitle),
|
|
),
|
|
body: activePage,
|
|
bottomNavigationBar: BottomNavigationBar(
|
|
onTap: _selectPage,
|
|
currentIndex: _selectedPageIndex,
|
|
items: const [
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.set_meal),
|
|
label: 'Categories',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.star),
|
|
label: 'Favorites',
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|