Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
leoafarias committed Aug 7, 2024
1 parent 8d002fa commit 839b68b
Show file tree
Hide file tree
Showing 20 changed files with 211 additions and 186 deletions.
2 changes: 2 additions & 0 deletions packages/superdeck/example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:superdeck/superdeck.dart';

import 'src/style.dart';
import 'src/widget/mix_demo.dart';

void main() async {
debugRepaintRainbowEnabled = true;
await SuperDeckApp.initialize();
runApp(
Builder(builder: (context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@

#include "generated_plugin_registrant.h"

#include <file_saver/file_saver_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
#include <window_manager/window_manager_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) file_saver_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSaverPlugin");
file_saver_plugin_register_with_registrar(file_saver_registrar);
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
file_saver
screen_retriever
url_launcher_linux
window_manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import FlutterMacOS
import Foundation

import file_saver
import path_provider_foundation
import screen_retriever
import sqflite
import url_launcher_macos
import window_manager

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FileSaverPlugin.register(with: registry.registrar(forPlugin: "FileSaverPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
Expand Down
6 changes: 6 additions & 0 deletions packages/superdeck/example/macos/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
PODS:
- file_saver (0.0.1):
- FlutterMacOS
- FlutterMacOS (1.0.0)
- path_provider_foundation (0.0.1):
- Flutter
Expand All @@ -14,6 +16,7 @@ PODS:
- FlutterMacOS

DEPENDENCIES:
- file_saver (from `Flutter/ephemeral/.symlinks/plugins/file_saver/macos`)
- FlutterMacOS (from `Flutter/ephemeral`)
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`)
- screen_retriever (from `Flutter/ephemeral/.symlinks/plugins/screen_retriever/macos`)
Expand All @@ -22,6 +25,8 @@ DEPENDENCIES:
- window_manager (from `Flutter/ephemeral/.symlinks/plugins/window_manager/macos`)

EXTERNAL SOURCES:
file_saver:
:path: Flutter/ephemeral/.symlinks/plugins/file_saver/macos
FlutterMacOS:
:path: Flutter/ephemeral
path_provider_foundation:
Expand All @@ -36,6 +41,7 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/window_manager/macos

SPEC CHECKSUMS:
file_saver: 44e6fbf666677faf097302460e214e977fdd977b
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
screen_retriever: 59634572a57080243dd1bf715e55b6c54f241a38
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

#include "generated_plugin_registrant.h"

#include <file_saver/file_saver_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
#include <window_manager/window_manager_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
FileSaverPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FileSaverPlugin"));
ScreenRetrieverPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ScreenRetrieverPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
file_saver
screen_retriever
url_launcher_windows
window_manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ class CacheImage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return AnimatedImageSpecWidget(
image: getImageProvider(
url: url,
),
image: getImageProvider(url),
spec: spec.copyWith(
fit: fit,
alignment: alignment,
Expand Down Expand Up @@ -63,9 +61,7 @@ class CacheImage extends StatelessWidget {
return (width: cacheWidth, height: cacheHeight);
}

ImageProvider getImageProvider({
required String url,
}) {
ImageProvider getImageProvider(String url) {
ImageProvider provider;

final assets = $superdeck.assets;
Expand Down
4 changes: 1 addition & 3 deletions packages/superdeck/lib/components/atoms/slide_thumbnail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ class SlideThumbnail extends HookWidget {
data: (file) {
return Image(
gaplessPlayback: true,
image: getImageProvider(
url: file.path,
),
image: getImageProvider(file.path),
);
},
loading: () {
Expand Down
8 changes: 2 additions & 6 deletions packages/superdeck/lib/components/atoms/slide_view.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';

import '../../providers/slide_provider.dart';
import '../../providers/snapshot_provider.dart';
import '../../providers/style_provider.dart';
import '../../superdeck.dart';
import 'cache_image_widget.dart';
Expand All @@ -20,7 +19,6 @@ class SlideView<T extends Slide> extends StatelessWidget {
final slide = this.slide;

final variantStyle = StyleProvider.of(context, slide.style);
final isSnapshot = SnapshotProvider.of(context);

final backgroundWidget = slide.background != null
? CacheImage(
Expand All @@ -30,10 +28,8 @@ class SlideView<T extends Slide> extends StatelessWidget {
)
: const SizedBox();

final duration = isSnapshot ? Duration.zero : null;

return TransitionWidget(
key: ValueKey(slide.transition?.copyWith(duration: duration)),
key: ValueKey(slide.transition),
transition: slide.transition,
child: SpecBuilder(
style: variantStyle,
Expand All @@ -42,7 +38,7 @@ class SlideView<T extends Slide> extends StatelessWidget {
return Builder(builder: (context) {
return AnimatedBoxSpecWidget(
spec: spec.outerContainer,
duration: duration ?? const Duration(milliseconds: 300),
duration: const Duration(milliseconds: 300),
child: Stack(
children: [
Positioned.fill(child: backgroundWidget),
Expand Down
15 changes: 1 addition & 14 deletions packages/superdeck/lib/components/molecules/slide_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:mix/mix.dart';

import '../../models/options_model.dart';
import '../../providers/snapshot_provider.dart';
import '../../styles/style_spec.dart';
import '../atoms/markdown_viewer.dart';

Expand All @@ -21,31 +20,19 @@ class SlideContent extends StatelessWidget {
Widget build(context) {
final alignment = options?.alignment ?? ContentAlignment.center;
final spec = SlideSpec.of(context);
final isSnapshot = SnapshotProvider.of(context);

Widget child = AnimatedMarkdownViewer(
content: content,
spec: spec,
duration: Durations.medium1,
);

if (!isSnapshot) {
child = SingleChildScrollView(
child: child,
);
} else {
child = Container(
clipBehavior: Clip.hardEdge,
child: child,
);
}

return AnimatedBoxSpecWidget(
duration: const Duration(milliseconds: 300),
spec: spec.contentContainer.copyWith(
alignment: alignment.toAlignment(),
),
child: child,
child: SingleChildScrollView(child: child),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SlideThumbnailList extends HookWidget {
@override
Widget build(BuildContext context) {
final navigation = useNavigation();
final currentSlide = navigation.page;
final currentPage = navigation.page;
final slides = useSlides();
final controller = useScrollVisibleController();
final visibleItems = controller.visibleItems;
Expand All @@ -28,12 +28,12 @@ class SlideThumbnailList extends HookWidget {
if (visibleItems.isEmpty) return;

final visibleItem =
visibleItems.firstWhereOrNull((e) => e.index == currentSlide);
visibleItems.firstWhereOrNull((e) => e.index == currentPage);

double alignment;

if (visibleItem == null) {
final isBeginning = visibleItems.first.index > currentSlide;
final isBeginning = visibleItems.first.index > currentPage;

alignment = isBeginning ? 0 : 0.7;
} else {
Expand All @@ -48,14 +48,14 @@ class SlideThumbnailList extends HookWidget {
}
}
controller.itemScrollController.scrollTo(
index: currentSlide,
index: currentPage,
alignment: alignment,
duration: _duration,
curve: _curve,
);

return;
}, [currentSlide, slides]);
}, [currentPage, slides]);

return Scaffold(
appBar: PreferredSize(
Expand All @@ -78,9 +78,9 @@ class SlideThumbnailList extends HookWidget {
],
onTap: (index) {
if (index == 0) {
navigation.goToPage(currentSlide - 1);
navigation.goToPage(currentPage - 1);
} else {
navigation.goToPage(currentSlide + 1);
navigation.goToPage(currentPage + 1);
}
},
),
Expand Down
2 changes: 1 addition & 1 deletion packages/superdeck/lib/components/organisms/app_shell.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class ScaffoldWithNavBar extends HookWidget {
toolbarOpacity: animation,
actions: [
IconButton(
onPressed: () {},
onPressed: () => context.go('/export'),
icon: const Icon(
Icons.picture_as_pdf,
),
Expand Down
23 changes: 12 additions & 11 deletions packages/superdeck/lib/components/superdeck_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import '../../superdeck.dart';
import '../helpers/constants.dart';
import '../helpers/theme.dart';
import '../providers/examples_provider.dart';
import '../providers/snapshot_provider.dart';
import '../providers/style_provider.dart';
import '../screens/export_screen.dart';
import '../screens/home_screen.dart';
import 'atoms/loading_indicator.dart';

final kAppKey = GlobalKey();
final _uniqueKey = UniqueKey();
var _initialized = false;

Expand Down Expand Up @@ -70,17 +70,18 @@ class SuperDeckApp extends HookWidget {
title: 'Superdeck',
routerConfig: _router,
theme: Theme.of(context),
key: kAppKey,
builder: (context, child) {
return LoadingOverlay(
isLoading: $superdeck.loading,
key: _uniqueKey,
child: Builder(
builder: (context) {
return $superdeck.completed
? child!
: const SizedBox();
},
return SnapshotProvider(
child: LoadingOverlay(
isLoading: $superdeck.loading,
key: _uniqueKey,
child: Builder(
builder: (context) {
return $superdeck.completed
? child!
: const SizedBox();
},
),
),
);
},
Expand Down
39 changes: 24 additions & 15 deletions packages/superdeck/lib/providers/snapshot_provider.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import 'package:flutter/widgets.dart';

class SnapshotProvider extends InheritedWidget {
const SnapshotProvider({
super.key,
required this.isSnapshot,
required super.child,
});
class SnapshotRef {
BuildContext? _context;

SnapshotRef._();

final bool isSnapshot;
static final SnapshotRef instance = SnapshotRef._();

void setContext(BuildContext context) {
Scrollable.ensureVisible(context);
_context = context;
}

static bool of(BuildContext context) {
return context
.dependOnInheritedWidgetOfExactType<SnapshotProvider>()
?.isSnapshot ??
false;
BuildContext get context {
assert(_context != null, '$runtimeType has not updated its context');
return _context!;
}
}

class SnapshotProvider extends StatelessWidget {
final Widget child;

const SnapshotProvider({
required this.child,
});

@override
bool updateShouldNotify(covariant SnapshotProvider oldWidget) {
return isSnapshot != oldWidget.isSnapshot;
Widget build(BuildContext context) {
SnapshotRef.instance.setContext(context);
return child;
}
}
Loading

0 comments on commit 839b68b

Please sign in to comment.