-
Notifications
You must be signed in to change notification settings - Fork 26
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
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; | ||
|
@@ -77,7 +94,7 @@ class _FullScreenPageState extends State<FullScreenPage> { | |
animationDuration = Duration.zero; | ||
} | ||
|
||
setDisposeLevel() { | ||
void setDisposeLevel() { | ||
setState(() { | ||
if (widget.disposeLevel == DisposeLevel.High) | ||
disposeLimit = 300; | ||
|
@@ -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) | ||
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} else { | ||
|
@@ -130,13 +145,12 @@ class _FullScreenPageState extends State<FullScreenPage> { | |
positionYDelta = 0; | ||
}); | ||
|
||
Future.delayed(animationDuration).then((_){ | ||
Future.delayed(animationDuration).then((_) { | ||
setState(() { | ||
animationDuration = Duration.zero; | ||
}); | ||
}); | ||
} | ||
|
||
} | ||
|
||
@override | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.