aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorFelipe Erias <felipeerias@igalia.com>2021-11-12 12:06:32 +0900
committerFelipe Erias <felipeerias@igalia.com>2021-11-12 12:06:32 +0900
commit6cdae5992de2b9865a3a05885e91338160243674 (patch)
tree084dafb4361bb668726c3f54075184ec3aa6c6c6 /lib
parent239ad725cd6e2b64974be4ab3949b38cb32eff7e (diff)
Home screen buttons navigate to the appropriate section
Diffstat (limited to 'lib')
-rw-r--r--lib/homescreen.dart12
-rw-r--r--lib/page_home.dart43
2 files changed, 47 insertions, 8 deletions
diff --git a/lib/homescreen.dart b/lib/homescreen.dart
index 232c184..c81a2d5 100644
--- a/lib/homescreen.dart
+++ b/lib/homescreen.dart
@@ -17,6 +17,12 @@ class Homescreen extends StatefulWidget {
class _HomescreenState extends State<Homescreen> {
int _selectedIndex = 0;
+ setNavigationIndex(int index) {
+ setState(() {
+ _selectedIndex = index;
+ });
+ }
+
@override
Widget build(BuildContext context) {
var screenHeight = MediaQuery.of(context).size.height;
@@ -35,9 +41,7 @@ class _HomescreenState extends State<Homescreen> {
// leading widget?
// trailing widget does not expand to bottom
onDestinationSelected: (int index) {
- setState(() {
- _selectedIndex = index;
- });
+ setNavigationIndex(index);
},
selectedIconTheme: IconTheme.of(context).copyWith(
size: iconSize,
@@ -93,7 +97,7 @@ class _HomescreenState extends State<Homescreen> {
Widget _childForIndex(int selectedIndex) {
switch (selectedIndex) {
case 0:
- return HomePage();
+ return HomePage(onSetNavigationIndex: setNavigationIndex);
case 1:
return DashboardPage();
case 2:
diff --git a/lib/page_home.dart b/lib/page_home.dart
index 57b8e88..ede3e36 100644
--- a/lib/page_home.dart
+++ b/lib/page_home.dart
@@ -1,12 +1,47 @@
import 'package:flutter/material.dart';
class HomePage extends StatelessWidget {
- // TODO placeholder
+ final Function(int index) onSetNavigationIndex;
+
+ const HomePage({Key? key, required this.onSetNavigationIndex})
+ : super(key: key);
+
@override
Widget build(BuildContext context) {
- return Text(
- 'HOME',
- style: Theme.of(context).textTheme.headline1,
+ final double spacing = MediaQuery.of(context).size.width / 32;
+ final double runSpacing = spacing / 2;
+ return Center(
+ child: Wrap(
+ spacing: spacing,
+ runSpacing: runSpacing,
+ children: <Widget>[
+ createItem(context, Icons.drive_eta, 1),
+ createItem(context, Icons.thermostat, 2),
+ createItem(context, Icons.music_note, 3)
+ ],
+ ));
+ }
+
+ Widget createItem(BuildContext context, IconData icon, int tabPosition) {
+ final double size = MediaQuery.of(context).size.width / 6;
+ return Padding(
+ padding: const EdgeInsets.symmetric(vertical: 8.0),
+ child: ElevatedButton(
+ style: ElevatedButton.styleFrom(
+ shape: CircleBorder(),
+ padding: EdgeInsets.all(size / 4),
+ primary: Colors.blue,
+ onPrimary: Colors.red,
+ ),
+ onPressed: () {
+ onSetNavigationIndex(tabPosition);
+ },
+ child: Icon(
+ icon,
+ color: Colors.white,
+ size: size / 2,
+ ),
+ ),
);
}
}