scroll_picker_dialog.dart
2.2 KB
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
// Copyright (c) 2018, codegrue. All rights reserved. Use of this source code
// is governed by the MIT license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
import '../pickers/scroll_picker.dart';
import 'responsive_dialog.dart';
import '../interfaces/common_dialog_properties.dart';
/// This is a support widget that returns an Dialog with checkboxes as a Widget.
/// It is designed to be used in the showDialog method of other fields.
class ScrollPickerDialog extends StatefulWidget
implements ICommonDialogProperties {
ScrollPickerDialog({
this.title,
this.items,
this.initialItem,
this.headerColor,
this.headerTextColor,
this.backgroundColor,
this.buttonTextColor,
this.maxLongSide,
this.maxShortSide,
this.confirmText,
this.cancelText,
});
// Variables
final List<String> items;
final String initialItem;
@override
final String title;
@override
final Color headerColor;
@override
final Color headerTextColor;
@override
final Color backgroundColor;
@override
final Color buttonTextColor;
@override
final double maxLongSide;
@override
final double maxShortSide;
@override
final String confirmText;
@override
final String cancelText;
@override
State<ScrollPickerDialog> createState() =>
_ScrollPickerDialogState(initialItem);
}
class _ScrollPickerDialogState extends State<ScrollPickerDialog> {
_ScrollPickerDialogState(this.selectedItem);
String selectedItem;
@override
Widget build(BuildContext context) {
assert(context != null);
return ResponsiveDialog(
context: context,
title: widget.title,
headerColor: widget.headerColor,
headerTextColor: widget.headerTextColor,
backgroundColor: widget.backgroundColor,
buttonTextColor: widget.buttonTextColor,
maxLongSide: widget.maxLongSide,
maxShortSide: widget.maxLongSide,
confirmText: widget.confirmText,
cancelText: widget.cancelText,
child: ScrollPicker(
items: widget.items,
initialValue: selectedItem,
onChanged: (value) => setState(() => selectedItem = value),
),
okPressed: () => Navigator.of(context).pop(selectedItem),
);
}
}