From ee7b4a70b8dc3e3f3c1ad9f216cb561a32a6610f Mon Sep 17 00:00:00 2001 From: Juan Gilsanz Polo Date: Thu, 4 May 2023 01:33:17 +0200 Subject: [PATCH] Added flex width --- lib/flutter_split_view.dart | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/flutter_split_view.dart b/lib/flutter_split_view.dart index b8d1e26..4ecaaef 100644 --- a/lib/flutter_split_view.dart +++ b/lib/flutter_split_view.dart @@ -16,6 +16,16 @@ typedef PageBuilder = Page Function({ bool? fullscreenDialog, }); +class FlexWidth { + final int mainViewFlexWidth; + final int secondaryViewFlexWidth; + + const FlexWidth({ + required this.mainViewFlexWidth, + required this.secondaryViewFlexWidth + }); +} + MaterialPage _materialPageBuilder({ required LocalKey key, required Widget child, @@ -75,6 +85,7 @@ class SplitView extends StatefulWidget { this.childWidth = _kDefaultWidth, this.breakpoint = _kDefaultBreakpoint, this.placeholder, + this.flexWidth, this.title, }) : pageBuilder = _materialPageBuilder, super(key: key); @@ -85,6 +96,7 @@ class SplitView extends StatefulWidget { this.childWidth = _kDefaultWidth, this.breakpoint = _kDefaultBreakpoint, this.placeholder, + this.flexWidth, this.title, }) : pageBuilder = _cupertinoPageBuilder, super(key: key); @@ -95,6 +107,7 @@ class SplitView extends StatefulWidget { this.childWidth = _kDefaultWidth, this.breakpoint = _kDefaultBreakpoint, this.placeholder, + this.flexWidth, this.title, required this.pageBuilder, }) : super(key: key); @@ -114,6 +127,10 @@ class SplitView extends StatefulWidget { /// Width of the child when it is in the main view. final double childWidth; + /// Width of the child when it is in the main view. If set the SizedBox will be + /// replaced with an Extended widget + final FlexWidth? flexWidth; + /// Title of the root page, used for the back button in Cupertino. final String? title; @@ -158,17 +175,27 @@ class SplitViewState extends State { return Row( children: [ - SizedBox( + if (widget.flexWidth == null) SizedBox( width: widget.childWidth, child: Navigator( pages: [_pages.first], onPopPage: _onPopPage, ), ), - const VerticalDivider( + if (widget.flexWidth != null) Expanded( + flex: widget.flexWidth!.mainViewFlexWidth, + child: Navigator( + pages: [_pages.first], + onPopPage: _onPopPage, + ), + ), + if (!(widget.hideDivider == true)) const VerticalDivider( width: 0, ), Expanded( + flex: widget.flexWidth != null + ? widget.flexWidth!.secondaryViewFlexWidth + : 1, child: ClipRect( clipBehavior: Clip.hardEdge, child: _buildSecondaryView(),