33// found in the LICENSE file.
44import 'package:flutter/cupertino.dart' ;
55import 'package:flutter/material.dart' ;
6- import 'package:intl/intl.dart' ;
76
87import 'cupertino_navigation_demo.dart' show coolColorNames;
98
@@ -20,8 +19,7 @@ class CupertinoPickerDemo extends StatefulWidget {
2019class _CupertinoPickerDemoState extends State <CupertinoPickerDemo > {
2120 int _selectedColorIndex = 0 ;
2221
23- int _selectedHour = 0 ;
24- int _selectedMinute = 0 ;
22+ Duration timer = new Duration ();
2523
2624 Widget _buildMenu (List <Widget > children) {
2725 return new Container (
@@ -74,63 +72,6 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> {
7472 );
7573 }
7674
77- Widget _buildAlarmPicker () {
78- return new Row (
79- children: < Widget > [
80- new Expanded (
81- child: new CupertinoPicker (
82- scrollController: new FixedExtentScrollController (
83- initialItem: _selectedHour,
84- ),
85- offAxisFraction: - 0.5 ,
86- useMagnifier: true ,
87- magnification: 1.1 ,
88- itemExtent: _kPickerItemHeight,
89- backgroundColor: CupertinoColors .white,
90- onSelectedItemChanged: (int index) {
91- setState (() {
92- _selectedHour = index;
93- });
94- },
95- children: new List <Widget >.generate (24 , (int index) {
96- return new Container (
97- alignment: Alignment .centerRight,
98- padding: const EdgeInsets .only (right: 32.0 ),
99- child: new Text (index.toString ()),
100- );
101- }),
102- looping: true ,
103- ),
104- ),
105- new Expanded (
106- child: new CupertinoPicker (
107- scrollController: new FixedExtentScrollController (
108- initialItem: _selectedMinute,
109- ),
110- offAxisFraction: 0.5 ,
111- useMagnifier: true ,
112- magnification: 1.1 ,
113- itemExtent: _kPickerItemHeight,
114- backgroundColor: CupertinoColors .white,
115- onSelectedItemChanged: (int index) {
116- setState (() {
117- _selectedMinute = index;
118- });
119- },
120- children: new List <Widget >.generate (60 , (int index) {
121- return new Container (
122- alignment: Alignment .centerLeft,
123- padding: const EdgeInsets .only (left: 32.0 ),
124- child: new Text (index.toString ()),
125- );
126- }),
127- looping: true ,
128- ),
129- ),
130- ],
131- );
132- }
133-
13475 Widget _buildBottomPicker (Widget picker) {
13576 return new Container (
13677 height: _kPickerSheetHeight,
@@ -151,9 +92,41 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> {
15192 );
15293 }
15394
95+ Widget _buildCountdownTimerPicker (BuildContext context) {
96+ return new GestureDetector (
97+ onTap: () {
98+ showCupertinoModalPopup <void >(
99+ context: context,
100+ builder: (BuildContext context) {
101+ return _buildBottomPicker (
102+ new CupertinoTimerPicker (
103+ initialTimerDuration: timer,
104+ onTimerDurationChanged: (Duration newTimer) {
105+ setState (() {
106+ timer = newTimer;
107+ });
108+ },
109+ ),
110+ );
111+ },
112+ );
113+ },
114+ child: _buildMenu (
115+ < Widget > [
116+ const Text ('Countdown Timer' ),
117+ new Text (
118+ '${timer .inHours }:'
119+ '${(timer .inMinutes % 60 ).toString ().padLeft (2 ,'0' )}:'
120+ '${(timer .inSeconds % 60 ).toString ().padLeft (2 ,'0' )}' ,
121+ style: const TextStyle (color: CupertinoColors .inactiveGray),
122+ ),
123+ ]
124+ ),
125+ );
126+ }
127+
154128 @override
155129 Widget build (BuildContext context) {
156- final String time = new DateFormat .Hm ().format (new DateTime (2018 , 1 , 1 , _selectedHour, _selectedMinute));
157130 return new Scaffold (
158131 appBar: new AppBar (
159132 title: const Text ('Cupertino Picker' ),
@@ -171,50 +144,30 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> {
171144 const Padding (padding: EdgeInsets .only (top: 32.0 )),
172145 new GestureDetector (
173146 onTap: () async {
174- await showModalBottomSheet <void >(
147+ await showCupertinoModalPopup <void >(
175148 context: context,
176149 builder: (BuildContext context) {
177150 return _buildBottomPicker (_buildColorPicker ());
178151 },
179152 );
180153 },
181154 child: _buildMenu (
182- < Widget > [
183- const Text ('Favorite Color' ),
184- new Text (
185- coolColorNames[_selectedColorIndex],
186- style: const TextStyle (
187- color: CupertinoColors .inactiveGray
155+ < Widget > [
156+ const Text ('Favorite Color' ),
157+ new Text (
158+ coolColorNames[_selectedColorIndex],
159+ style: const TextStyle (
160+ color: CupertinoColors .inactiveGray
161+ ),
188162 ),
189- ),
190- ]
191- ),
192- ),
193- new GestureDetector (
194- onTap: () async {
195- await showModalBottomSheet <void >(
196- context: context,
197- builder: (BuildContext context) {
198- return _buildBottomPicker (_buildAlarmPicker ());
199- },
200- );
201- },
202- child: _buildMenu (
203- < Widget > [
204- const Text ('Alarm' ),
205- new Text (
206- time,
207- style: const TextStyle (
208- color: CupertinoColors .inactiveGray
209- ),
210- ),
211- ]
163+ ]
212164 ),
213165 ),
166+ _buildCountdownTimerPicker (context),
214167 ],
215168 ),
216169 ),
217170 ),
218171 );
219172 }
220- }
173+ }
0 commit comments