daily pastebin goal
0%
SHARE
TWEET

Untitled

a guest Mar 26th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. lass ParentProvider extends InheritedWidget {
  2.   final String title;
  3.   final Widget child;
  4.  
  5.   ParentProvider({this.title, this.child});
  6.  
  7.   @override
  8.   bool updateShouldNotify(ParentProvider oldWidget) {
  9.     return true;
  10.   }
  11.  
  12.   static ParentProvider of(BuildContext context) =>
  13.       context.inheritFromWidgetOfExactType(ParentProvider);
  14. }
  15.  
  16. class ParentPageState extends State<ParentPage>
  17.     with SingleTickerProviderStateMixin {
  18.   TabController _controller;
  19.   String myTitle = "My Parent Title";
  20.   String updateChild2Title;
  21.  
  22.   @override
  23.   void initState() {
  24.     _controller = TabController(
  25.       length: 2,
  26.       vsync: this,
  27.     );
  28.     super.initState();
  29.   }
  30.  
  31.   @override
  32.   void dispose() {
  33.     _controller.dispose();
  34.     super.dispose();
  35.   }
  36.  
  37.   updateChild2(String text) {
  38.     setState(() {
  39.       updateChild2Title = text;
  40.     });
  41.   }
  42.  
  43.   @override
  44.   Widget build(BuildContext context) {
  45.     return ParentProvider(
  46.       title: updateChild2Title,
  47.       child: Column(
  48.         children: [
  49.           ListTile(
  50.             title: Text(
  51.               myTitle,
  52.               textAlign: TextAlign.center,
  53.             ),
  54.           ),
  55.           RaisedButton(
  56.             child: Text("Action 1"),
  57.             onPressed: () {},
  58.           ),
  59.           TabBar(
  60.             controller: _controller,
  61.             tabs: [
  62.               Tab(
  63.                 text: "First",
  64.                 icon: Icon(Icons.check_circle),
  65.               ),
  66.               Tab(
  67.                 text: "Second",
  68.                 icon: Icon(Icons.crop_square),
  69.               )
  70.             ],
  71.           ),
  72.           Expanded(
  73.             child: TabBarView(
  74.               controller: _controller,
  75.               children: [
  76.                 Child1Page(
  77.                   child2Action: updateChild2,
  78.                 ),
  79.                 Child2Page(),
  80.               ],
  81.             ),
  82.           )
  83.         ],
  84.       ),
  85.     );
  86.   }
  87. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top