Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] android – How should I adjust my widget tree in Flutter?

Posted on November 14, 2022

Solution 1 :

I totally agree with David on using some State Management like Providers, BLoC. But if you are using a single page state management, then, you can leave it for now, since, it is advanced topics. It also requires some package imports, for instance providers, flutter_bloc etc.

What you can do is to use a simple version of the State Management and that is ValueListenableBuilder class.

  • It checks for the value which you have defined for it, that is in the ValueNotifier object, and then you pass into it. It is mandatory
  • You wrap the widget, which would rebuild at the time of value changed, in this case, textVahy and bottomRect

You wrap your widget in your ValueListenableBuilder for the textVahy and bottomRect

Now, let us talk like the way you want to understand.

We take the bool value which has to be sent to the two widgets, in your tree, with the help of ValueNotifier

// taking the initial value as true
ValueNotifier<bool> _myBool = ValueNotifier<bool>(true);

Now, we wrap the two widgets, which get’s affected with the value change only.

Please note: No other widgets should be wrapped, which don’t required to be changed with the bool

            ValueListenableBuilder(
              // the value is myBool's value only
              builder: (BuildContext context, bool value, Widget child) {
                // This builder will only get called when _myBool
                // is updated.
                return Column(
                  children: <Widget>[
                    // whatever operation you wanna do based upon your value
                    // listen to value, since it has a param, it shows text with value
                    // if the value is false, else show you textVahy and bottomRect
                    if value ? textVahy : Text('$value'),
                    if value ? bottomRect : Text('$value')
                  ]
                );
              },
              // passing ValueNotifier object to listen for any changes
              valueListenable: _myBool
            )

Now when you want to change the value of the _myBool via deleteBtn, you simply do via setState()

RaisedButton(
   onPressed: (){
      // please note _myBool is the object of ValueNotifier, but _myBool.value has 
      // the right variable to store the predefined data
      setState(() => _myBool.value = false);
   },
   child: Text('Delete Me!!')
)

As soon as you hit the button, the value will be sent to ValueListenableBuilder(), and according to the bool, it will rebuild the Widgets, which are wrapped in it.

READ  [ANSWERED] Xamarin Forms Android - Picker accepting free text
Powered by Inline Related Posts

Solution 2 :

I would suggest to use some sort of state management such as BloC or Redux. In case of Redux you can wrap your “dropDown” inside StoreProvider which allows you to handle various events from various widgets. These widgets needs to be wrapped inside StoreConnector. After you dispatch action to reducer from one connector, lets say tour “deleteBtn”, you can define how the other connector would react. Take a look at example here.

Problem :

This is the widget tree of my application.Widget tree

In deleteBtn widget is a button. If I press the button it should send false value to textVahy and bottomRect. Is here any simple way to do it? Maybe it can be done with Inherited Widget but I can’t use that widget… So is here any simple way to do that?

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress