Pannam T
Pannam T

Reputation: 479

How do we print the value of a varible inside the widget?

I would like to print the values of boolean inside the widget Visibility how can I do it ?

Stack(
        children: [
            Scaffold(
                body: Container(
                    //change the margin
                    margin: EdgeInsets.fromLTRB(0, 0, 0, 300),
                    child: 
                    Visibility(
                        visible: mapVisible,

                        // print the value of the boolean mapVisible
                        maintainSemantics: true,
                        maintainInteractivity: true,
                        maintainAnimation: true,
                        maintainState: true,
                        maintainSize: true,
                        replacement: Container(), )

Upvotes: 0

Views: 552

Answers (1)

Terblanche Daniel
Terblanche Daniel

Reputation: 1465

Your question is rather vague. It could be one of 2 things.

  1. To print the variable value every time the widget builds you can just move the logic into a method like such.

    bool mapVisible = true;
    Stack(
            children: [
                Scaffold(
                    body: Container(
                        //change the margin
                        margin: EdgeInsets.fromLTRB(0, 0, 0, 300),
                        child: 
                        Visibility(
                            visible: _shouldShow,
    
                            // print the value of the boolean mapVisible
                            maintainSemantics: true,
                            maintainInteractivity: true,
                            maintainAnimation: true,
                            maintainState: true,
                            maintainSize: true,
                            replacement: Container(), )
    bool _shouldShow()
    {
    print(mapVisible);
    return mapVisible;
    }
    
  2. or to display the variable as text to the user you can do the following.

    Stack(
            children: [
                Scaffold(
                    body: Container(
                        //change the margin
                        margin: EdgeInsets.fromLTRB(0, 0, 0, 300),
                        child: 
                        Visibility(
                            visible: mapVisible,
    
                            // print the value of the boolean mapVisible
                            maintainSemantics: true,
                            maintainInteractivity: true,
                            maintainAnimation: true,
                            maintainState: true,
                            maintainSize: true,
                            replacement: Container(),
                            child:Text(mapVisible.toString()),//-->show it a widget
     )
    

Upvotes: 2

Related Questions