Flutter如何从CupertinoTimerPicker返回数据?

问题描述 投票:0回答:1

我正在研究从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),
          ],
        ),
      )
    );
  }
}
android flutter dart flutter-layout
1个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.