Back button switches to apps + more haptics

This commit is contained in:
Imran Remtulla
2022-08-27 16:37:27 -04:00
parent 5e785ae1d5
commit c14c4d2f14

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:obtainium/pages/add_app.dart'; import 'package:obtainium/pages/add_app.dart';
import 'package:obtainium/pages/apps.dart'; import 'package:obtainium/pages/apps.dart';
import 'package:obtainium/pages/settings.dart'; import 'package:obtainium/pages/settings.dart';
@ -20,22 +21,34 @@ class _HomePageState extends State<HomePage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return WillPopScope(
appBar: AppBar(title: const Text('Obtainium')), child: Scaffold(
body: pages.elementAt(selectedIndex), appBar: AppBar(title: const Text('Obtainium')),
bottomNavigationBar: NavigationBar( body: pages.elementAt(selectedIndex),
destinations: const [ bottomNavigationBar: NavigationBar(
NavigationDestination(icon: Icon(Icons.settings), label: 'Settings'), destinations: const [
NavigationDestination(icon: Icon(Icons.apps), label: 'Apps'), NavigationDestination(
NavigationDestination(icon: Icon(Icons.add), label: 'Add App'), icon: Icon(Icons.settings), label: 'Settings'),
], NavigationDestination(icon: Icon(Icons.apps), label: 'Apps'),
onDestinationSelected: (int index) { NavigationDestination(icon: Icon(Icons.add), label: 'Add App'),
setState(() { ],
selectedIndex = index; onDestinationSelected: (int index) {
}); HapticFeedback.lightImpact();
}, setState(() {
selectedIndex: selectedIndex, selectedIndex = index;
), });
); },
selectedIndex: selectedIndex,
),
),
onWillPop: () async {
if (selectedIndex != 1) {
setState(() {
selectedIndex = 1;
});
return false;
}
return true;
});
} }
} }