-
Notifications
You must be signed in to change notification settings - Fork 1
/
failure_handling_custom.dart
45 lines (39 loc) · 1.21 KB
/
failure_handling_custom.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import 'package:async_controller/async_controller.dart';
import 'package:example/helpers.dart';
import 'package:flutter/material.dart';
class FailureHandlingCustomPage extends StatefulWidget with ExamplePage {
@override
_FailureHandlingCustomPageState createState() =>
_FailureHandlingCustomPageState();
@override
String get title => 'Failure handling custom';
}
class _FailureHandlingCustomPageState extends State<FailureHandlingCustomPage> {
final _controller = AsyncController<int>.method(() async {
await Future<void>.delayed(Duration(seconds: 1));
throw 'Sorry, loading failed.';
});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: widget.buildAppBar(),
body: _controller.buildAsyncData(
builder: (_, data) {
return const Text('OK');
},
decorator: CustomAsyncDataDecoration(),
),
);
}
}
class CustomAsyncDataDecoration extends AsyncDataDecoration {
@override
Widget buildError(
BuildContext context, dynamic error, VoidCallback tryAgain) {
return Center(child: Text('Sorry :('));
}
@override
Widget buildNoDataYet(BuildContext context) {
return Center(child: Text('Loading...'));
}
}