Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.94 KB | None | 0 0
  1. import 'dart:async';
  2.  
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter/widgets.dart';
  6. import 'package:google_restaurants/models/restaurant.dart';
  7.  
  8. class RestaurantListItem extends StatefulWidget {
  9.   final Restaurant restaurant;
  10.   final int index;
  11.  
  12.   RestaurantListItem({this.restaurant, this.index});
  13.  
  14.   @override
  15.   _RestaurantListItemState createState() => _RestaurantListItemState();
  16. }
  17.  
  18. class _RestaurantListItemState extends State<RestaurantListItem>
  19.     with TickerProviderStateMixin {
  20.   Animation<double> _opacity;
  21.   Animation<Offset> _translation;
  22.   AnimationController _animationController;
  23.   Timer _timeout;
  24.  
  25.   void _onPressItem() {
  26.     debugPrint("press item")
  27.   }
  28.  
  29.   @override
  30.   void initState() {
  31.     // TODO: implement initState
  32.     super.initState();
  33.     _animationController =
  34.         AnimationController(vsync: this, duration: Duration(milliseconds: 500));
  35.     final CurvedAnimation curvedAnimation = CurvedAnimation(
  36.       curve: Curves.easeInOut,
  37.       parent: _animationController,
  38.     );
  39.     _opacity = Tween(begin: 0.0, end: 1.0).animate(curvedAnimation);
  40.     _translation = Tween(begin: Offset(1.0, 0.0), end: Offset.zero)
  41.         .animate(curvedAnimation);
  42.     _timeout = Timer(Duration(milliseconds: 70 * widget.index), () {
  43.       _animationController.forward();
  44.     });
  45.   }
  46.  
  47.   @override
  48.   void dispose() {
  49.     // TODO: implement dispose
  50.     _animationController.dispose();
  51.     _timeout.cancel();
  52.     super.dispose();
  53.   }
  54.  
  55.   @override
  56.   Widget build(BuildContext context) {
  57.     return SlideTransition(
  58.       position: _translation,
  59.       child: FadeTransition(
  60.         opacity: _opacity,
  61.         child: GestureDetector(
  62.           onTap: _onPressItem,
  63.           child: Container(
  64.             margin: EdgeInsets.symmetric(vertical: 10),
  65.             padding: EdgeInsets.all(10),
  66.             decoration: BoxDecoration(
  67.                 color: Colors.white,
  68.                 borderRadius: BorderRadius.circular(8),
  69.                 boxShadow: [
  70.                   BoxShadow(color: Color(0xFFc9d6df), offset: Offset(1, 0)),
  71.                   BoxShadow(
  72.                       color: Color(0xFFc9d6df),
  73.                       offset: Offset(0, 3),
  74.                       blurRadius: 3),
  75.                   BoxShadow(color: Color(0xFFc9d6df), offset: Offset(-1, 0)),
  76.                 ]),
  77.             child: Column(
  78.               crossAxisAlignment: CrossAxisAlignment.start,
  79.               children: <Widget>[
  80.                 Text(
  81.                   widget.restaurant.name,
  82.                   style: TextStyle(fontWeight: FontWeight.bold),
  83.                 ),
  84.                 Container(
  85.                   margin: const EdgeInsets.only(top: 4),
  86.                   child: Text(widget.restaurant.address,
  87.                       style: TextStyle(fontSize: 15)),
  88.                 )
  89.               ],
  90.             ),
  91.           ),
  92.         ),
  93.       ),
  94.     );
  95.   }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement