-
Notifications
You must be signed in to change notification settings - Fork 105
/
list_view.dart
98 lines (90 loc) · 2.96 KB
/
list_view.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
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:flutter/material.dart';
import 'diagram_step.dart';
class ListViewDiagram extends StatelessWidget with DiagramMetadata {
const ListViewDiagram(this.name, {super.key});
@override
final String name;
static const List<String> entries = <String>['A', 'B', 'C'];
static const List<int> colorCodes = <int>[600, 500, 100];
@override
Widget build(BuildContext context) {
Widget returnWidget;
switch (name) {
case 'list_view':
returnWidget = ListView(
padding: const EdgeInsets.all(8.0),
children: <Widget>[
Container(
height: 50,
color: Colors.amber[600],
child: const Center(child: Text('Entry A')),
),
Container(
height: 50,
color: Colors.amber[500],
child: const Center(child: Text('Entry B')),
),
Container(
height: 50,
color: Colors.amber[100],
child: const Center(child: Text('Entry C')),
),
],
);
break;
case 'list_view_builder':
returnWidget = ListView.builder(
padding: const EdgeInsets.all(8.0),
itemCount: entries.length,
itemBuilder: (BuildContext context, int index) {
return Container(
height: 50,
color: Colors.amber[colorCodes[index]],
child: Center(child: Text('Entry ${entries[index]}')),
);
});
break;
case 'list_view_separated':
returnWidget = ListView.separated(
padding: const EdgeInsets.all(8.0),
itemCount: entries.length,
itemBuilder: (BuildContext context, int index) {
return Container(
height: 50,
color: Colors.amber[colorCodes[index]],
child: Center(child: Text('Entry ${entries[index]}')),
);
},
separatorBuilder: (BuildContext context, int index) =>
const Divider(),
);
break;
default:
returnWidget = const Text('Error');
break;
}
return ConstrainedBox(
key: UniqueKey(),
constraints: BoxConstraints.tight(const Size(400.0, 250.0)),
child: Container(
alignment: FractionalOffset.center,
padding: const EdgeInsets.all(5.0),
color: Colors.white,
child: returnWidget),
);
}
}
class ListViewDiagramStep extends DiagramStep {
@override
final String category = 'widgets';
@override
Future<List<ListViewDiagram>> get diagrams async => <ListViewDiagram>[
const ListViewDiagram('list_view'),
const ListViewDiagram('list_view_builder'),
const ListViewDiagram('list_view_separated'),
];
}