forked from hmziqrs/flutter-ui-designs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Animate on navigate provider for UI Detail Overlay
- Loading branch information
Showing
6 changed files
with
156 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
), | ||
), | ||
), | ||
); | ||
}, | ||
), | ||
); | ||
} | ||
} |