【问题标题】:How to Hide Continue and Cancel button on Flutter Stepper如何隐藏 Flutter Stepper 上的继续和取消按钮
【发布时间】:2022-06-10 20:55:30
【问题描述】:

我想在步进器上隐藏继续和取消按钮 并更改为 On Enter Text Filed 以继续该步骤。 可能吗? 该怎么做?

谢谢

【问题讨论】:

    标签: android flutter flutter-layout


    【解决方案1】:

    将此添加到您的步进器中:

            child: Stepper(
              controlsBuilder: (BuildContext context, ControlsDetails controls) {
                return Row(
                  children: <Widget>[
                    Container(),
                  ],
                );
              },
    

    【讨论】:

      【解决方案2】:

      我已经使用此代码隐藏继续和取消。

      首先将变量hide声明为bool,值为false

      bool hide = false;
      

      然后在装订器中使用 controlsBuilder。

      对于颤振>2.6

      controlsBuilder: (BuildContext ctx, ControlsDetails dtl){
                 return Row(
                  children: <Widget>[
                    TextButton(
                      onPressed: dtl.onStepContinue,
                      child: Text(hide == true ? '' : 'NEXT'),
                    ),
                    TextButton(
                      onPressed: dtl.onStepCancel,
                      child: Text(hide == true ? '' :'CANCEL'),
                    ),
                  ],
                ); 
              },
      

      对于颤振

      controlsBuilder: (BuildContext context, { VoidCallback? onStepContinue, VoidCallback? onStepCancel }) {
               return Row(
                 children: <Widget>[
                   TextButton(
                     onPressed: onStepContinue,
                     child:  Text(hide == true ? '' : 'NEXT'),
                   ),
                   TextButton(
                     onPressed: onStepCancel,
                     child: Text(hide == true ? '' : 'CANCEL'),
                   ),
                 ],
               );
            },
      

      CMIIW

      谢谢,

      【讨论】:

        【解决方案3】:
              class MyHomePage extends StatefulWidget {
             const MyHomePage({Key? key}) : super(key: key);
        
               @override
                _MyHomePageState createState() => _MyHomePageState();
               }
        
              class _MyHomePageState extends State<MyHomePage> {
                     int _currentstep = 0;
        
              
               @override
              Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            centerTitle: true,
            backgroundColor: Colors.green,
            title: const Text('App',style: TextStyle(color: 
                 Colors.white), ),
                    ),
           
        
                 body: Stepper(
                  steps: [
            const Step(  state: _ _currentstep <= 0 ? 
              StepState.editing : StepState.complete,
              isActive: _ _currentstep >= 0,
                 title: Text('Account'), content: Center(child: 
              Text('Account'),)),
             const Step(state: _ _currentstep <= 1 ? 
              StepState.editing : StepState.complete,
              isActive: _ _currentstep >= 1,title: Text('Address'), 
           content: Center(child: 
            Text('Address'),)),
              const Step(state: _ _currentstep <= 2 ? 
              StepState.editing : StepState.complete,
              isActive: _ _currentstep >= 2,title: Text('Confirm'), content: Center(child: 
              Text('Confirm'),))
                   ],
              onStepContinue: () {
                if (_currentstep < (2)) {
                  setState(() {
                    _currentstep += 1;
                  });
                } ),
                controlsBuilder: (context, details) {
                return Row(
                  mainAxisAlignment: _currentstep != 0
                      ? MainAxisAlignment.spaceBetween
                      : MainAxisAlignment.end,
                  children: [
                    if (_currentstep != 0)
                      ElevatedButton(
                          style: ElevatedButton.styleFrom(
                              side: const BorderSide(color: Colors.grey),
                              shape: RoundedRectangleBorder(
                                  borderRadius: 
               BorderRadius.circular(10)),
                              fixedSize: Size(20.w, 6.h),
                              elevation: 0,
                              primary: Colors.white),
                          onPressed: details.onStepCancel,
                          child: Icon(
                            Icons.arrow_back_ios,
                            color: Colors.grey[300],
                          )),
                    ElevatedButton(
                        style: ElevatedButton.styleFrom(
                            shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(10)),
                            fixedSize: Size(45, 6),
                            primary: buttonColor),
                        onPressed: details.onStepContinue,
                        child: Text(
                          "Next",
                          style: TextStyle(
                              color: Colors.white,
                              fontSize: 13,
                              fontWeight: FontWeight.bold),
                        ))
                  ],
                );
              },
                  )
                 );
                  }
             }
        

        通过在控件生成器中应用条件,您可以隐藏或显示下一个或上一个。按钮

        【讨论】:

          【解决方案4】:

          隐藏步进按钮的简单方法:

          controlsBuilder: (BuildContext context, ControlsDetails controls) {
              return const SizedBox.shrink();
          },
          

          你必须在Stepper里面通过这段代码

          【讨论】:

            猜你喜欢
            • 2013-11-18
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2021-10-19
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多