Side menu now shows everything that stored in db

And it's clickable
Tracking ability soon
This commit is contained in:
dan63047 2023-06-09 01:06:03 +03:00
parent ff04c27edb
commit ae14e1789c
1 changed files with 68 additions and 49 deletions

View File

@ -75,7 +75,6 @@ class _MainState extends State<MainView> with SingleTickerProviderStateMixin {
@override @override
void initState() { void initState() {
//teto = TetrioService();
teto.open(); teto.open();
_scrollController = ScrollController(); _scrollController = ScrollController();
_tabController = TabController(length: 4, vsync: this); _tabController = TabController(length: 4, vsync: this);
@ -88,7 +87,6 @@ class _MainState extends State<MainView> with SingleTickerProviderStateMixin {
void dispose() { void dispose() {
_tabController.dispose(); _tabController.dispose();
_scrollController.dispose(); _scrollController.dispose();
//db.close();
super.dispose(); super.dispose();
developer.log("Main view disposed", name: "main_view"); developer.log("Main view disposed", name: "main_view");
} }
@ -105,20 +103,6 @@ class _MainState extends State<MainView> with SingleTickerProviderStateMixin {
}); });
} }
// _scrollListener() {
// if (fixedScroll) {
// _scrollController.jumpTo(0);
// }
// }
// _smoothScrollToTop() {
// _scrollController.animateTo(
// 0,
// duration: const Duration(microseconds: 300),
// curve: Curves.ease,
// );
// }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -257,31 +241,33 @@ class _MainState extends State<MainView> with SingleTickerProviderStateMixin {
} }
} }
class NavDrawer extends StatelessWidget { class NavDrawer extends StatefulWidget {
final Function changePlayer; final Function changePlayer;
const NavDrawer(this.changePlayer, {super.key}); const NavDrawer(this.changePlayer, {super.key});
@override
State<NavDrawer> createState() => _NavDrawerState();
}
class _NavDrawerState extends State<NavDrawer> {
late ScrollController _scrollController;
@override
void initState() {
super.initState();
_scrollController = ScrollController();
}
@override
void dispose() {
_scrollController.dispose();
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Drawer( return Drawer(
child: ListView( child: StreamBuilder(
padding: EdgeInsets.zero,
children: <Widget>[
const DrawerHeader(
child: Text(
'Players you track',
style: TextStyle(color: Colors.white, fontSize: 25),
)),
ListTile(
leading: const Icon(Icons.home),
title: Text(prefs.getString("player") ?? "dan63047"),
onTap: () {
developer.log("Navigator changed player", name: "main_view");
changePlayer(prefs.getString("player") ?? "dan63047");
Navigator.of(context).pop();
},
),
StreamBuilder(
stream: teto.allPlayers, stream: teto.allPlayers,
builder: (context, snapshot) { builder: (context, snapshot) {
switch (snapshot.connectionState) { switch (snapshot.connectionState) {
@ -289,13 +275,46 @@ class NavDrawer extends StatelessWidget {
return Center(child: Text('none case of StreamBuilder')); return Center(child: Text('none case of StreamBuilder'));
case ConnectionState.waiting: case ConnectionState.waiting:
case ConnectionState.active: case ConnectionState.active:
return Center(child: Text('${snapshot.data}')); final allPlayers = (snapshot.data != null) ? snapshot.data as Map<String, List<TetrioPlayer>> : <String, List<TetrioPlayer>>{};
List<String> keys = allPlayers.keys.toList();
return NestedScrollView(
headerSliverBuilder: (context, value) {
return [
const SliverToBoxAdapter(
child: DrawerHeader(
child: Text(
'Players you track',
style: TextStyle(color: Colors.white, fontSize: 25),
))),
SliverToBoxAdapter(
child: ListTile(
leading: const Icon(Icons.home),
title: Text(prefs.getString("player") ?? "dan63047"),
onTap: () {
developer.log("Navigator changed player", name: "main_view");
widget.changePlayer(prefs.getString("player") ?? "dan63047");
Navigator.of(context).pop();
},
),
)
];
},
body: ListView.builder(
itemCount: allPlayers.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(allPlayers[keys[index]]?.last.username as String),
onTap: () {
developer.log("Navigator changed player", name: "main_view");
widget.changePlayer(keys[index]);
Navigator.of(context).pop();
},
);
}));
case ConnectionState.done: case ConnectionState.done:
return Center(child: Text('done case of StreamBuilder')); return Center(child: Text('done case of StreamBuilder'));
} }
}, },
)
],
), ),
); );
} }