/
main.dart
120 lines (110 loc) · 3.25 KB
/
main.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
108
109
110
111
112
113
114
115
116
117
118
119
120
import 'package:example/example.dart';
import 'package:example/examples/basic_example.dart';
import 'package:example/examples/builder_example.dart';
import 'package:example/examples/color_transition_example.dart';
import 'package:example/examples/compose_transition_example.dart';
import 'package:example/examples/cube_transition_example.dart';
import 'package:example/examples/linear_transition_example.dart';
import 'package:example/examples/scale_transition_example.dart';
import 'package:example/examples/vertical_example.dart';
import 'package:flutter/material.dart';
final examples = [
Example(
title: 'Basic example',
icon: Icons.eco,
route: '/basic',
itemBuilder: (context, example) => BasicExample(example),
),
Example(
title: 'Builder example',
icon: Icons.eco,
route: '/builder',
itemBuilder: (context, example) => BuilderExample(example),
),
Example(
title: 'Vertical example',
icon: Icons.eco,
route: '/vertical',
itemBuilder: (context, example) => VerticalExample(example),
),
Example(
title: 'Scale transition example',
icon: Icons.refresh,
route: '/scale-transition',
itemBuilder: (context, example) => ScaleTransitionExample(example),
),
Example(
title: 'Linear transition example',
icon: Icons.refresh,
route: '/linear-transition',
itemBuilder: (context, example) => LinearTransitionExample(example),
),
Example(
title: 'Cube transition example',
icon: Icons.refresh,
route: '/cube-transition',
itemBuilder: (context, example) => CubeTransitionExample(example),
),
Example(
title: 'Color transition example',
icon: Icons.refresh,
route: '/color-transition',
itemBuilder: (context, example) => ColorTransitionExample(example),
),
Example(
title: 'Compose transition example',
icon: Icons.refresh,
route: '/compose-transition',
itemBuilder: (context, example) => ComposeTransitionExample(example),
),
];
void main() => runApp(CarouselExample(examples));
class CarouselExample extends StatelessWidget {
final List<Example> examples;
CarouselExample(
this.examples, {
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
MapEntry<String, WidgetBuilder> entry(int index, Example example) {
return MapEntry(
example.route,
(context) => example.itemBuilder(context, example),
);
}
return MaterialApp(
initialRoute: '/',
routes: {
'/': (ctx) => HomePage(examples),
...examples.asMap().map(entry),
},
);
}
}
class HomePage extends StatelessWidget {
final List<Example> examples;
HomePage(
this.examples, {
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
Widget listTile(Example example) {
return Card(
child: ListTile(
leading: Icon(example.icon, color: Theme.of(context).primaryColor),
title: Text(example.title),
trailing: Icon(Icons.chevron_right),
onTap: () => Navigator.pushNamed(context, example.route),
),
);
}
return Scaffold(
appBar: AppBar(title: Text('Flutter Carousel Example')),
body: ListView(
children: examples.map(listTile).toList(),
),
);
}
}