如何在颤动时将 CupertinoTimerPicker(timerpicker.dart) 中的数据返回给 showModalBottomSheet(form.dart)?
我想使用 navigator.pop 或 sth 但它不像 ondismissed() 函数?
timerpicker.dart
class TimerModal extends StatefulWidget {
@override
_TimerModalState createState() => _TimerModalState();
}
class _TimerModalState extends State<TimerModal> {
Duration _initialtimer = new Duration();
@override
Widget build(BuildContext context) {
return Container(
height: MediaQuery.of(context).copyWith().size.height / 3,
child: SizedBox.expand(
child: CupertinoTimerPicker(
mode: CupertinoTimerPickerMode.hm,
minuteInterval: 1,
secondInterval: 1,
initialTimerDuration: _initialtimer,
onTimerDurationChanged: (Duration changedtimer) {
setState(() {
_initialtimer = changedtimer;
});
},
),
)
);
}
}
表单.dart
FlatButton _timerPickerModal() {
return FlatButton(
color: Colors.white,
textColor: Colors.grey,
disabledColor: Colors.grey,
disabledTextColor: Colors.black,
// padding: EdgeInsets.all(8.0),
// splashColor: Colors.blueAccent,
onPressed: () async {
final result = await showModalBottomSheet(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
backgroundColor: Colors.white,
context: context,
builder: (builder) => TimerModal()
);
print(result);
// setState(() {
// _newTimer = result;
// });
},
child: Row(
children: <Widget>[
Expanded(
child: Text(
"Timer: " + _checkTimerText(_newTimer),
style: TextStyle(fontSize: 20.0),
),
),
Icon(Icons.arrow_forward_ios),
],
),
);
}