Advertisement
Guest User

Untitled

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