flutter -time_range_picker软件包
我设法创建了一个函数(我放入了文本键),您可以在其中看到time_range_picker并选择范围。
我只是无法在文本小部件或按钮标签中显示结果。
class OpeningHours extends StatefulWidget {
const OpeningHours({Key? key}) : super(key: key);
@override
State<OpeningHours> createState() => _OpeningHoursState();
}
class _OpeningHoursState extends State<OpeningHours> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: TextButton.icon(
icon: const Icon(
FontAwesomeIcons.penToSquare,
color: Colors.white,
),
label: Text(
result.toString(), // it does not work
style: const TextStyle(
color: Colors.white,
fontSize: 22,
),
),
style: TextButton.styleFrom(
shadowColor: Colors.red,
elevation: 18,
backgroundColor: Colors.red),
onPressed: () {
pickTimeRange(context);
},
),
),
);
}
Future pickTimeRange(BuildContext context) async {
final TimeRange? result = await showTimeRangePicker(context: context);
}
}
I managed to create a function (which I put in a TextButton) where you can see the Time_range_picker and choose the range.
I just can't show the result either in a text widget or in the button label.
class OpeningHours extends StatefulWidget {
const OpeningHours({Key? key}) : super(key: key);
@override
State<OpeningHours> createState() => _OpeningHoursState();
}
class _OpeningHoursState extends State<OpeningHours> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: TextButton.icon(
icon: const Icon(
FontAwesomeIcons.penToSquare,
color: Colors.white,
),
label: Text(
result.toString(), // it does not work
style: const TextStyle(
color: Colors.white,
fontSize: 22,
),
),
style: TextButton.styleFrom(
shadowColor: Colors.red,
elevation: 18,
backgroundColor: Colors.red),
onPressed: () {
pickTimeRange(context);
},
),
),
);
}
Future pickTimeRange(BuildContext context) async {
final TimeRange? result = await showTimeRangePicker(context: context);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您应该像这样初始化计时器值
TimeRange?结果打印; // 添加这一行
,然后你应该使用setSteate
更新这个值,请检查我的代码,它会起作用
first you should initialize the timer value like this
TimeRange? resultForPrint; // add this line
,then you should update this value usingsetSteate
please check my code , it will work