
模拟器动画略有卡顿。
import 'package:flutter/material.dart';
import 'package:flutterappfood/pages/HomePage.dart';
import 'package:flutterappfood/pages/StarterPage.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: ThemeData(
fontFamily:'Roboto' ,
primarySwatch: Colors.blue,
),
home: Scaffold(
body: StarterPage(),
),
);
}
}
import 'package:flutter/material.dart';
import 'package:flutterappfood/animations/FadeAnimation.dart';
import 'package:flutterappfood/pages/HomePage.dart';
import 'package:page_transition/page_transition.dart';
class StarterPage extends StatefulWidget {
StarterPage({Key key}) : super(key: key);
@override
_StarterPageState createState() => _StarterPageState();
}
class _StarterPageState extends State<StarterPage>
with SingleTickerProviderStateMixin {
AnimationController _animationController;
Animation<double> _animation;
var _textVisible = true;
@override
void initState() {
_animationController =
AnimationController(vsync: this, duration: Duration(milliseconds: 500));
_animation =
Tween<double>(begin: 1.0, end: 25.0).animate(_animationController);
super.initState();
}
void _onTap() {
setState(() {
_textVisible = false;
});
_animationController.forward().then((f) => {
Navigator.push(context,
PageTransition(child: HomePage(), type: PageTransitionType.fade))
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage('assets/images/starter-image.jpg'))),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(begin: Alignment.bottomCenter, colors: [
Colors.black.withOpacity(.9),
Colors.black.withOpacity(.8),
Colors.black.withOpacity(.2),
]),
),
child: Padding(
padding: EdgeInsets.all(20),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
FadeAnimation(
delay: .5,
child: Text(
"Taking Order For Faster Deliver",
style: TextStyle(
fontSize: 50,
color: Colors.white,
fontWeight: FontWeight.bold),
),
),
SizedBox(
height: 20,
),
FadeAnimation(
delay: 1,
child: Text(
"See resturants nearby by \nadding location",
style: TextStyle(
color: Colors.white, height: 1.4, fontSize: 18),
)),
SizedBox(
height: 20,
),
FadeAnimation(
delay: 1.2,
child: ScaleTransition(
scale: _animation,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.yellow, Colors.orange]),
borderRadius: BorderRadius.circular(10)),
width: double.infinity,
child: AnimatedOpacity(
opacity: _textVisible ? 1.0 : 0.0,
duration: Duration(milliseconds: 50),
child: MaterialButton(
onPressed: () => _onTap(),
child: Text(
"Start",
style: TextStyle(color: Colors.white),
),
),
),
))),
SizedBox(
height: 30,
),
FadeAnimation(
delay: 1.4,
child: Align(
child: Text(
'Now Deliver To Your Door 24/7',
style: TextStyle(color: Colors.white70, fontSize: 15),
),
))
],
),
),
),
),
);
}
}
import 'package:flutter/material.dart';
import 'package:flutterappfood/animations/FadeAnimation.dart';
class HomePage extends StatefulWidget {
HomePage({Key key}) : super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey.shade100,
appBar: AppBar(
backgroundColor: Colors.grey.shade100,
leading: Icon(null),
elevation: 0,
brightness: Brightness.light,
actions: <Widget>[
IconButton(
onPressed: () {},
color: Colors.grey.shade800,
icon: Icon(Icons.shopping_basket),
)
],
),
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
FadeAnimation(
delay: 1,
child: Text(
'Food Delivery',
style: TextStyle(
color: Colors.grey[80],
fontWeight: FontWeight.bold,
fontSize: 30),
),
),
SizedBox(
height: 20,
),
Container(
height: 50,
child: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
FadeAnimation(
delay: 1,
child: makeCategory(isActive: true, title: 'Pizza'),
),
FadeAnimation(
delay: 1.2,
child:
makeCategory(isActive: false, title: 'Burgers'),
),
FadeAnimation(
delay: 1.3,
child:
makeCategory(isActive: false, title: 'Kebab'),
),
FadeAnimation(
delay: 1.4,
child:
makeCategory(isActive: false, title: 'Desert'),
),
FadeAnimation(
delay: 1.5,
child:
makeCategory(isActive: false, title: 'Salad'),
),
],
),
),
SizedBox(
height: 10,
)
],
),
),
FadeAnimation(
delay: 1,
child: Padding(
padding: EdgeInsets.all(20),
child: Text(
'Free Delivery',
style: TextStyle(
color: Colors.grey[700],
fontSize: 20,
fontWeight: FontWeight.bold),
),
)),
Expanded(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
FadeAnimation(
delay: 1.5,
child: makeItem(image: 'assets/images/one.jpg'),
),
FadeAnimation(
delay: 1.6,
child: makeItem(image: 'assets/images/two.jpg'),
),
FadeAnimation(
delay: 1.7,
child: makeItem(image: 'assets/images/three.jpg'),
),
],
),
),
)
],
),
));
}
}
Widget makeCategory({isActive, title}) {
return AspectRatio(
aspectRatio: isActive ? 3 : 2.0 / 1,
child: Container(
margin: EdgeInsets.only(right: 15),
decoration: BoxDecoration(
color: isActive ? Colors.yellow[700] : Colors.white,
borderRadius: BorderRadius.circular(50),
),
child: Align(
child: Text(
title,
style: TextStyle(
color: isActive ? Colors.white : Colors.grey[500],
fontSize: 18,
fontWeight: isActive ? FontWeight.bold : FontWeight.w100),
),
),
));
}
Widget makeItem({image}) {
return AspectRatio(
aspectRatio: 1 / 1.5,
child: GestureDetector(
child: Container(
margin: EdgeInsets.only(right: 20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
image: DecorationImage(
image: AssetImage(image),
fit: BoxFit.cover,
)),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
gradient: LinearGradient(begin: Alignment.bottomCenter, stops: [
.2,
.9
], colors: [
Colors.black.withOpacity(.9),
Colors.black.withOpacity(.3),
])),
child: Padding(
padding: EdgeInsets.all(20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Align(
alignment: Alignment.topRight,
child: Icon(
Icons.favorite,
color: Colors.white,
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"\$ 15.00",
style: TextStyle(
color: Colors.white,
fontSize: 40,
fontWeight: FontWeight.bold),
),
SizedBox(
height: 10,
),
Text(
"Vegetarian Pizza",
style: TextStyle(color: Colors.white, fontSize: 20),
)
],
)
],
),
),
),
),
),
);
}
name: flutterappfood
description: A new Flutter application.
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
simple_animations: ^1.3.9
page_transition: ^1.1.5
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:
- assets/images/
fonts:
- family: Roboto
fonts:
- asset: assets/fonts/Roboto-Bold.ttf
- asset: assets/fonts/Roboto-Light.ttf
- asset: assets/fonts/Roboto-Regular.ttf
网友评论