Last active
October 20, 2017 04:09
-
-
Save mehmetf/c7679643991927b53471348ab1a516d4 to your computer and use it in GitHub Desktop.
With Inherited Widget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyInheritedWidget extends InheritedWidget { | |
final int accountId; | |
final int scopeId; | |
MyInheritedWidget(accountId, scopeId, child): super(child); | |
@override | |
bool updateShouldNotify(MyInheritedWidget old) => | |
accountId != old.accountId || scopeId != old.scopeId; | |
} | |
class MyPage extends StatelessWidget { | |
final int accountId; | |
final int scopeId; | |
MyPage(this.accountId, this.scopeId); | |
Widget build(BuildContext context) { | |
return new MyInheritedWidget( | |
accountId, | |
scopeId, | |
const MyWidget(), | |
); | |
} | |
} | |
class MyWidget extends StatelessWidget { | |
const MyWidget(); | |
Widget build(BuildContext context) { | |
// somewhere down the line | |
const MyOtherWidget(); | |
... | |
} | |
} | |
class MyOtherWidget extends StatelessWidget { | |
const MyOtherWidget(); | |
Widget build(BuildContext context) { | |
final myInheritedWidget = MyInheritedWidget.of(context); | |
print(myInheritedWidget.scopeId); | |
print(myInheritedWidget.accountId); | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment