Skip to content

Commit

Permalink
added split
Browse files Browse the repository at this point in the history
  • Loading branch information
leoafarias committed Aug 6, 2024
1 parent 7d70713 commit 24c7427
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
61 changes: 43 additions & 18 deletions packages/superdeck/lib/components/molecules/split_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_hooks/flutter_hooks.dart';
import '../../helpers/hooks.dart';
import '../../helpers/utils.dart';
import '../../superdeck.dart';
import '../atoms/sized_transition.dart';
import 'slide_thumbnail_list.dart';

// ignore: non_constant_identifier_names
Expand All @@ -26,9 +27,14 @@ class SplitView extends HookWidget {
required this.child,
});

final _maxWidth = 450.0;
final _minWidth = 300.0;

@override
Widget build(BuildContext context) {
final navigation = useNavigation();
final sideSize = useState(context.isMobileLandscape ? 200.0 : _maxWidth);
final isDragging = useState(false);

final animationController = useAnimationController(
duration: Durations.medium1,
Expand All @@ -47,46 +53,65 @@ class SplitView extends HookWidget {
}
}, [navigation.sideIsOpen]);

final sideWidth = context.isMobileLandscape ? 200.0 : 400.0;
final handleUpdateSize = useCallback((DragUpdateDetails details) {
sideSize.value =
(sideSize.value + details.delta.dx).clamp(_minWidth, _maxWidth);
}, [sideSize.value]);

const sideHeight = 200.0;

final isSmall = context.isSmall || context.isMobileLandscape;

final sidePanel = SlideThumbnailList(
key: ValueKey(isSmall ? Axis.horizontal : Axis.vertical),
scrollDirection: isSmall ? Axis.horizontal : Axis.vertical,
);

return LayoutBuilder(
builder: (context, constraints) {
final animatedWidth = animation * sideWidth;
final animatedWidth = animation * sideSize.value;
final animatedHeight = animation * sideHeight;

Offset offset;
EdgeInsets padding;
if (isSmall) {
offset = Offset(0, -(animatedHeight - sideHeight));
padding = EdgeInsets.only(bottom: animatedHeight);
} else {
offset = Offset(animatedWidth - sideWidth, 0);
padding = EdgeInsets.only(left: animatedWidth);
}

Widget drawer = Transform.translate(
offset: offset,
child: SizedBox(
width: isSmall ? null : sideWidth,
height: isSmall ? sideHeight : null,
child: sidePanel,
final divider = MouseRegion(
cursor: SystemMouseCursors.resizeColumn,
child: GestureDetector(
onHorizontalDragUpdate: handleUpdateSize,
onHorizontalDragStart: (_) {
isDragging.value = true;
},
onHorizontalDragEnd: (_) {
isDragging.value = false;
},
child: Container(
color: Colors.black,
width: 8,
),
),
);

// Align at the bottom if its a small screen
if (isSmall) {
drawer = Align(
alignment: Alignment.bottomCenter,
child: drawer,
);
}
final drawer = Align(
alignment: isSmall ? Alignment.bottomCenter : Alignment.centerLeft,
child: SizedTransition(
sizeFactor: animation,
child: SizedBox(
width: isSmall ? null : sideSize.value,
height: isSmall ? sideHeight : null,
child: Row(
children: [
Expanded(child: isDragging.value ? Container() : sidePanel),
divider,
],
),
),
),
);

final current = Padding(
padding: padding,
Expand Down
4 changes: 0 additions & 4 deletions packages/superdeck/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ dependencies:
animate_do: ^3.3.4
recase: ^4.1.0
syntax_highlight: ^0.4.0

scrollable_positioned_list: ^0.3.8
pdf: ^3.10.8
localstorage: ^5.0.0
Expand All @@ -32,9 +31,6 @@ dependencies:
flutter_markdown: ^0.7.3
markdown: ^7.2.2
flutter_hooks: ^0.20.5
multi_split_view: ^3.5.0



dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 24c7427

Please sign in to comment.