Skip to content

Commit

Permalink
Animate on navigate provider for UI Detail Overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
hmziqrs committed Dec 22, 2020
1 parent 03292ff commit 76922f5
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 64 deletions.
22 changes: 22 additions & 0 deletions lib/Providers/FadeScreen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:provider/provider.dart';
import 'package:supercharged/supercharged.dart';

class FadeScreenProvider extends ChangeNotifier {
static FadeScreenProvider state(BuildContext context, [listen = false]) =>
Provider.of<FadeScreenProvider>(context, listen: listen);

bool _fadeOff = false;
bool get fadeOff => _fadeOff;

close({VoidCallback callback, int delay = 700}) async {
if (!this._fadeOff) {
return;
}
this._fadeOff = false;
await delay.milliseconds.delay;
callback();
notifyListeners();
}
}
9 changes: 9 additions & 0 deletions lib/screens/UIDetail/Provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'package:flutter_uis/Providers/FadeScreen.dart';

class UIDetailStateProvider extends FadeScreenProvider {
static UIDetailStateProvider state(BuildContext context, [listen = false]) =>
Provider.of<UIDetailStateProvider>(context, listen: listen);
}
105 changes: 48 additions & 57 deletions lib/screens/UIDetail/UIDetail.dart
Original file line number Diff line number Diff line change
@@ -1,85 +1,76 @@
import 'package:flutter/material.dart';
import 'package:flutter_uis/Widgets/custom/CustomFlexibleSpaceBar.dart';
import 'package:flutter_uis/Widgets/Overlay/GradientFade.dart';
import 'package:provider/provider.dart';

import 'package:flutter_uis/configs/AppDimensions.dart';
import 'package:flutter_uis/configs/AppTheme.dart';

import 'package:flutter_uis/statics/data/uiList.dart';

import 'package:flutter_uis/Widgets/custom/CustomFlexibleSpaceBar.dart';
import 'package:flutter_uis/widgets/Screen/Screen.dart';

import 'widgets/UIDetailContent.dart';
import 'Dimensions.dart';
import 'Provider.dart';

class UIDetailScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
Dimensions.init(context);
final UIItem uiItem = ModalRoute.of(context).settings.arguments;

return Screen(
overlayBuilders: [
Positioned(
top: 0,
left: 0,
right: 0,
child: Container(
return ChangeNotifierProvider<UIDetailStateProvider>(
create: (_) => UIDetailStateProvider(),
child: Screen(
overlayBuilders: [
OverlayGradientFade<UIDetailStateProvider>(
height: Dimensions.cardHeight * 0.6,
decoration: BoxDecoration(
gradient: LinearGradient(
end: Alignment.bottomCenter,
begin: Alignment.topCenter,
stops: [0.15, 1.0],
colors: [
AppTheme.primary.withOpacity(0.84),
AppTheme.primary.withOpacity(0.01),
],
),
),
),
),
Positioned(
top: MediaQuery.of(context).padding.top + AppDimensions.padding,
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: AppDimensions.padding,
),
child: BackButton(
color: Colors.black,
onPressed: () => Navigator.of(context).popUntil(
ModalRoute.withName("uiList"),
Positioned(
top: MediaQuery.of(context).padding.top + AppDimensions.padding,
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: AppDimensions.padding,
),
),
),
),
],
child: CustomScrollView(
slivers: [
SliverAppBar(
stretch: true,
backgroundColor: Colors.transparent,
iconTheme: IconThemeData(opacity: 0.0),
expandedHeight: Dimensions.coverImageHeight,
flexibleSpace: CustomFlexibleSpaceBar(
collapseMode: CollapseMode.parallax,
stretchModes: [
StretchMode.zoomBackground,
],
background: Hero(
transitionOnUserGestures: true,
tag: "thumbnail-${uiItem.id}",
child: Image.asset(
uiItem.thumbnail,
fit: BoxFit.cover,
child: BackButton(
color: Colors.black,
onPressed: () => Navigator.of(context).popUntil(
ModalRoute.withName("uiList"),
),
),
),
),
SliverToBoxAdapter(
child: UIDetailContent(
uiItem: uiItem,
),
)
],
child: CustomScrollView(
slivers: [
SliverAppBar(
stretch: true,
backgroundColor: Colors.transparent,
iconTheme: IconThemeData(opacity: 0.0),
expandedHeight: Dimensions.coverImageHeight,
flexibleSpace: CustomFlexibleSpaceBar(
collapseMode: CollapseMode.parallax,
stretchModes: [
StretchMode.zoomBackground,
],
background: Hero(
transitionOnUserGestures: true,
tag: "thumbnail-${uiItem.id}",
child: Image.asset(
uiItem.thumbnail,
fit: BoxFit.cover,
),
),
),
),
SliverToBoxAdapter(
child: UIDetailContent(
uiItem: uiItem,
),
)
],
),
),
);
}
Expand Down
6 changes: 1 addition & 5 deletions lib/screens/UIDetail/widgets/UIDetailButton.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';

import 'package:flutter_uis/configs/Theme.dart' as theme;
import 'package:flutter_uis/configs/AppDimensions.dart';

import 'package:flutter_uis/widgets/BorderButton/BorderButton.dart';

Expand All @@ -28,10 +27,7 @@ class UIDetailButton extends StatelessWidget {
width: Dimensions.buttonWidth,
child: Text(
text,
style: TextStyle(
fontSize: 7.5 * AppDimensions.ratio,
fontWeight: FontWeight.w600,
),
style: TextStyle(),
),
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/widgets/BorderButton/BorderButton.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BorderButton extends StatelessWidget {
child: InkWell(
key: Key(this.testKey),
onTap: this.onPressed,
// disabledColor: Colors.transparent,
borderRadius: CommonProps.buttonRadius,
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: this.maxWidth),
child: Ink(
Expand All @@ -41,7 +41,7 @@ class BorderButton extends StatelessWidget {
),
width: this.width,
padding: EdgeInsets.symmetric(
vertical: AppDimensions.padding * 1.3,
vertical: AppDimensions.padding * 1.5,
),
child: DefaultTextStyle(
child: this.child,
Expand Down
74 changes: 74 additions & 0 deletions lib/widgets/Overlay/GradientFade.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import 'package:flutter/material.dart';
import 'package:simple_animations/simple_animations.dart';
import 'package:supercharged/supercharged.dart';
import 'package:provider/provider.dart';

import 'package:flutter_uis/configs/AppTheme.dart';

import 'package:flutter_uis/Providers/FadeScreen.dart';

class OverlayGradientFade<T extends FadeScreenProvider>
extends StatelessWidget {
const OverlayGradientFade({
Key key,
this.delay,
this.colors,
this.duration,
@required this.height,
}) : super(key: key);

final int delay;
final int duration;
final double height;
final List<Color> colors;

@override
Widget build(BuildContext context) {
final colors = this.colors ??
[
AppTheme.primary.withOpacity(0.84),
AppTheme.primary.withOpacity(0.01),
];
int delay = this.delay ?? 120;
int duration = this.duration ?? 300;

return Positioned(
top: 0,
left: 0,
right: 0,
child: Selector<T, bool>(
selector: (_, state) => state.fadeOff,
builder: (context, flag, child) {
return CustomAnimation<double>(
tween: 0.0.tweenTo(1.0),
delay: delay.milliseconds,
duration: duration.milliseconds,
control: !flag
? CustomAnimationControl.PLAY
: CustomAnimationControl.PLAY_REVERSE,
builder: (_, child, animation) {
return Transform.translate(
offset: Offset(0.0, -this.height + animation * this.height),
child: Opacity(
opacity: animation,
child: child,
),
);
},
child: Container(
height: this.height,
decoration: BoxDecoration(
gradient: LinearGradient(
end: Alignment.bottomCenter,
begin: Alignment.topCenter,
stops: [0.15, 1.0],
colors: colors,
),
),
),
);
},
),
);
}
}

0 comments on commit 76922f5

Please sign in to comment.