Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
leoafarias committed Aug 6, 2024
1 parent c702c1a commit 7d70713
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 151 deletions.
37 changes: 37 additions & 0 deletions packages/superdeck/lib/components/atoms/sized_transition.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'dart:math' as math;

import 'package:flutter/widgets.dart';

class SizedTransition extends StatelessWidget {
const SizedTransition({
super.key,
required this.sizeFactor,
this.child,
this.direction = Axis.horizontal,
});

final double sizeFactor;
final Axis direction;

final Widget? child;

@override
Widget build(BuildContext context) {
AlignmentDirectional alignment;
if (direction == Axis.horizontal) {
alignment = const AlignmentDirectional(0.0, -1.0);
} else {
alignment = const AlignmentDirectional(-1.0, 0.0);
}
return ClipRect(
child: Align(
alignment: alignment,
heightFactor:
direction == Axis.vertical ? math.max(sizeFactor, 0.0) : 1.0,
widthFactor:
direction == Axis.horizontal ? math.max(sizeFactor, 0.0) : 1.0,
child: child,
),
);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import 'package:flutter/material.dart';

import '../../helpers/utils.dart';
import '../../superdeck.dart';
import '../atoms/slide_view.dart';
import 'scaled_app.dart';
import 'split_view.dart';

class SlidePreview<T extends Slide> extends StatelessWidget {
const SlidePreview(
Expand All @@ -16,12 +14,8 @@ class SlidePreview<T extends Slide> extends StatelessWidget {

@override
Widget build(BuildContext context) {
final panelSize = SplitViewProvider.panelSizeOf(context);
var paddingSize = panelSize / (context.isSmall ? 5.0 : 20.0);

return Center(
child: Container(
margin: EdgeInsets.all(paddingSize),
decoration: BoxDecoration(
color: const Color.fromARGB(144, 0, 0, 0),
boxShadow: [
Expand Down
80 changes: 5 additions & 75 deletions packages/superdeck/lib/components/molecules/split_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,15 @@ class SplitView extends HookWidget {
final animatedHeight = animation * sideHeight;

Offset offset;
if (isSmall) {
offset = Offset(0, -(animatedHeight - sideHeight));
} else {
offset = Offset(animatedWidth - sideWidth, 0);
}

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);
}

final panelSize = isSmall ? animatedHeight : animatedWidth;

Widget drawer = Transform.translate(
offset: offset,
child: SizedBox(
Expand All @@ -95,12 +88,10 @@ class SplitView extends HookWidget {
);
}

final current = SplitViewProvider(
panelSize: panelSize,
isOpen: navigation.sideIsOpen,
size: constraints.biggest,
final current = Padding(
padding: padding,
child: Padding(
padding: padding,
padding: EdgeInsets.all(20 * animation),
child: child,
),
);
Expand All @@ -112,64 +103,3 @@ class SplitView extends HookWidget {
);
}
}

enum SplitViewProviderAspect {
panelSize,
isOpen,
size,
}

class SplitViewProvider extends InheritedModel<SplitViewProviderAspect> {
final double panelSize;
final bool isOpen;
final Size size;

const SplitViewProvider({
super.key,
required this.panelSize,
required this.isOpen,
required this.size,
required super.child,
});

@override
bool updateShouldNotify(covariant SplitViewProvider oldWidget) {
return panelSize != oldWidget.panelSize ||
isOpen != oldWidget.isOpen ||
size != oldWidget.size;
}

@override
bool updateShouldNotifyDependent(covariant SplitViewProvider oldWidget,
Set<SplitViewProviderAspect> dependencies) {
if (dependencies.contains(SplitViewProviderAspect.panelSize) &&
panelSize != oldWidget.panelSize) {
return true;
}
if (dependencies.contains(SplitViewProviderAspect.isOpen) &&
isOpen != oldWidget.isOpen) {
return true;
}
if (dependencies.contains(SplitViewProviderAspect.size) &&
size != oldWidget.size) {
return true;
}
return false;
}

static SplitViewProvider of(BuildContext context) {
return context.dependOnInheritedWidgetOfExactType<SplitViewProvider>()!;
}

static Size sizeOf(BuildContext context) {
return SplitViewProvider.of(context).size;
}

static double panelSizeOf(BuildContext context) {
return SplitViewProvider.of(context).panelSize;
}

static bool isOpenOf(BuildContext context) {
return SplitViewProvider.of(context).isOpen;
}
}
69 changes: 1 addition & 68 deletions packages/superdeck/lib/components/organisms/app_shell.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import 'dart:math' as math;

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:go_router/go_router.dart';

import '../../helpers/constants.dart';
import '../../helpers/hooks.dart';
import '../../helpers/utils.dart';
import '../../superdeck.dart';
import 'drawer.dart';

final scaffoldKey = GlobalKey<ScaffoldState>();

Expand Down Expand Up @@ -98,27 +94,6 @@ class ScaffoldWithNavBar extends HookWidget {
): handlePrevious,
};

void onTap(int index) {
_onTap(context, index);
}

final menuItems = kCanRunProcess ? SideMenu.devMenu : SideMenu.prodMenu;

final navigationRail = NavigationRail(
extended: false,
selectedIndex: navigationShell.currentIndex,
onDestinationSelected: onTap,
minWidth: 80,
leading: const SizedBox(height: 20),
labelType: NavigationRailLabelType.none,
destinations: menuItems
.map((e) => NavigationRailDestination(
icon: Icon(e.icon, size: 20),
label: Text(e.label),
))
.toList(),
);

return CallbackShortcuts(
bindings: bindings,
child: Scaffold(
Expand Down Expand Up @@ -158,49 +133,7 @@ class ScaffoldWithNavBar extends HookWidget {
child: const Icon(Icons.menu),
),
),
body: Row(
children: [
_SizeTransition(
sizeFactor: animation,
direction: Axis.horizontal,
child: navigationRail,
),
Expanded(child: navigationShell),
],
),
),
);
}
}

class _SizeTransition extends StatelessWidget {
const _SizeTransition({
required this.sizeFactor,
this.child,
this.direction = Axis.horizontal,
});

final double sizeFactor;
final Axis direction;

final Widget? child;

@override
Widget build(BuildContext context) {
AlignmentDirectional alignment;
if (direction == Axis.horizontal) {
alignment = const AlignmentDirectional(0.0, -1.0);
} else {
alignment = const AlignmentDirectional(-1.0, 0.0);
}
return ClipRect(
child: Align(
alignment: alignment,
heightFactor:
direction == Axis.vertical ? math.max(sizeFactor, 0.0) : 1.0,
widthFactor:
direction == Axis.horizontal ? math.max(sizeFactor, 0.0) : 1.0,
child: child,
body: navigationShell,
),
);
}
Expand Down
3 changes: 1 addition & 2 deletions packages/superdeck/lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class HomeScreen extends HookWidget {
}, [page]);

return SplitView(
child: Container(
alignment: Alignment.center,
child: Center(
child: PageView.builder(
controller: pageController,
itemCount: slides.length,
Expand Down
1 change: 1 addition & 0 deletions packages/superdeck/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies:
flutter_markdown: ^0.7.3
markdown: ^7.2.2
flutter_hooks: ^0.20.5
multi_split_view: ^3.5.0



Expand Down

0 comments on commit 7d70713

Please sign in to comment.