Make a little better display

This commit is contained in:
2025-02-22 14:43:00 +01:00
parent 8c6ce9f6ff
commit 283c9dbbb3
2 changed files with 221 additions and 20 deletions

View File

@@ -60,7 +60,7 @@ class Game {
class GameRepository { class GameRepository {
static Future<Game> upsert(Game game) async { static Future<Game> upsert(Game game) async {
final db = await DB.db; final db = DB.db;
await db.rawInsert( await db.rawInsert(
''' '''
INSERT INTO games INSERT INTO games

View File

@@ -17,17 +17,23 @@ class MyApp extends StatelessWidget {
title: 'Gamer Updater', title: 'Gamer Updater',
theme: ThemeData( theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
), ),
darkTheme: ThemeData( darkTheme: ThemeData(
brightness: Brightness.dark, brightness: Brightness.dark,
useMaterial3: true, useMaterial3: true,
scaffoldBackgroundColor: Colors.black, scaffoldBackgroundColor: Colors.black,
colorSchemeSeed: Colors.black, colorSchemeSeed: Colors.deepPurple,
highlightColor: Colors.deepPurple, cardTheme: CardTheme(
textTheme: TextTheme( color: Colors.grey[900],
bodyLarge: TextStyle(fontSize: 22, fontWeight: FontWeight.bold), elevation: 4,
bodyMedium: TextStyle(fontSize: 20), margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
bodySmall: TextStyle(fontSize: 16), ),
textTheme: const TextTheme(
titleLarge: TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
bodyLarge: TextStyle(fontSize: 18),
bodyMedium: TextStyle(fontSize: 16),
bodySmall: TextStyle(fontSize: 14),
), ),
), ),
themeMode: ThemeMode.system, themeMode: ThemeMode.system,
@@ -50,15 +56,14 @@ class _MyHomePageState extends State<MyHomePage> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
GameRepository.getAll().then((games) { _refreshGames();
}
Future<void> _refreshGames() async {
final games = await GameRepository.getAll();
setState(() { setState(() {
this.games = games; this.games = games;
}); });
for (var e in games) {
e.updateActualVersion();
GameRepository.upsert(e);
}
});
} }
@override @override
@@ -67,13 +72,209 @@ class _MyHomePageState extends State<MyHomePage> {
appBar: AppBar( appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary, backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title), title: Text(widget.title),
actions: [
IconButton(icon: const Icon(Icons.refresh), onPressed: _refreshGames),
],
), ),
body: Center( body: RefreshIndicator(
onRefresh: _refreshGames,
child: GridView.builder(
padding: const EdgeInsets.all(8),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
childAspectRatio: 1.3,
crossAxisSpacing: 4,
mainAxisSpacing: 4,
),
itemCount: games.length,
itemBuilder: (context, index) {
return GameCard(
game: games[index],
onGameUpdated: (game) async {
game = await GameRepository.upsert(game);
setState(() {
games[index] = game;
});
},
);
},
),
),
);
}
}
class GameCard extends StatefulWidget {
final Game game;
final Function(Game) onGameUpdated;
const GameCard({super.key, required this.game, required this.onGameUpdated});
@override
State<GameCard> createState() => _GameCardState();
}
class _GameCardState extends State<GameCard>
with SingleTickerProviderStateMixin {
late final AnimationController _controller;
bool _isLoading = false;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(seconds: 1),
vsync: this,
);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
Future<void> _refreshVersion() async {
setState(() => _isLoading = true);
_controller.repeat();
final updatedGame = widget.game;
await updatedGame.updateActualVersion();
widget.onGameUpdated(updatedGame);
_controller.stop();
_controller.reset();
setState(() => _isLoading = false);
}
@override
Widget build(BuildContext context) {
final isUpToDate = widget.game.actualVersion == widget.game.lastPlayed;
return Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: [
Text(games.map((e) => e.name).join('\n')), Row(
Text(games.map((e) => e.actualVersion).join('\n')), mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
widget.game.name,
style: Theme.of(context).textTheme.titleLarge,
),
RotationTransition(
turns: _controller,
child: IconButton(
icon: const Icon(Icons.refresh),
onPressed: _isLoading ? null : _refreshVersion,
),
),
],
),
const SizedBox(height: 8),
Row(
children: [
SizedBox(
width: 120,
child: Text(
'Version:',
style: Theme.of(context).textTheme.bodyLarge,
),
),
Text(
widget.game.actualVersion.isEmpty
? 'Unknown'
: widget.game.actualVersion,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: isUpToDate ? Colors.green : Colors.red,
fontWeight: FontWeight.bold,
),
),
],
),
Row(
children: [
SizedBox(
width: 120,
child: Text(
'Last Updated:',
style: Theme.of(context).textTheme.bodyLarge,
),
),
Text(
widget.game.lastUpdated.isEmpty
? 'Never'
: DateTime.parse(widget.game.lastUpdated).toString(),
style: Theme.of(context).textTheme.bodyMedium,
),
],
),
Row(
children: [
SizedBox(
width: 120,
child: Text(
'Last Played:',
style: Theme.of(context).textTheme.bodyLarge,
),
),
Text(
widget.game.lastPlayed,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: isUpToDate ? Colors.green : Colors.red,
fontWeight: FontWeight.bold,
),
),
],
),
const Divider(),
TextField(
controller: TextEditingController(text: widget.game.versionRegex),
decoration: const InputDecoration(labelText: 'Version Regex'),
onChanged:
(value) => widget.onGameUpdated(
Game(
name: widget.game.name,
versionRegex: value,
lastPlayed: widget.game.lastPlayed,
rssFeedUrl: widget.game.rssFeedUrl,
actualVersion: widget.game.actualVersion,
lastUpdated: widget.game.lastUpdated,
),
),
),
TextField(
controller: TextEditingController(text: widget.game.rssFeedUrl),
decoration: const InputDecoration(labelText: 'RSS Feed URL'),
onChanged:
(value) => widget.onGameUpdated(
Game(
name: widget.game.name,
versionRegex: widget.game.versionRegex,
lastPlayed: widget.game.lastPlayed,
rssFeedUrl: value,
actualVersion: widget.game.actualVersion,
lastUpdated: widget.game.lastUpdated,
),
),
),
TextField(
controller: TextEditingController(text: widget.game.lastPlayed),
decoration: const InputDecoration(labelText: 'Last Played'),
onChanged:
(value) => widget.onGameUpdated(
Game(
name: widget.game.name,
versionRegex: widget.game.versionRegex,
lastPlayed: value,
rssFeedUrl: widget.game.rssFeedUrl,
actualVersion: widget.game.actualVersion,
lastUpdated: widget.game.lastUpdated,
),
),
),
], ],
), ),
), ),