forked from flutter/assets-for-api-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_view.dart
107 lines (99 loc) · 3.32 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
99
100
101
102
103
104
105
106
107
// Copyright 2019 The Chromium 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 'dart:io';
import 'package:diagram_capture/diagram_capture.dart';
import 'package:flutter/material.dart';
import 'diagram_step.dart';
class ListViewDiagram extends StatelessWidget implements DiagramMetadata {
const ListViewDiagram(this.name);
@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<ListViewDiagram> {
ListViewDiagramStep(DiagramController controller) : super(controller);
@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'),
];
@override
Future<File> generateDiagram(ListViewDiagram diagram) async {
controller.builder = (BuildContext context) => diagram;
return await controller.drawDiagramToFile(File('${diagram.name}.png'));
}
}