ﻲﻟﺎﺘﻟا InheritedWidget in/mohammed-salah-tighezza mohammed salah the InheritedWidget


Download 156.17 Kb.
Pdf ko'rish
Sana17.06.2023
Hajmi156.17 Kb.
#1523023
Bog'liq
flutter inhereted widget



ﻲﻟﺎﺘﻟا
InheritedWidget
in/mohammed-salah-tighezza
MOHAMMED SALAH
The InheritedWidget is a Flutter widget
that allows data to be passed down the
widget tree to its descendants. The
data is stored within the
InheritedWidget and can be accessed
by descendant widgets by calling
InheritedWidget.of(context). This is
useful for sharing data that needs to be
accessible by multiple widgets, such as
.theme information or user preferences


ﻲﻟﺎﺘﻟا
Here's how to use it:
in/mohammed-salah-tighezza
MOHAMMED SALAH
Create a class that extends InheritedWidget.
Store the data you want to share in the class as
fields.
Override the updateShouldNotify method to
determine if a rebuild is needed.
Use the InheritedWidget as the root of a widget
tree, using the build method to pass data down
to its descendants.
Access the shared data by calling
InheritedWidget.of(context) in the build
method of descendant widgets.
1.
2.
3.
4.
5.


ﻲﻟﺎﺘﻟا
Creat class DataContainer extends from
InheritedWidget :
in/mohammed-salah-tighezza
MOHAMMED SALAH


ﻲﻟﺎﺘﻟا
The updateShouldNotify 
method is part of the
InheritedWidget class and is used to determine if
a rebuild of the widget tree is necessary when
the data stored in the widget changes.
The method takes in the previous DataContainer
widget as an argument and returns a boolean
value indicating whether the widget tree should
be rebuilt. In this example, it returns true if the
count field of the new widget is different from the
count field of the old widget, and false otherwise.
When updateShouldNotify returns true, Flutter
will call the build method of all the widgets that
depend on this DataContainer widget, allowing
them to access the updated data.
in/mohammed-salah-tighezza
MOHAMMED SALAH


ﻲﻟﺎﺘﻟا
The 
CounterDisplay 
widget is used to display the current
value of the count field stored in the DataContainer
widget. It does this by using the
DataContainer.of(context) method to access the shared
data, and then using the value of the count field to build a
Text widget with the current count.
in/mohammed-salah-tighezza
MOHAMMED SALAH


ﻲﻟﺎﺘﻟا
The 
CounterIncrementor 
widget is used to increment the
value of the count field stored in the DataContainer widget. It
does this by using the DataContainer.of(context) method to
access the shared data and then incrementing the value of
the count field whenever the button is pressed.
in/mohammed-salah-tighezza
MOHAMMED SALAH


ﻲﻟﺎﺘﻟا
The 
CounterApp 
widget is the root widget of the app. It
contains the logic to build the app and render the UI.
in/mohammed-salah-tighezza
MOHAMMED SALAH


ﻲﻟﺎﺘﻟا
and in the end we are gonna call CounterApp() in the main method 
in/mohammed-salah-tighezza
MOHAMMED SALAH

Download 156.17 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling