Show/hide widgets in Flutter programmatically

前端 未结 13 1323
轮回少年
轮回少年 2020-11-28 04:13

In Android, every single View subclass has a setVisibility() method that allows you modify the visibility of a View object

The

13条回答
  •  日久生厌
    2020-11-28 04:45

    For beginner try this too.

    class Visibility extends StatefulWidget {
      @override
      _VisibilityState createState() => _VisibilityState();
    }
    
    class _VisibilityState extends State {
      bool a = true;
      String mText = "Press to hide";
    
      @override
      Widget build(BuildContext context) {
        return new MaterialApp(
          title: "Visibility",
          home: new Scaffold(
              body: new Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  new RaisedButton(
                    onPressed: _visibilitymethod, child: new Text(mText),),
                    a == true ? new Container(
                    width: 300.0,
                    height: 300.0,
                    color: Colors.red,
                  ) : new Container(),
                ],
              )
          ),
        );
      }
    
      void _visibilitymethod() {
        setState(() {
          if (a) {
            a = false;
            mText = "Press to show";
          } else {
            a = true;
            mText = "Press to hide";
          }
        });
      }
    }
    

提交回复
热议问题