Frontend first draft
This commit is contained in:
31
frontend/pweb/lib/providers/template.dart
Normal file
31
frontend/pweb/lib/providers/template.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
|
||||
class FutureProviderTemplate<T> extends ChangeNotifier {
|
||||
FutureProviderTemplate({required this.loader});
|
||||
|
||||
final Future<T> Function() loader;
|
||||
|
||||
T? _data;
|
||||
bool _isLoading = false;
|
||||
String? _error;
|
||||
|
||||
T? get data => _data;
|
||||
bool get isLoading => _isLoading;
|
||||
String? get error => _error;
|
||||
|
||||
Future<void> load() async {
|
||||
_isLoading = true;
|
||||
_error = null;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
_data = await loader();
|
||||
} catch (e) {
|
||||
_error = e.toString();
|
||||
}
|
||||
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user