tabs
This commit is contained in:
parent
378e777589
commit
5717d79a5f
1 changed files with 79 additions and 22 deletions
101
lib/main.dart
101
lib/main.dart
|
@ -18,38 +18,95 @@ class MyApp extends StatelessWidget {
|
|||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
||||
useMaterial3: true,
|
||||
),
|
||||
home: const HomePage(),
|
||||
home: const MyHomePage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class HomePage extends StatelessWidget {
|
||||
const HomePage({super.key});
|
||||
// todo : homepage with tabs
|
||||
// tab 1: home stats
|
||||
// tab 2: item list
|
||||
// tab 3: locations
|
||||
|
||||
class StatsPage extends StatelessWidget {
|
||||
const StatsPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold();
|
||||
}
|
||||
}
|
||||
|
||||
class LocationsPage extends StatelessWidget {
|
||||
const LocationsPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold();
|
||||
}
|
||||
}
|
||||
|
||||
class ItemsPage extends StatelessWidget {
|
||||
const ItemsPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text("Home Page")),
|
||||
body: Column(children: [
|
||||
const Row(children: [Text("Stats about everything")]),
|
||||
FutureBuilder(
|
||||
future: API().getItems(),
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData) {
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
appBar: AppBar(
|
||||
title: const Text("Items"),
|
||||
),
|
||||
body: FutureBuilder(
|
||||
future: API().getItems(),
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData) {
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
|
||||
var items = snapshot.data!;
|
||||
var items = snapshot.data!;
|
||||
|
||||
return Expanded(
|
||||
child: GridView.count(
|
||||
crossAxisCount: 2,
|
||||
children: items.map((x) {
|
||||
return ItemCard(x);
|
||||
}).toList(),
|
||||
));
|
||||
})
|
||||
]),
|
||||
return Expanded(
|
||||
child: GridView.count(
|
||||
crossAxisCount: 2,
|
||||
children: items.map((x) {
|
||||
return ItemCard(x);
|
||||
}).toList(),
|
||||
));
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
const MyHomePage({super.key});
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
int pageIndex = 0;
|
||||
|
||||
List<Widget> pages = [StatsPage(), ItemsPage(), LocationsPage()];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
items: const [
|
||||
BottomNavigationBarItem(icon: Icon(Icons.home), label: "Home"),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.data_object), label: "Items"),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.location_city), label: "Locations"),
|
||||
],
|
||||
currentIndex: pageIndex,
|
||||
onTap: (value) {
|
||||
setState(() {
|
||||
pageIndex = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
body: pages[pageIndex],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue