Created
December 20, 2019 06:47
-
-
Save ggichure/2b6f804f10f228f1cd834a5ba024979f to your computer and use it in GitHub Desktop.
wave animation
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
import 'package:flutter/material.dart'; | |
final Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue), | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: OnBoarding(), | |
), | |
), | |
); | |
} | |
} | |
class MyWidget extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Text('Hello, World!', style: Theme.of(context).textTheme.display1); | |
} | |
} | |
class OnBoarding extends StatefulWidget { | |
@override | |
_OnBoardingState createState() => new _OnBoardingState(); | |
} | |
class _OnBoardingState extends State<OnBoarding> with TickerProviderStateMixin { | |
PageController _controller; | |
int currentPage = 0; | |
bool lastPage = false; | |
AnimationController animationController; | |
Animation<double> _scaleAnimation; | |
@override | |
void initState() { | |
super.initState(); | |
_controller = PageController( | |
initialPage: currentPage, | |
); | |
animationController = | |
AnimationController(duration: Duration(milliseconds: 400), vsync: this); | |
_scaleAnimation = Tween(begin: 0.6, end: 1.0).animate(animationController); | |
} | |
@override | |
void dispose() { | |
_controller.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
decoration: BoxDecoration( | |
gradient: LinearGradient( | |
colors: [ | |
Colors.black87, | |
Colors.blueGrey, | |
], | |
tileMode: TileMode.repeated, | |
begin: Alignment.topRight, | |
stops: [0.0, 1.0], | |
end: Alignment.bottomCenter), | |
), | |
child: Scaffold( | |
backgroundColor: Colors.transparent, | |
body: new Stack( | |
fit: StackFit.expand, | |
children: <Widget>[ | |
PageView.builder( | |
itemCount: pageList.length, | |
controller: _controller, | |
onPageChanged: (index) { | |
setState(() { | |
currentPage = index; | |
if (currentPage == pageList.length - 1) { | |
lastPage = true; | |
animationController.forward(); | |
} else { | |
lastPage = false; | |
animationController.reset(); | |
} | |
print(lastPage); | |
}); | |
}, | |
itemBuilder: (context, index) { | |
return AnimatedBuilder( | |
animation: _controller, | |
builder: (context, child) { | |
var page = pageList[index]; | |
var delta; | |
var y = 1.0; | |
if (_controller.position.haveDimensions) { | |
delta = _controller.page - index; | |
y = 1 - delta.abs().clamp(0.0, 1.0); | |
} | |
return Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
crossAxisAlignment: CrossAxisAlignment.start, | |
mainAxisSize: MainAxisSize.min, | |
children: <Widget>[ | |
Image.asset( | |
page.imageUrl, | |
height: 60, | |
), | |
Container( | |
margin: EdgeInsets.only(left: 12.0), | |
height: 100.0, | |
child: Stack( | |
children: <Widget>[ | |
Opacity( | |
opacity: .39, | |
child: Text("hello") | |
), | |
Padding( | |
padding: EdgeInsets.only(top: 18.0, left: 22.0), | |
child: Text("hello") | |
), | |
], | |
), | |
), | |
Padding( | |
padding: const EdgeInsets.only( | |
left: 34.0, top: 12.0, right: 8), | |
child: Transform( | |
transform: | |
Matrix4.translationValues(0, 50.0 * (1 - y), 0), | |
child: Text( | |
page.body, | |
style: TextStyle( | |
fontSize: 18.0, | |
fontFamily: "Montserrat-Medium", | |
color: Colors.white), | |
), | |
), | |
) | |
], | |
); | |
}, | |
); | |
}, | |
), | |
Positioned( | |
left: 30.0, | |
bottom: 55.0, | |
child: Container( | |
width: 160.0, | |
child: PageIndicator(currentPage, pageList.length)), | |
), | |
Positioned( | |
right: 30.0, | |
bottom: 30.0, | |
child: ScaleTransition( | |
scale: _scaleAnimation, | |
child: lastPage | |
? FloatingActionButton.extended( | |
backgroundColor: Colors.white, | |
label: Text("login", | |
style: TextStyle( | |
color: Colors.blue, | |
)), | |
icon: Icon( | |
Icons.directions_boat, | |
color: Colors.blueAccent, | |
), | |
onPressed: () { | |
Navigator.pushReplacementNamed(context, '/welcome'); | |
}, | |
) | |
: Container(), | |
), | |
), | |
], | |
), | |
), | |
); | |
} | |
} | |
var pageList = [ | |
PageModel( | |
imageUrl: "assets/c.png", | |
title: "name", | |
body: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis ", | |
titleGradient: gradients[0]), | |
PageModel( | |
imageUrl: "assets/ai.png", | |
title: "Get quick assitance", | |
body: | |
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis ", | |
titleGradient: gradients[2]), | |
PageModel( | |
imageUrl: "assets/do.png", | |
title: "Getting Started", | |
body: | |
" Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis ", | |
titleGradient: gradients[3]), | |
]; | |
List<List<Color>> gradients = [ | |
[Color(0xFF00E676), Color(0xFF736EFE)], | |
[Color(0xFF9708CC), Color(0xFF43CBFF)], | |
[Color(0xFFE2859F), Color(0xFFFCCF31)], | |
[Color(0xFF43CBFF), Color(0xFF736EFE)], | |
]; | |
class PageModel { | |
var imageUrl; | |
var title; | |
var body; | |
List<Color> titleGradient = []; | |
PageModel({this.imageUrl, this.title, this.body, this.titleGradient}); | |
} | |
class PageIndicator extends StatelessWidget { | |
final int currentIndex; | |
final int pageCount; | |
PageIndicator(this.currentIndex, this.pageCount); | |
_indicator(bool isActive) { | |
return Expanded( | |
child: Padding( | |
padding: EdgeInsets.symmetric(horizontal: 4.0), | |
child: Container( | |
height: 4.0, | |
decoration: BoxDecoration( | |
color: isActive ? Colors.white : Colors.blueGrey, | |
boxShadow: [ | |
BoxShadow( | |
color: Colors.black12, | |
offset: Offset(0.0, 2.0), | |
blurRadius: 2.0) | |
]), | |
), | |
), | |
); | |
} | |
_buildPageIndicators() { | |
List<Widget> indicatorList = []; | |
for (int i = 0; i < pageCount; i++) { | |
indicatorList | |
.add(i == currentIndex ? _indicator(true) : _indicator(false)); | |
} | |
return indicatorList; | |
} | |
@override | |
Widget build(BuildContext context) { | |
return new Row( | |
children: _buildPageIndicators(), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment