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

Implemented various improvements #2

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
3 changes: 1 addition & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import 'package:flutter/material.dart';
import 'package:full_screen_image/full_screen_image.dart';


void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
String lorem =
final String lorem =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla consequat mauris in ex facilisis feugiat. Donec vestibulum elit id feugiat ultrices. Aenean ultrices rhoncus velit at viverra. In pharetra, nibh egestas mattis pretium, ipsum sapien rhoncus leo, consequat commodo erat elit ac nisi. Nulla elit justo, pretium sit amet quam eu, congue aliquam tellus. Integer eget luctus ante, pulvinar efficitur metus. Nam ut sodales urna, id placerat dolor. Nunc in feugiat turpis. In dictum leo dapibus justo semper, at facilisis lacus commodo. Nam porttitor et eros ut pharetra. Nullam ut quam eu felis ullamcorper elementum at et arcu. Phasellus nec massa risus. Praesent viverra pharetra ante. Etiam elementum ultricies nisl ultricies tempus. Pellentesque consequat feugiat ipsum, at venenatis nulla tincidunt eget. Nunc lobortis pretium nulla. Aenean condimentum felis a dignissim ultricies. Maecenas bibendum scelerisque rhoncus. Vestibulum sed ante sit amet elit luctus molestie. Curabitur consequat dolor magna, vitae pulvinar metus ultrices at. Maecenas sit amet pretium nibh. Ut vulputate nisl lorem, sed fringilla elit facilisis ut. Ut ac tincidunt tortor. Pellentesque leo ex, efficitur eget neque non, maximus molestie quam. Duis sagittis at ipsum non sagittis. Sed convallis, lorem a sagittis eleifend, nisl turpis efficitur massa, nec ultrices diam purus non leo. Pellentesque tempor in sem quis lacinia. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Mauris lacinia, elit a maximus fermentum, lacus felis venenatis elit, ut fringilla sem justo quis est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nam ornare tincidunt lectus sit amet euismod. Nunc sodales velit quis leo luctus ultrices. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer molestie, felis eget ornare consequat, elit dolor ullamcorper leo, et feugiat felis eros sit amet nisl. Vestibulum et egestas felis, ac sodales ante. In in volutpat justo.Vestibulum volutpat dapibus felis. Proin in dolor purus. Mauris varius vitae nulla quis sodales. Duis sapien sapien, maximus sed lacinia quis, elementum in arcu. Etiam hendrerit convallis nulla efficitur consequat. Suspendisse mattis lacinia erat, eget congue ligula molestie at. Aenean blandit nisl eget arcu sodales pellentesque. Aenean ullamcorper neque vel eleifend dignissim. Phasellus nec feugiat mi. Ut dictum diam quis nulla suscipit, eu venenatis eros faucibus.Aenean aliquet purus nec orci facilisis congue. Aliquam gravida sem non ipsum venenatis, sit amet volutpat mi placerat. In vitae risus quis sem ullamcorper vestibulum. Maecenas bibendum tellus at libero congue consequat. Nulla quam elit, placerat at egestas vel, ultrices in erat. Donec non rhoncus nulla, nec consectetur magna. Aenean luctus dolor mi, nec sodales ipsum hendrerit et. Aliquam volutpat risus in pulvinar fringilla. Etiam tellus erat, malesuada ac pharetra non, egestas non sapien. Curabitur malesuada aliquet rhoncus. Aenean semper, magna nec malesuada feugiat, lorem odio vestibulum mauris, sed interdum nisl tortor sit amet arcu. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Phasellus tempor metus mi, quis volutpat elit auctor non. Quisque tellus diam, aliquam eget blandit quis, sagittis sit amet erat. Mauris lobortis nunc a neque consequat efficitur.In hac habitasse platea dictumst. Aenean varius risus eu pulvinar interdum. Pellentesque imperdiet tortor urna, pharetra lacinia eros luctus ac. Nunc vitae luctus eros. Mauris eu vestibulum metus, iaculis rhoncus mi. Nulla imperdiet finibus sagittis. Proin vel pellentesque urna. Interdum et malesuada fames ac ante ipsum primis in faucibus. In dignissim ultricies massa sed pharetra. Nunc libero massa, scelerisque ac orci vel, finibus aliquet urna. Maecenas eget lorem at dui sodales feugiat eget et nibh. Phasellus feugiat, lectus in facilisis dapibus, odio nisi maximus quam, eu facilisis turpis lorem vel diam. Morbi auctor consequat leo, sed venenatis lacus. Nunc vel nisl diam.Vivamus augue odio, varius nec lacinia in, placerat sed arcu. Integer sollicitudin nisl ut tempor malesuada. Suspendisse nunc dui, molestie pulvinar pretium vitae, accumsan a nulla. Aliquam erat volutpat. Ut dictum malesuada vestibulum. Quisque commodo ex id diam maximus, fermentum egestas neque euismod. Donec molestie augue elit, eget vulputate justo pellentesque ut. Mauris sed pulvinar erat, eu molestie dolor. Integer nec eleifend lacus. Suspendisse lobortis, eros id mattis sagittis, tortor libero feugiat est, et tristique arcu tortor lacinia quam. Etiam posuere elit nibh, non maximus turpis cursus sed. Proin rhoncus purus ex, vitae interdum purus aliquam porttitor. Cras dignissim et enim nec convallis.Duis non metus in magna elementum elementum. Proin vitae commodo dui. Pellentesque ultricies, lectus nec suscipit ornare, enim neque pellentesque sapien, quis varius mauris magna pretium odio. Sed quis purus eu lorem dignissim mollis. Nullam mattis quam nunc, quis accumsan turpis scelerisque ac. Proin pharetra tempor lorem, et pretium diam lacinia sed. Sed in turpis tristique, imperdiet elit in, rutrum ante. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vivamus augue diam, euismod quis placerat imperdiet, hendrerit vitae tortor. In non sapien vitae ante fermentum consectetur.Integer elementum ligula erat, id sodales dui convallis vel. Pellentesque elementum quam tellus, vitae sodales metus ultrices ac. Aenean at nibh lectus. Pellentesque tempus imperdiet sollicitudin. Fusce porttitor mauris sed euismod aliquet. Aenean sed nibh tortor. Etiam pretium mauris sed ultricies tincidunt. Mauris imperdiet sem orci, et euismod ligula laoreet non. Suspendisse ut ex leo. Sed pellentesque libero non facilisis porta.";

Widget fullScreenImage() => FullScreenWidget(
Expand Down
80 changes: 47 additions & 33 deletions lib/full_screen_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,67 @@ library full_screen_image;
import 'package:flutter/material.dart';

class FullScreenWidget extends StatelessWidget {
FullScreenWidget(
{@required this.child,
this.backgroundColor = Colors.black,
this.backgroundIsTransparent = true,
this.disposeLevel});

final Widget Function(
BuildContext context, bool isPreview, Widget staticChild)
builderWithChild;
final Widget child;

final Widget Function(BuildContext context, bool isPreview) builder;

final Color backgroundColor;
final bool backgroundIsTransparent;
final DisposeLevel disposeLevel;

const FullScreenWidget({
Key key,
this.builderWithChild,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not do either/or? So either provide a child or a builder, this is more in line with the usage of builders in the rest of Flutter.

Then assert that only one is provided, before the super

: assert(child = null | builder = null), super(key: key)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can split the constructor into 3 factories, one with builder, another with child and another with both child and builder
what do you think about that ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think that makes it much better. Point was that it'd be weird to have multiple builders that can be defined at the same time, without any errors, though it will actually choose one.

this.builder,
this.backgroundColor,
this.backgroundIsTransparent = true,
this.disposeLevel,
this.child,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
Navigator.push(
context,
PageRouteBuilder(
opaque: false,
barrierColor: backgroundIsTransparent
? Colors.white.withOpacity(0)
: backgroundColor,
pageBuilder: (BuildContext context, _, __) {
return FullScreenPage(
child: child,
backgroundColor: backgroundColor,
backgroundIsTransparent: backgroundIsTransparent,
disposeLevel: disposeLevel,
);
}));
context,
PageRouteBuilder(
opaque: false,
barrierColor: backgroundIsTransparent
? Colors.white.withOpacity(0)
: backgroundColor,
pageBuilder: (BuildContext context, _, __) {
return FullScreenPage(
child: child == null
? builder(context, false)
: builderWithChild(context, false, child),
backgroundColor: backgroundColor,
backgroundIsTransparent: backgroundIsTransparent,
disposeLevel: disposeLevel,
);
},
),
);
},
child: child,
child: child == null
? builder(context, true)
: builderWithChild(context, true, child),
);
}
}

enum DisposeLevel { High, Medium, Low }

class FullScreenPage extends StatefulWidget {
FullScreenPage(
{@required this.child,
this.backgroundColor = Colors.black,
this.backgroundIsTransparent = true,
this.disposeLevel = DisposeLevel.Medium});
FullScreenPage({
this.child,
this.backgroundColor = Colors.black,
this.backgroundIsTransparent = true,
this.disposeLevel = DisposeLevel.Medium,
});

final Widget child;
final Color backgroundColor;
Expand Down Expand Up @@ -77,7 +94,7 @@ class _FullScreenPageState extends State<FullScreenPage> {
animationDuration = Duration.zero;
}

setDisposeLevel() {
void setDisposeLevel() {
setState(() {
if (widget.disposeLevel == DisposeLevel.High)
disposeLimit = 300;
Expand All @@ -102,12 +119,10 @@ class _FullScreenPageState extends State<FullScreenPage> {
});
}

setOpacity() {
void setOpacity() {
double tmp = positionYDelta < 0
? 1 - ((positionYDelta / 1000) * -1)
: 1 - (positionYDelta / 1000);
print(tmp);

if (tmp > 1)
opacity = 1;
else if (tmp < 0)
Expand All @@ -120,7 +135,7 @@ class _FullScreenPageState extends State<FullScreenPage> {
}
}

_endVerticalDrag(DragEndDetails details) {
void _endVerticalDrag(DragEndDetails details) {
if (positionYDelta > disposeLimit || positionYDelta < -disposeLimit) {
Navigator.of(context).pop();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if we were to be able to access this context through the builder somehow. Especially for the non-preview version.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the non-preview version is in a different route, thus a different context.
What exactly do you want to access with the preview context?

} else {
Expand All @@ -130,13 +145,12 @@ class _FullScreenPageState extends State<FullScreenPage> {
positionYDelta = 0;
});

Future.delayed(animationDuration).then((_){
Future.delayed(animationDuration).then((_) {
setState(() {
animationDuration = Duration.zero;
});
});
}

}

@override
Expand Down