我一直在寻找从CupertinoTimerPicker返回数据的方法,但我只能使用navigator.pop返回数据,但没有使用导航器来推动屏幕。返回数据的正确方法是什么?
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
class SetTimerButton extends StatefulWidget {
@override
_SetTimerButtonState createState() => _SetTimerButtonState();
}
class _SetTimerButtonState extends State<SetTimerButton> {
Duration initialtimer = new Duration();
@override
Widget build(BuildContext context) {
return Builder(
builder: (context) => FlatButton(
color: Colors.white,
textColor: Colors.grey,
disabledColor: Colors.grey,
disabledTextColor: Colors.black,
onPressed: () {
showModalBottomSheet(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
backgroundColor: Colors.white,
context: context,
builder: (builder) {
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;
});
},
),
)
);
}
);
},
child: Row(
children: <Widget>[
Expanded(
child: Text(
"No Timer",
style: TextStyle(fontSize: 20.0),
),
),
Icon(Icons.arrow_forward_ios),
],
),
)
);
}
}
答案 0 :(得分:0)
showModalBottomSheet(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
backgroundColor: Colors.white,
context: context,
builder: (builder) {
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;
});
},
),
));
}, // fix form
).whenComplete(() {
print(initialtimer.toString());
}); // fix to