GameHistoryView anpassen #20
@@ -22,4 +22,13 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
|||||||
final result = await query.getSingle();
|
final result = await query.getSingle();
|
||||||
return Game(id: result.id, name: result.name);
|
return Game(id: result.id, name: result.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Retrieves the number of games in the database.
|
||||||
|
Future<int> getGameCount() async {
|
||||||
|
final count =
|
||||||
|
await (selectOnly(gameTable)..addColumns([gameTable.id.count()]))
|
||||||
|
.map((row) => row.read(gameTable.id.count()))
|
||||||
|
.getSingle();
|
||||||
|
return count ?? 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,4 +56,13 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
|
|||||||
);
|
);
|
||||||
return rowsAffected > 0;
|
return rowsAffected > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Retrieves the number of groups in the database.
|
||||||
|
Future<int> getGroupCount() async {
|
||||||
|
final count =
|
||||||
|
await (selectOnly(groupTable)..addColumns([groupTable.id.count()]))
|
||||||
|
.map((row) => row.read(groupTable.id.count()))
|
||||||
|
.getSingle();
|
||||||
|
return count ?? 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,30 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:game_tracker/data/db/database.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/game_tile.dart';
|
import 'package:game_tracker/presentation/widgets/game_tile.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/quick_create_button.dart';
|
import 'package:game_tracker/presentation/widgets/quick_create_button.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/tiles/info_tile.dart';
|
import 'package:game_tracker/presentation/widgets/tiles/info_tile.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/tiles/quick_info_tile.dart';
|
import 'package:game_tracker/presentation/widgets/tiles/quick_info_tile.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class HomeView extends StatelessWidget {
|
class HomeView extends StatefulWidget {
|
||||||
const HomeView({super.key});
|
const HomeView({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<HomeView> createState() => _HomeViewState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _HomeViewState extends State<HomeView> {
|
||||||
|
late Future<int> _gameCountFuture;
|
||||||
|
late Future<int> _groupCountFuture;
|
||||||
|
|
||||||
|
@override
|
||||||
|
initState() {
|
||||||
|
super.initState();
|
||||||
|
final db = Provider.of<AppDatabase>(context, listen: false);
|
||||||
|
_gameCountFuture = db.gameDao.getGameCount();
|
||||||
|
_groupCountFuture = db.groupDao.getGroupCount();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return LayoutBuilder(
|
return LayoutBuilder(
|
||||||
@@ -18,25 +36,41 @@ class HomeView extends StatelessWidget {
|
|||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
QuickInfoTile(
|
FutureBuilder<int>(
|
||||||
width: constraints.maxWidth * 0.45,
|
future: _gameCountFuture,
|
||||||
height: constraints.maxHeight * 0.15,
|
builder: (context, snapshot) {
|
||||||
title: 'Games',
|
final int count = (snapshot.hasData) ? snapshot.data! : 0;
|
||||||
icon: Icons.casino,
|
return QuickInfoTile(
|
||||||
value: 42,
|
width: constraints.maxWidth * 0.45,
|
||||||
|
height: constraints.maxHeight * 0.15,
|
||||||
|
title: 'Games',
|
||||||
|
icon: Icons.groups_rounded,
|
||||||
|
value: count,
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
SizedBox(width: constraints.maxWidth * 0.05),
|
SizedBox(width: constraints.maxWidth * 0.05),
|
||||||
QuickInfoTile(
|
FutureBuilder<int>(
|
||||||
width: constraints.maxWidth * 0.45,
|
future: _groupCountFuture,
|
||||||
height: constraints.maxHeight * 0.15,
|
builder: (context, snapshot) {
|
||||||
title: 'Groups',
|
final int count =
|
||||||
icon: Icons.groups_rounded,
|
(snapshot.connectionState == ConnectionState.done &&
|
||||||
value: 5,
|
snapshot.hasData)
|
||||||
|
? snapshot.data!
|
||||||
|
: 0;
|
||||||
|
return QuickInfoTile(
|
||||||
|
width: constraints.maxWidth * 0.45,
|
||||||
|
height: constraints.maxHeight * 0.15,
|
||||||
|
title: 'Groups',
|
||||||
|
icon: Icons.groups_rounded,
|
||||||
|
value: count,
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 24.0),
|
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
||||||
child: InfoTile(
|
child: InfoTile(
|
||||||
width: constraints.maxWidth * 0.95,
|
width: constraints.maxWidth * 0.95,
|
||||||
title: 'Recent Games',
|
title: 'Recent Games',
|
||||||
|
|||||||
Reference in New Issue
Block a user