-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwelcome.dart
149 lines (129 loc) · 4.01 KB
/
welcome.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import 'package:flutter/material.dart';
class WelcomeScreen extends StatefulWidget {
@override
State<StatefulWidget> createState() => _WelcomeScreenState();
}
class _WelcomeScreenState extends State<WelcomeScreen> with SingleTickerProviderStateMixin {
TabController _tabController;
int page = 0;
String nextText = "Lanjut";
@override
void initState() {
super.initState();
_tabController = TabController(vsync: this, length: contents.length);
}
@override
void dispose() {
_tabController.dispose();
super.dispose();
}
void _nextPage(int delta) {
final int newIndex = _tabController.index + delta;
setState(() {
page = newIndex;
print("page: $page");
print("text: ${_tabController.previousIndex}");
});
if (newIndex == _tabController.length) {
setState(() {
nextText = "LOGIN";
});
} else {
setState(() {
nextText = "LANJUT";
});
}
if(newIndex < 0 || newIndex >= _tabController.length) return;
_tabController.animateTo(newIndex);
}
Widget _buildBody() {
return Container(
// color: Colors.red,
child: Stack(
fit: StackFit.expand,
alignment: Alignment.center,
children: <Widget>[
_buildTab(),
Positioned(
child: _buildPageSelector(),
bottom: 20.0,
),
],
),
);
}
Widget _buildTab() {
return TabBarView(
controller: _tabController,
children: contents.map((WelcomeContent content) {
return Padding(
padding: const EdgeInsets.all(0.0),
child: WelcomeCard(content: content,),
);
}).toList(),
);
}
Widget _buildPageSelector() {
return PreferredSize(
child: Theme(
data: Theme.of(context).copyWith(accentColor: Colors.white),
child: Container(
height: 48.0,
alignment: Alignment.center,
child: TabPageSelector(
controller: _tabController,
),
)),
preferredSize: const Size.fromHeight(48.0),
);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: _buildBody(),
),
);
}
}
class WelcomeContent {
final String title;
final String text;
final IconData icon;
final Color color;
const WelcomeContent({this.title = "", this.text, this.icon, this.color});
}
const List<WelcomeContent> contents = const <WelcomeContent>[
const WelcomeContent(title: 'JUDULNYA', text: 'blablabalabalaa', icon: Icons.directions_car, color: Colors.blue),
const WelcomeContent(title: 'JUDULNYA', text: 'BICYCLE', icon: Icons.directions_bike, color: Colors.orange),
const WelcomeContent(title: 'JUDULNYA', text: 'BOAT', icon: Icons.directions_boat, color: Colors.green),
const WelcomeContent(title: 'JUDULNYA', text: 'BUS', icon: Icons.directions_bus, color: Colors.yellow),
const WelcomeContent(title: 'JUDULNYA', text: 'TRAIN', icon: Icons.directions_railway, color: Colors.lightBlue),
const WelcomeContent(title: 'JUDULNYA', text: 'WALK', icon: Icons.directions_walk, color: Colors.red),
];
class WelcomeCard extends StatelessWidget {
const WelcomeCard({Key key, this.content}): super(key: key);
final WelcomeContent content;
@override
Widget build(BuildContext context) {
final TextStyle styleTitle = Theme.of(context).textTheme.display1;
final TextStyle styleContent = Theme.of(context).textTheme.headline;
print("choice: ${content.text}");
return Container(
color: content.color,
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Icon(content.icon, size: 128.0, color: styleTitle.color),
Padding(padding: EdgeInsets.only(top: 20.0)),
Text(content.title, style: styleTitle,),
Padding(padding: EdgeInsets.only(top: 20.0)),
Text(content.text, style: styleContent),
],
),
),
);
}
}