Skip to content
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

Renaming view to trailing and leading and adding rtl support. #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
8 changes: 4 additions & 4 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ class _MyHomePageState extends State<MyHomePage> {
),
body: SplitView(
initialWeight: 0.7,
view1: SplitView(
leading: SplitView(
viewMode: SplitViewMode.Horizontal,
view1: Container(
leading: Container(
child: Center(child: Text("View1")),
color: Colors.red,
),
view2: Container(
trailing: Container(
child: Center(child: Text("View2")),
color: Colors.blue,
),
onWeightChanged: (w) => print("Horizon: $w"),
),
view2: Container(
trailing: Container(
child: Center(
child: Text("View3"),
),
Expand Down
8 changes: 4 additions & 4 deletions example/lib/main_tabview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@ class _MyHomePageState extends State<MyHomePage> {
SplitView(
key: PageStorageKey(0),
initialWeight: 0.7,
view1: SplitView(
leading: SplitView(
key: PageStorageKey(1),
viewMode: SplitViewMode.Horizontal,
view1: Container(
leading: Container(
child: Center(child: Text("View1")),
color: Colors.red,
),
view2: Container(
trailing: Container(
child: Center(child: Text("View2")),
color: Colors.blue,
),
onWeightChanged: (w) => print("Horizon: $w"),
),
view2: Container(
trailing: Container(
child: ListView.separated(
itemBuilder: (context, index) {
return ListTile(
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.0.1+2"
version: "3.0.0"
stack_trace:
dependency: transitive
description:
Expand Down
37 changes: 27 additions & 10 deletions lib/split_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import 'package:flutter/widgets.dart';

/// A SplitView class.
class SplitView extends StatefulWidget {
/// The [view1] is first view.
final Widget view1;
/// The [leading] is first view.
final Widget leading;

/// The [view2] is second view.
final Widget view2;
/// The [trailing] is second view.
final Widget trailing;

/// The [viewMode] specifies how to arrange views.
final SplitViewMode viewMode;
Expand Down Expand Up @@ -50,14 +50,22 @@ class SplitView extends StatefulWidget {
/// but cannot be specified individually.
final double positionLimit;

/// If `TextDirection.ltr` then [leading] is on the left side and [trailing] is on the right side, else
/// [trailing] is on the left side and [leading] is on the right side.
///
/// If `null`, then the result of `Directionality.of(context)` is used.
///
/// If [viewMode] is Vertical, this property will be ignored.
final TextDirection? direction;

/// Called when the user moves the grip.
final ValueChanged<double?>? onWeightChanged;

/// Creates an [SplitView].
SplitView({
Key? key,
required this.view1,
required this.view2,
required this.leading,
required this.trailing,
required this.viewMode,
this.gripSize = 12.0,
this.minWidthSidebar,
Expand All @@ -68,6 +76,7 @@ class SplitView extends StatefulWidget {
this.gripColor = Colors.grey,
this.positionLimit = 20.0,
this.onWeightChanged,
this.direction,
}) : super(key: key);

@override
Expand Down Expand Up @@ -135,14 +144,14 @@ class _SplitViewState extends State<SplitView> {
left: 0,
right: 0,
bottom: bottom + halfGripSize,
child: widget.view1,
child: widget.leading,
),
Positioned(
top: top + halfGripSize,
left: 0,
right: 0,
bottom: 0,
child: widget.view2,
child: widget.trailing,
),
Positioned(
top: top - halfGripSize,
Expand Down Expand Up @@ -185,21 +194,29 @@ class _SplitViewState extends State<SplitView> {
right = constraints.maxWidth - widget.minWidthSidebar!;
}

final directionality = Directionality.of(context);

final leftView =
directionality == TextDirection.ltr ? widget.leading : widget.trailing;

final rightView =
directionality == TextDirection.ltr ? widget.trailing : widget.leading;

return Stack(
children: <Widget>[
Positioned(
top: 0,
left: 0,
right: right + halfGripSize,
bottom: 0,
child: widget.view1,
child: leftView,
),
Positioned(
top: 0,
left: left + halfGripSize,
right: 0,
bottom: 0,
child: widget.view2,
child: rightView,
),
Positioned(
top: 0,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: split_view
description: This wedget provides horizontal or vertical split view for flutter.
version: 2.0.1+2
version: 3.0.0
homepage: https://github.com/toshiaki-h/split_view

environment:
Expand Down