Files
Obtainium/lib/pages/home.dart
2022-08-27 16:37:27 -04:00

55 lines
1.5 KiB
Dart

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