Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lass ParentProvider extends InheritedWidget {
- final String title;
- final Widget child;
- ParentProvider({this.title, this.child});
- @override
- bool updateShouldNotify(ParentProvider oldWidget) {
- return true;
- }
- static ParentProvider of(BuildContext context) =>
- context.inheritFromWidgetOfExactType(ParentProvider);
- }
- class ParentPageState extends State<ParentPage>
- with SingleTickerProviderStateMixin {
- TabController _controller;
- String myTitle = "My Parent Title";
- String updateChild2Title;
- @override
- void initState() {
- _controller = TabController(
- length: 2,
- vsync: this,
- );
- super.initState();
- }
- @override
- void dispose() {
- _controller.dispose();
- super.dispose();
- }
- updateChild2(String text) {
- setState(() {
- updateChild2Title = text;
- });
- }
- @override
- Widget build(BuildContext context) {
- return ParentProvider(
- title: updateChild2Title,
- child: Column(
- children: [
- ListTile(
- title: Text(
- myTitle,
- textAlign: TextAlign.center,
- ),
- ),
- RaisedButton(
- child: Text("Action 1"),
- onPressed: () {},
- ),
- TabBar(
- controller: _controller,
- tabs: [
- Tab(
- text: "First",
- icon: Icon(Icons.check_circle),
- ),
- Tab(
- text: "Second",
- icon: Icon(Icons.crop_square),
- )
- ],
- ),
- Expanded(
- child: TabBarView(
- controller: _controller,
- children: [
- Child1Page(
- child2Action: updateChild2,
- ),
- Child2Page(),
- ],
- ),
- )
- ],
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement