diff --git a/example/lib/main.dart b/example/lib/main.dart index 3400ddb..496019e 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -18,14 +18,30 @@ class MyApp extends StatelessWidget { } } -class MyPage extends StatelessWidget { +class MyPage extends StatefulWidget { const MyPage({Key? key}) : super(key: key); + @override + State createState() => _MyPageState(); +} + +class _MyPageState extends State { + bool _showFirst = true; + @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Resizable Widget Example'), + actions: [ + TextButton( + onPressed: () { + setState(() { + _showFirst = !_showFirst; + }); + }, + child: const Text('Change chidren')), + ], ), body: ResizableWidget( isHorizontalSeparator: false, @@ -34,7 +50,7 @@ class MyPage extends StatelessWidget { separatorSize: 4, onResized: _printResizeInfo, children: [ - Container(color: Colors.greenAccent), + if(_showFirst) Container(color: Colors.greenAccent), ResizableWidget( isHorizontalSeparator: true, separatorColor: Colors.blue, @@ -47,7 +63,7 @@ class MyPage extends StatelessWidget { Container(color: Colors.yellowAccent), Container(color: Colors.redAccent), ], - percentages: const [0.2, 0.5, 0.3], + percentages: const [0.2, 0.5, 0.3] ), Container(color: Colors.redAccent), ], diff --git a/lib/src/resizable_widget.dart b/lib/src/resizable_widget.dart index c1ecc43..e8536a8 100644 --- a/lib/src/resizable_widget.dart +++ b/lib/src/resizable_widget.dart @@ -72,15 +72,23 @@ class ResizableWidget extends StatefulWidget { } class _ResizableWidgetState extends State { - late ResizableWidgetArgsInfo _info; late ResizableWidgetController _controller; @override void initState() { super.initState(); - - _info = ResizableWidgetArgsInfo(widget); _controller = ResizableWidgetController(_info); + } + + ResizableWidgetArgsInfo get _info => ResizableWidgetArgsInfo(widget) ; + + @override + void didUpdateWidget(covariant ResizableWidget oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.children != widget.children) { + _controller = ResizableWidgetController(_info); + _controller.update(); + } } @override diff --git a/lib/src/resizable_widget_controller.dart b/lib/src/resizable_widget_controller.dart index f0f86a3..86be84e 100644 --- a/lib/src/resizable_widget_controller.dart +++ b/lib/src/resizable_widget_controller.dart @@ -28,6 +28,10 @@ class ResizableWidgetController { _model.callOnResized(); } + void update() { + eventStream.add(this); + } + void tryHideOrShow(int separatorIndex) { final result = _model.tryHideOrShow(separatorIndex);