#14 add ssh log
This commit is contained in:
47
lib/view/widget/future_widget.dart
Normal file
47
lib/view/widget/future_widget.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class FutureWidget<T> extends StatelessWidget {
|
||||
final Future future;
|
||||
final Widget loading;
|
||||
final Widget Function(Object? error, StackTrace? trace) error;
|
||||
final Widget Function(T data) success;
|
||||
final Widget noData;
|
||||
final Widget Function(AsyncSnapshot<Object?> snapshot)? active;
|
||||
|
||||
const FutureWidget({
|
||||
super.key,
|
||||
required this.future,
|
||||
required this.loading,
|
||||
required this.error,
|
||||
required this.success,
|
||||
required this.noData,
|
||||
this.active,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder(
|
||||
future: future,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
return error(snapshot.error, snapshot.stackTrace);
|
||||
}
|
||||
switch (snapshot.connectionState) {
|
||||
case ConnectionState.none:
|
||||
case ConnectionState.waiting:
|
||||
return loading;
|
||||
case ConnectionState.active:
|
||||
if (active != null) {
|
||||
return active!(snapshot);
|
||||
}
|
||||
return loading;
|
||||
case ConnectionState.done:
|
||||
if (snapshot.hasData) {
|
||||
return success(snapshot.data as T);
|
||||
}
|
||||
return noData;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user