/
image_api.dart
68 lines (57 loc) · 1.62 KB
/
image_api.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2022 Andrious Solutions Ltd. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
///
/// Manages the API request for specifically 'image' public API's
///
import 'package:example/src/controller.dart';
import 'package:example/src/view.dart';
/// The State object allows for a web service to be called.
class ImageAPIStateX<T extends StatefulWidget> extends StateX<T>
implements ImageAPIState {
///
ImageAPIStateX({
required this.uri,
this.message,
StateXController? controller,
}) : super(controller) {
//
final id = add(ImageAPIController());
// Retrieve the Controller by its unique id.
_con = controllerById(id) as ImageAPIController;
// or Simply by its type.
_con = controllerByType<ImageAPIController>()!;
}
///
@override
final Uri? uri;
///
@override
final String? message;
late ImageAPIController _con;
/// Supply the widget to the FutureBuilder. Don't implement an InheritedWidget
@override
Widget buildWidget(context) {
controller?.dependOnInheritedWidget(context);
return GestureDetector(
onTap: _con.onTap,
onDoubleTap: _con.onTap,
child: Card(
child: _con.image ?? const SizedBox(),
),
);
}
/// Supply an 'error handler' routine if something goes wrong
/// in the corresponding initAsync() routine.
@override
bool onAsyncError(FlutterErrorDetails details) => false;
}
///
abstract class ImageAPIState {
///
ImageAPIState({required this.uri, required this.message});
///
final Uri? uri;
///
final String? message;
}