Untitled
unknown
plain_text
a year ago
3.9 kB
4
Indexable
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:sample_app/models/category_model.dart';
import 'package:sample_app/models/diet_model.dart';
class HomePage extends StatefulWidget {
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int _currentIndex = 0; // Tracks the currently selected tab
List<CategoryModel> categories = [];
List<DietModel> diets = [];
void _getInitialInfo() {
categories = CategoryModel.getCategories();
diets = DietModel.getDiets();
}
final List<Widget> _pages = [
HomeContent(), // The current home page content
Center(child: Text("Discover Page", style: TextStyle(fontSize: 20))),
Center(child: Text("Profile Page", style: TextStyle(fontSize: 20))),
];
@override
Widget build(BuildContext context) {
_getInitialInfo();
return Scaffold(
appBar: _appBar(),
backgroundColor: Colors.white,
body: _pages[_currentIndex], // Display the currently selected page
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
onTap: (index) {
setState(() {
_currentIndex = index;
});
},
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.search),
label: 'Discover',
),
BottomNavigationBarItem(
icon: Icon(Icons.person),
label: 'Profile',
),
],
selectedItemColor: Colors.blueAccent,
unselectedItemColor: Colors.grey,
),
);
}
AppBar _appBar() {
return AppBar(
title: const Text(
'Breakfast',
style: TextStyle(
color: Colors.black,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
backgroundColor: Colors.white,
elevation: 0.0,
centerTitle: true,
leading: GestureDetector(
onTap: () {},
child: Container(
margin: const EdgeInsets.all(10),
alignment: Alignment.center,
child: SvgPicture.asset(
'assets/icons/Arrow - Left 2.svg',
height: 20,
width: 20,
),
decoration: BoxDecoration(
color: const Color(0xffF7F8F8),
borderRadius: BorderRadius.circular(10),
),
),
),
actions: [
GestureDetector(
onTap: () {},
child: Container(
margin: const EdgeInsets.all(10),
alignment: Alignment.center,
width: 37,
child: SvgPicture.asset(
'assets/icons/dots.svg',
height: 5,
width: 5,
),
decoration: BoxDecoration(
color: const Color(0xffF7F8F8),
borderRadius: BorderRadius.circular(10),
),
),
),
],
);
}
}
class HomeContent extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: SingleChildScrollView(
child: Column(
children: [
_searchField(),
SizedBox(height: 40),
_categoriesSelection(),
SizedBox(height: 40),
_categoriesSelection1(),
SizedBox(height: 40),
_dietSection(),
SizedBox(height: 40),
_categoriesSelection1(),
],
),
),
),
],
);
}
// Keep the helper functions (_searchField, _categoriesSelection, etc.) here...
}
Editor is loading...
Leave a Comment