Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<MyPage> createState() => _MyPageState();
}

class _MyPageState extends State<MyPage> {
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,
Expand All @@ -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,
Expand All @@ -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),
],
Expand Down
14 changes: 11 additions & 3 deletions lib/src/resizable_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,23 @@ class ResizableWidget extends StatefulWidget {
}

class _ResizableWidgetState extends State<ResizableWidget> {
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
Expand Down
4 changes: 4 additions & 0 deletions lib/src/resizable_widget_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class ResizableWidgetController {
_model.callOnResized();
}

void update() {
eventStream.add(this);
}

void tryHideOrShow(int separatorIndex) {
final result = _model.tryHideOrShow(separatorIndex);

Expand Down