Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. class DragButton extends StatefulWidget {
  4. String title, route;
  5. DragButton({this.title, this.route});
  6.  
  7. @override
  8. _DragButtonState createState() => _DragButtonState();
  9. }
  10.  
  11. class _DragButtonState extends State<DragButton> {
  12. bool isRight = false;
  13.  
  14. @override
  15. Widget build(BuildContext context) {
  16. return GestureDetector(
  17. onHorizontalDragUpdate: (direction) {
  18. var sentido = direction.delta.dx;
  19. setState(() {
  20. if (sentido > 0) {
  21. isRight = true;
  22. Future.delayed(Duration(seconds: 1)).then((value) {
  23. return Navigator.pushNamed(context, '/home');
  24. });
  25. } else {
  26. isRight = false;
  27. }
  28. });
  29. },
  30. child: Draggable(
  31. maxSimultaneousDrags: isRight ? 1 : 0,
  32. feedbackOffset: Offset(100, 0),
  33. axis: Axis.horizontal,
  34. child: Container(
  35. width: MediaQuery.of(context).size.width / 1.8,
  36. height: 50,
  37. decoration: BoxDecoration(
  38. color: Colors.amber[700],
  39. borderRadius: BorderRadius.only(
  40. topRight: Radius.circular(30),
  41. bottomRight: Radius.circular(30)),
  42. ),
  43. child: Center(
  44. child: Container(
  45. child: Text(widget.title,
  46. style: TextStyle(
  47. color: Colors.white,
  48. fontWeight: FontWeight.w700,
  49. fontSize: 16,
  50. )))),
  51. ),
  52. feedback: Container(
  53. width: MediaQuery.of(context).size.width / 1.8,
  54. height: 50,
  55. decoration: BoxDecoration(
  56. color: Colors.amber[700],
  57. borderRadius: BorderRadius.only(
  58. topRight: Radius.circular(30),
  59. bottomRight: Radius.circular(30)),
  60. ),
  61. child: Center(
  62. child: Container(
  63. child: Text(
  64. widget.title,
  65. style: TextStyle(
  66. color: Colors.white, fontWeight: FontWeight.w600, fontSize: 20),
  67. ))),
  68. ),
  69. childWhenDragging: Container(
  70. width: MediaQuery.of(context).size.width / 1.7,
  71. height: 50,
  72. decoration: BoxDecoration(
  73. color: Colors.amber[700],
  74. borderRadius: BorderRadius.only(
  75. topRight: Radius.circular(30),
  76. bottomRight: Radius.circular(30)),
  77. ),
  78. ),
  79. ),
  80. );
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement