import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatefulWidget { @override State createState() => MyAppState(); } class MyAppState extends State { Color _color = Colors.green; @override Widget build(BuildContext context) { return InheritedColor( color: Colors.red, child: MaterialApp( home: Scaffold( body: ListView( children: [ InheritedColor( color: _color, child: Test(), ), ListTile( title: Text('Blue'), onTap: () { setState(() { _color = Colors.blue; }); }, ), ListTile( title: Text('Green'), onTap: () { setState(() { _color = Colors.green; }); }, ), ListTile( title: Text('Teal'), onTap: () { setState(() { _color = Colors.teal; }); }, ), ], ), ), ), ); } } class Test extends StatefulWidget { Test(); State createState() => _TestState(); } class _Card { _Card(this.entry, this.widget); final ProxyOverlayEntry entry; final Widget widget; } class _TestState extends State { int _count = 0; static const double dim = 100.0; Set<_Card> _cards = <_Card>{}; @override Widget build(BuildContext context) { Widget result = ListTile( title: Text('Create Entry'), onTap: () { int index = _count; _count += 1; _Card card; card = _Card( ProxyOverlayEntry(), Builder( builder: (BuildContext context) { final Size size = MediaQuery.of(context).size; return Align( alignment: Alignment.topLeft, child: Padding( padding: EdgeInsets.only( left: dim * (index % (size.width ~/ dim)), top: 200.0 + dim * ((index ~/ (size.width ~/ dim)) % ((size.height - 200.0) ~/ dim)), ), child: SizedBox( width: dim, height: dim, child: Padding( padding: EdgeInsets.all(10.0), child: RaisedButton( color: InheritedColor.of(context), child: Text('#$index'), onPressed: () { card.entry.remove(); setState(() { _cards.remove(card); }); }, ), ), ), ), ); }, ) ); setState(() { _cards.add(card); }); Overlay.of(context).insert(card.entry); }, ); for (_Card card in _cards) { result = OverlayConduit( key: ObjectKey(card), overlayEntry: card.entry, overlayChild: card.widget, child: result, ); } return result; } } class InheritedColor extends InheritedWidget { InheritedColor({ this.color, Widget child }) : super(child: child); final Color color; @override bool updateShouldNotify(InheritedColor old) => old.color != color; static Color of(BuildContext context) { return (context.inheritFromWidgetOfExactType(InheritedColor) as InheritedColor).color; } }