Skip to content

Added flex width #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
29 changes: 28 additions & 1 deletion lib/flutter_split_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> _materialPageBuilder({
required LocalKey key,
required Widget child,
Expand Down Expand Up @@ -75,6 +85,7 @@ class SplitView extends StatefulWidget {
this.childWidth = _kDefaultWidth,
this.breakpoint = _kDefaultBreakpoint,
this.placeholder,
this.flexWidth,
this.title,
this.hideDivider
}) : pageBuilder = _materialPageBuilder,
Expand All @@ -86,6 +97,7 @@ class SplitView extends StatefulWidget {
this.childWidth = _kDefaultWidth,
this.breakpoint = _kDefaultBreakpoint,
this.placeholder,
this.flexWidth,
this.title,
this.hideDivider
}) : pageBuilder = _cupertinoPageBuilder,
Expand All @@ -97,6 +109,7 @@ class SplitView extends StatefulWidget {
this.childWidth = _kDefaultWidth,
this.breakpoint = _kDefaultBreakpoint,
this.placeholder,
this.flexWidth,
this.title,
required this.pageBuilder,
this.hideDivider
Expand All @@ -117,6 +130,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;

Expand Down Expand Up @@ -164,17 +181,27 @@ class SplitViewState extends State<SplitView> {

return Row(
children: <Widget>[
SizedBox(
if (widget.flexWidth == null) SizedBox(
width: widget.childWidth,
child: Navigator(
pages: [_pages.first],
onPopPage: _onPopPage,
),
),
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(),
Expand Down