Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
462 views
in Technique[技术] by (71.8m points)

Flutter: do not open ExpansionTile

Before open this widget I need to validate other parameters for the user. So if the user clicks to soon I'll display a SnackBar saying "You forgot to do something first".

I can wrap the children inside this widget in a Visibility widget but the status would be open anyway.

Can I validate somehow this?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think you want to validate some fields, before opening the expansion tile.

You can use a boolean variable for that, first set the bool variable to false and after that validate your fields on the onExpansionChanged method and show the toast.

Assign a bool field, When your fields are validated then change that bool field to true ,

Let the bool field be false by default and then use it to hide the expansion tile childrens if false, and show the childrens if set to true.

  bool isValid = false;

ExpansionTile(
            onExpansionChanged: (value){
              if(isValid){
                print(" ok");
              }else{
                print("Show a toast, Please check all Fields");
              }
            },
                title: Text(
                  'Title',
                ),
                children: <Widget>[
                  isValid ? ListTile(
                    title: Text('data'),
                  ) : new Container(),
                ],
              ),

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...