forked from Jamalianpour/time_planner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemp.txt
362 lines (346 loc) · 13.5 KB
/
temp.txt
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
import 'package:flutter/material.dart';
import 'package:time_planner/src/time_planner_style.dart';
import 'package:time_planner/src/config/global_config.dart' as config;
import 'package:time_planner/src/time_planner_task.dart';
import 'package:time_planner/src/time_planner_time.dart';
import 'package:time_planner/src/time_planner_title.dart';
/// Time planner widget
class TimePlanner extends StatefulWidget {
/// Time start from this, it will start from 0
final int startHour;
/// Time end at this hour, max value is 23
final int endHour;
/// Create days from here, each day is a TimePlannerTitle.
///
/// you should create at least one day
final List<TimePlannerTitle> headers;
/// List of widgets on time planner
final List<TimePlannerTask>? tasks;
/// Style of time planner
final TimePlannerStyle? style;
/// When widget loaded scroll to current time with an animation. Default is true
final bool? currentTimeAnimation;
/// Time planner widget
const TimePlanner({
Key? key,
required this.startHour,
required this.endHour,
required this.headers,
this.tasks,
this.style,
this.currentTimeAnimation,
}) : super(key: key);
@override
_TimePlannerState createState() => _TimePlannerState();
}
class _TimePlannerState extends State<TimePlanner> {
ScrollController mainHorizontalController = ScrollController();
ScrollController mainVerticalController = ScrollController();
ScrollController dayHorizontalController = ScrollController();
ScrollController timeVerticalController = ScrollController();
TimePlannerStyle style = TimePlannerStyle();
List<TimePlannerTask> tasks = [];
bool? isAnimated = true;
/// check input value rules
void _checkInputValue() {
if (widget.startHour > widget.endHour) {
throw FlutterError("Start hour should be lower than end hour");
} else if (widget.startHour < 0) {
throw FlutterError("Start hour should be larger than 0");
} else if (widget.endHour > 23) {
throw FlutterError("Start hour should be lower than 23");
} else if (widget.headers.isEmpty) {
throw FlutterError("header can't be empty");
}
}
/// create local style
void _convertToLocalStyle() {
style.backgroundColor = widget.style?.backgroundColor;
style.cellHeight = widget.style?.cellHeight ?? 80;
style.cellWidth = widget.style?.cellWidth ?? 90;
style.horizontalTaskPadding = widget.style?.horizontalTaskPadding ?? 0;
style.borderRadius = widget.style?.borderRadius ??
const BorderRadius.all(Radius.circular(8.0));
style.dividerColor = widget.style?.dividerColor;
style.showScrollBar = widget.style?.showScrollBar ?? false;
}
/// store input data to static values
void _initData() {
_checkInputValue();
_convertToLocalStyle();
config.horizontalTaskPadding = style.horizontalTaskPadding;
config.cellHeight = style.cellHeight;
config.cellWidth = style.cellWidth;
config.totalHours = (widget.endHour - widget.startHour).toDouble();
config.totalDays = widget.headers.length;
config.startHour = widget.startHour;
config.borderRadius = style.borderRadius;
isAnimated = widget.currentTimeAnimation;
tasks = widget.tasks ?? [];
}
@override
void initState() {
_initData();
super.initState();
Future.delayed(Duration.zero).then((_) {
int hour = DateTime.now().hour;
if (isAnimated != null && isAnimated == true) {
if (hour > widget.startHour) {
double scrollOffset =
(hour - widget.startHour) * config.cellHeight!.toDouble();
mainVerticalController.animateTo(
scrollOffset,
duration: const Duration(milliseconds: 800),
curve: Curves.easeOutCirc,
);
timeVerticalController.animateTo(
scrollOffset,
duration: const Duration(milliseconds: 800),
curve: Curves.easeOutCirc,
);
}
}
});
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
mainHorizontalController.addListener(() {
dayHorizontalController.jumpTo(mainHorizontalController.offset);
});
mainVerticalController.addListener(() {
timeVerticalController.jumpTo(mainVerticalController.offset);
});
return GestureDetector(
child: Container(
color: style.backgroundColor,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SingleChildScrollView(
controller: dayHorizontalController,
scrollDirection: Axis.horizontal,
physics: const NeverScrollableScrollPhysics(),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const SizedBox(
width: 60,
),
for (int i = 0; i < config.totalDays; i++) widget.headers[i],
],
),
),
Container(
height: 1,
color: style.dividerColor ?? Theme.of(context).primaryColor,
),
Expanded(
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ScrollConfiguration(
behavior: ScrollConfiguration.of(context)
.copyWith(scrollbars: false),
child: SingleChildScrollView(
physics: const NeverScrollableScrollPhysics(),
controller: timeVerticalController,
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
//first number is start hour and second number is end hour
for (int i = widget.startHour;
i <= widget.endHour;
i++)
TimePlannerTime(
time: i.toString() + ':00',
),
],
),
Container(
height:
(config.totalHours * config.cellHeight!) + 80,
width: 2,
color: style.dividerColor ??
Theme.of(context).primaryColor,
),
],
),
),
),
Expanded(
child: buildMainBody(),
),
],
),
),
],
),
),
);
}
Widget buildMainBody() {
if (style.showScrollBar!) {
return Scrollbar(
controller: mainVerticalController,
thumbVisibility: true,
child: SingleChildScrollView(
controller: mainVerticalController,
child: Scrollbar(
controller: mainHorizontalController,
thumbVisibility: true,
child: SingleChildScrollView(
controller: mainHorizontalController,
scrollDirection: Axis.horizontal,
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SizedBox(
height: (config.totalHours * config.cellHeight!) + 80,
width:
(config.totalDays * config.cellWidth!).toDouble(),
child: Stack(
children: <Widget>[
Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
for (var i = 0; i < config.totalHours; i++)
Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SizedBox(
height:
(config.cellHeight! - 1).toDouble(),
),
const Divider(
height: 1,
color: Colors.white,
),
],
)
],
),
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
for (var i = 0; i < config.totalDays; i++)
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SizedBox(
width:
(config.cellWidth! - 1).toDouble(),
),
Container(
width: 1,
height: (config.totalHours *
config.cellHeight!) +
config.cellHeight!,
color: Colors.white,
)
],
)
],
),
for (int i = 0; i < tasks.length; i++) tasks[i],
],
),
),
],
),
],
),
),
),
),
);
}
return SingleChildScrollView(
controller: mainVerticalController,
child: SingleChildScrollView(
controller: mainHorizontalController,
scrollDirection: Axis.horizontal,
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SizedBox(
height: (config.totalHours * config.cellHeight!) + 80,
width: (config.totalDays * config.cellWidth!).toDouble(),
child: Stack(
children: <Widget>[
Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
for (var i = 0; i < config.totalHours; i++)
Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SizedBox(
height: (config.cellHeight! - 1).toDouble(),
),
const Divider(
height: 1,
),
],
)
],
),
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
for (var i = 0; i < config.totalDays; i++)
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SizedBox(
width: (config.cellWidth! - 1).toDouble(),
),
Container(
width: 1,
height:
(config.totalHours * config.cellHeight!) +
config.cellHeight!,
color: Colors.black12,
)
],
)
],
),
for (int i = 0; i < tasks.length; i++) tasks[i],
],
),
),
],
),
],
),
),
);
}
}