Frontend first draft
This commit is contained in:
28
frontend/pshared/lib/widgets/template.dart
Normal file
28
frontend/pshared/lib/widgets/template.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/provider/template.dart';
|
||||
|
||||
|
||||
class ResourceContainer<T extends GenericProvider> extends StatelessWidget {
|
||||
final Widget Function(BuildContext context, T provider) builder;
|
||||
final Widget? loading;
|
||||
final Widget? error;
|
||||
final Widget? empty;
|
||||
|
||||
const ResourceContainer({
|
||||
required this.builder,
|
||||
this.loading,
|
||||
this.error,
|
||||
this.empty,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Consumer<T>(builder: (context, provider, _) {
|
||||
if (provider.isLoading) return loading ?? Center(child: CircularProgressIndicator());
|
||||
if (provider.error != null) return error ?? Text('Error while loading data. Try again'); //TODO: need to implement localizations and add more details to the error
|
||||
if (provider.isEmpty) return empty ?? Text('Empty data'); //TODO: need to implement localizations too
|
||||
return builder(context, provider);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user