-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlisting_feature.dart
101 lines (93 loc) · 3.92 KB
/
listing_feature.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import 'package:dart_board_core/dart_board_core.dart';
import 'package:dart_board_template_bottomnav/state/bottom_nav_state.dart';
import 'package:flutter/material.dart';
import 'package:transparent_image/transparent_image.dart';
import 'details_feature.dart';
import 'repository_feature.dart';
class ListingFeature extends DartBoardFeature {
@override
List<RouteDefinition> get routes => [
NamedRouteDefinition(
route: "/listings", builder: (context, settings) => _listingsScreen)
];
@override
String get namespace => "ListingsFeature";
@override
List<DartBoardFeature> get dependencies =>
[RepositoryFeature(repository: MockRepository())];
}
final _listingsScreen = ListingScreen();
class ListingScreen extends StatefulWidget {
@override
_ListingScreenState createState() => _ListingScreenState();
}
class _ListingScreenState extends State<ListingScreen> {
late final results = RepositoryMessenger.performSearch(context);
int _selection = 0;
@override
Widget build(BuildContext context) => Container(
child: FutureBuilder<List<ShortRecord>>(
future: results,
builder: (ctx, snapshot) {
if (snapshot.hasData && snapshot.data != null) {
/// Safe to unwrap
final data = snapshot.data!;
return ListView.builder(
itemCount: data.length,
itemBuilder: (ctx, idx) => ListTile(
selected: _selection == idx,
title: Row(
children: [
Expanded(
child: Text(
data[idx].title,
style: Theme.of(context).textTheme.headline3,
)),
Stack(
children: [
Container(
width: 200,
height: 200,
child: Material(
elevation: 2,
child: FadeInImage.memoryNetwork(
placeholder: kTransparentImage,
image: data[idx].imageUrl,
fit: BoxFit.cover,
width: 200,
),
),
),
Card(
child: InkWell(
onTap: () {
context
.dispatchMethod("addItemToCart", {
"id": data[idx].id,
});
},
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text("Add"),
)))
],
),
],
),
onTap: () {
/// Since we use BottomNav we can use the BottomNavMessenger
/// to tell BottomNav what tab to show
BottomNavMessenger.requestNewRoute(context, "/details");
/// Since we have a global state for a Main Details screen
/// we can call that here too.
MainDetailsMessenger.setId(context, idx);
setState(() {
/// Notify the selection
_selection = idx;
});
}));
} else {
return Text("Loading...");
}
}));
}