Skip to content

Commit

Permalink
Port all components to widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
kra-mo committed Dec 19, 2024
1 parent d3bdda0 commit 68e4988
Show file tree
Hide file tree
Showing 13 changed files with 1,193 additions and 1,086 deletions.
2 changes: 1 addition & 1 deletion lib/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ class SlyImage {
'denoise': SlyRangeAttribute('Noise Reduction', 0, 0, 0, 1),
'sharpness': SlyRangeAttribute('Sharpness', 0, 0, 0, 1),
'vignette': SlyRangeAttribute('Vignette', 0, 0, 0, 1),
'border': SlyRangeAttribute('Border', 0, 0, -1, 1),
'sepia': SlyRangeAttribute('Sepia', 0, 0, 0, 1),
'border': SlyRangeAttribute('Border', 0, 0, -1, 1),
};

/// For informational purposes only, not actually reflected in the buffer
Expand Down
97 changes: 0 additions & 97 deletions lib/io.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import 'dart:typed_data';
import 'dart:ui' as ui;

import 'package:flutter/material.dart';

import 'package:image/image.dart' as img;
import 'package:gal/gal.dart';
import 'package:file_selector/file_selector.dart';

import '/platform.dart';
import '/image.dart';
import '/widgets/dialog.dart';
import '/widgets/button.dart';
import '/widgets/spinner.dart';

Future<img.Image?> loadImgImage(Uint8List bytes) async {
final ui.Image? uiImage;
Expand Down Expand Up @@ -51,97 +45,6 @@ Future<bool> saveImage(Uint8List imageData,
return true;
}

SlyButton getSaveButton(
GlobalKey<SlyButtonState> key,
BuildContext context,
String label,
Function setImageFormat,
Function save,
) {
SlyButton? saveButton;

void setButtonChild(Widget newChild) {
if (saveButton == null) return;

saveButton.setChild(newChild);
}

saveButton = SlyButton(
key: key,
suggested: true,
child: Text(label),
onPressed: () async {
setButtonChild(
const Padding(
padding: EdgeInsets.all(6),
child: SizedBox(
width: 24,
height: 24,
child: SlySpinner(),
),
),
);

SlyImageFormat? format;

await showSlyDialog(
context,
'Choose a Quality',
<Widget>[
Padding(
padding: const EdgeInsets.only(bottom: 12),
child: SlyButton(
onPressed: () {
format = SlyImageFormat.jpeg75;
Navigator.pop(context);
},
child: const Text('For Sharing'),
),
),
Padding(
padding: const EdgeInsets.only(bottom: 12),
child: SlyButton(
onPressed: () {
format = SlyImageFormat.jpeg90;
Navigator.pop(context);
},
child: const Text('For Storing'),
),
),
Padding(
padding: const EdgeInsets.only(bottom: 16),
child: SlyButton(
onPressed: () {
format = SlyImageFormat.png;
Navigator.pop(context);
},
child: const Text('Lossless'),
),
),
SlyButton(
suggested: true,
onPressed: () {
Navigator.pop(context);
},
child: const Text('Cancel'),
),
],
);

// The user cancelled the format selection
if (format == null) {
setButtonChild(Text(label));
return;
}

setImageFormat(format!);
save();
},
);

return saveButton;
}

Future<img.Image?> _decodeImgImage(Uint8List bytes) async {
try {
return (await (img.Command()..decodeImage(bytes)).executeThread())
Expand Down
14 changes: 4 additions & 10 deletions lib/widgets/controls_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,28 @@ LinearGradient? getGradientForAttributeName(String name) {

class SlyControlsListView extends StatelessWidget {
final Map<String, SlyRangeAttribute> attributes;
final BoxConstraints constraints;
final bool wideLayout;
final HistoryManager history;
final Function updateImage;

const SlyControlsListView({
super.key,
required this.attributes,
required this.constraints,
required this.wideLayout,
required this.history,
required this.updateImage,
});

@override
build(BuildContext context) {
return ListView.builder(
physics: constraints.maxWidth > 600
? null
: const NeverScrollableScrollPhysics(),
physics: wideLayout ? null : const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: attributes.length,
itemBuilder: (context, index) {
return Padding(
padding: EdgeInsets.only(
top: index == 0 &&
constraints.maxWidth > 600 &&
!platformHasInsetTopBar
? 16
: 0,
top: index == 0 && wideLayout && !platformHasInsetTopBar ? 16 : 0,
bottom: index == attributes.length - 1 ? 28 : 0,
left: platformHasBackGesture ? 8 : 0,
right: platformHasBackGesture ? 8 : 0,
Expand Down
26 changes: 24 additions & 2 deletions lib/widgets/unique/carousel.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
import 'package:flutter/material.dart';

import '/widgets/snack_bar.dart';
import '/widgets/unique/editor.dart';
import '/juggler.dart';

class SlyCarouselData extends InheritedWidget {
final (bool, bool, SlyJuggler, GlobalKey) data;

const SlyCarouselData({
super.key,
required this.data,
required super.child,
});

static SlyCarouselData? maybeOf(BuildContext context) {
return context.dependOnInheritedWidgetOfExactType<SlyCarouselData>();
}

static SlyCarouselData of(BuildContext context) {
final SlyCarouselData? result = maybeOf(context);
return result!;
}

@override
bool updateShouldNotify(SlyCarouselData oldWidget) => data != oldWidget.data;
}

class SlyImageCarousel extends StatefulWidget {
const SlyImageCarousel({super.key});
Expand All @@ -13,7 +35,7 @@ class SlyImageCarousel extends StatefulWidget {
class _SlyImageCarouselState extends State<SlyImageCarousel> {
@override
build(BuildContext context) {
final data = CarouselData.of(context).data;
final data = SlyCarouselData.of(context).data;
final visible = data.$1;
final wideLayout = data.$2;
final juggler = data.$3;
Expand Down
78 changes: 43 additions & 35 deletions lib/widgets/unique/controls.dart
Original file line number Diff line number Diff line change
@@ -1,39 +1,47 @@
import 'package:flutter/material.dart';

Widget getControlsView(
GlobalKey key,
BoxConstraints constraints,
Widget? child,
) {
return AnimatedSize(
key: key,
duration: const Duration(milliseconds: 300),
curve: Curves.easeOutQuint,
child: AnimatedSwitcher(
switchInCurve: Curves.easeOutQuint,
// switchOutCurve: Curves.easeInSine,
transitionBuilder: (Widget newChild, Animation<double> animation) {
// Don't transition widgets animating out
// as this causes issues with the crop page
if (newChild != child) return Container();
class SlyControlsView extends StatelessWidget {
final GlobalKey globalKey;
final bool wideLayout;
final Widget? child;

return SlideTransition(
key: ValueKey<Key?>(newChild.key),
position: Tween<Offset>(
begin: (constraints.maxWidth > 600)
? const Offset(0.07, 0.0)
: const Offset(0.0, 0.07),
end: Offset.zero,
).animate(animation),
child: FadeTransition(
key: ValueKey<Key?>(newChild.key),
opacity: animation,
child: newChild,
),
);
},
duration: const Duration(milliseconds: 150),
child: child,
),
);
const SlyControlsView({
super.key,
required this.globalKey,
required this.wideLayout,
this.child,
});

@override
Widget build(BuildContext context) => AnimatedSize(
key: key,
duration: const Duration(milliseconds: 300),
curve: Curves.easeOutQuint,
child: AnimatedSwitcher(
switchInCurve: Curves.easeOutQuint,
// switchOutCurve: Curves.easeInSine,
transitionBuilder: (Widget newChild, Animation<double> animation) {
// Don't transition widgets animating out
// as this causes issues with the crop page
if (newChild != child) return Container();

return SlideTransition(
key: ValueKey<Key?>(newChild.key),
position: Tween<Offset>(
begin: (wideLayout)
? const Offset(0.07, 0.0)
: const Offset(0.0, 0.07),
end: Offset.zero,
).animate(animation),
child: FadeTransition(
key: ValueKey<Key?>(newChild.key),
opacity: animation,
child: newChild,
),
);
},
duration: const Duration(milliseconds: 150),
child: child,
),
);
}
Loading

0 comments on commit 68e4988

Please sign in to comment.