initial commit
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../core/models/models.dart';
|
||||
import '../../core/network/api_exception.dart';
|
||||
import '../../core/theme/theme_x.dart';
|
||||
import '../../core/widgets/error_banner.dart';
|
||||
import '../../data/repositories/node_repository.dart';
|
||||
import 'widgets/updates_table.dart';
|
||||
|
||||
class UpdatesScreen extends ConsumerWidget {
|
||||
const UpdatesScreen({super.key});
|
||||
|
||||
Future<void> _delete(BuildContext context, WidgetRef ref, UpdateRecord record) async {
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Delete update record?'),
|
||||
content: const Text('This removes the record from NodeMaster\'s log. It does not undo the update.'),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.of(context).pop(false), child: const Text('Cancel')),
|
||||
FilledButton(
|
||||
style: FilledButton.styleFrom(backgroundColor: context.status.critical),
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: const Text('Delete'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (confirmed != true) return;
|
||||
|
||||
final repo = ref.read(nodeRepositoryProvider);
|
||||
if (repo == null) return;
|
||||
try {
|
||||
await repo.deleteUpdate(record.id);
|
||||
ref.invalidate(updatesListProvider);
|
||||
} catch (e) {
|
||||
final message = e is ApiException ? e.userMessage : e.toString();
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final updatesAsync = ref.watch(updatesListProvider);
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
updatesAsync.maybeWhen(
|
||||
data: (records) => '${records.length} UPDATE RECORD(S)',
|
||||
orElse: () => 'UPDATE HISTORY',
|
||||
),
|
||||
style: context.text.titleSmall,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Expanded(
|
||||
child: updatesAsync.when(
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error: (error, stackTrace) => Align(
|
||||
alignment: Alignment.topCenter,
|
||||
child: ErrorBanner(
|
||||
message: error is ApiException ? error.userMessage : error.toString(),
|
||||
onRetry: () => ref.invalidate(updatesListProvider),
|
||||
),
|
||||
),
|
||||
data: (records) => SingleChildScrollView(
|
||||
child: UpdatesTable(
|
||||
records: records,
|
||||
onDelete: (record) => _delete(context, ref, record),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user