Advertisement
Guest User

Untitled

a guest
Oct 5th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.79 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3.  
  4.  
  5. class PageA extends StatefulWidget {
  6.  
  7.  
  8.  
  9.  
  10.  
  11.   @override
  12.   _PageAState createState() => _PageAState();
  13. }
  14.  
  15. class _PageAState extends State<PageA> with TickerProviderStateMixin{
  16.  
  17.   @override
  18.   Widget build(BuildContext context) {
  19.     return Scaffold(
  20.       appBar: AppBar(
  21.         title: Text("PageA"),
  22.       ),
  23.       body: Center(
  24.         child: Text("okay"),
  25.       ),
  26.       floatingActionButtonLocation: FloatingActionButtonLocation.endDocked,
  27.       floatingActionButton: TransitionFab(
  28.         screenHeight: MediaQuery.of(context).size.height - 65.0,
  29.         screenWidth: MediaQuery.of(context).size.width,
  30.       ),
  31.     );
  32.   }
  33. }
  34.  
  35. class TransitionFab extends StatefulWidget {
  36.  
  37.   var screenWidth;
  38.   var screenHeight;
  39.  
  40.   TransitionFab({this.screenWidth, this.screenHeight});
  41.  
  42.   @override
  43.   _TransitionFabState createState() => _TransitionFabState();
  44. }
  45.  
  46. class _TransitionFabState extends State<TransitionFab> with TickerProviderStateMixin{
  47.  
  48.   AnimationController _controller;
  49.   Animation _animationBorderRadius;
  50.   Animation _animationFabSizeWidth;
  51.   Animation _animationFabSizeHeight;
  52.   Animation _animationNegativePadding;
  53.  
  54.   bool didStart = false;
  55.  
  56.  
  57.   @override
  58.   void initState() {
  59.     super.initState();
  60.  
  61.     _controller = new AnimationController(vsync: this, duration: Duration(milliseconds: 400));
  62.  
  63.     _animationBorderRadius = BorderRadiusTween(
  64.         begin: BorderRadius.circular(75.0),
  65.         end: BorderRadius.circular(0.0)
  66.     ).animate(CurvedAnimation(
  67.         parent: _controller,
  68.         curve: Curves.ease
  69.     ));
  70.  
  71.     _animationFabSizeWidth = Tween(
  72.         begin: 50.0,
  73.         end: widget.screenWidth
  74.     ).animate(CurvedAnimation(
  75.         parent: _controller,
  76.         curve: Curves.ease
  77.     ));
  78.  
  79.     _animationFabSizeHeight = Tween(
  80.       begin: 50.0,
  81.       end: widget.screenHeight,
  82.     ).animate(CurvedAnimation(
  83.         parent: _controller,
  84.         curve: Curves.ease
  85.     ));
  86.  
  87.  
  88.   }
  89.  
  90.   void startAnim(){
  91.     setState(() {
  92.       didStart = !didStart;
  93.     });
  94.     if(didStart){
  95.       _controller.reverse();
  96.     }else{
  97.       _controller.forward();
  98.     }
  99.   }
  100.  
  101.   @override
  102.   Widget build(BuildContext context) {
  103.     return AnimatedBuilder(
  104.       animation: _controller,
  105.       builder: (BuildContext context, Widget child){
  106.         return InkWell(
  107.           onTap: () => this.startAnim(),
  108.           child: new Container(
  109.             width: _animationFabSizeWidth.value,
  110.             height: _animationFabSizeHeight.value,
  111.             decoration: BoxDecoration(
  112.                 borderRadius: _animationBorderRadius.value,
  113.                 color: Colors.blue[500]
  114.             ),
  115.             child: Icon(Icons.add, color: Colors.white),
  116.           ),
  117.         );
  118.       }
  119.     );
  120.   }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement