Advertisement
BlackBoY_

bukan_praktikum

Jun 7th, 2022
1,331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 4.83 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() {
  4.   runApp(MyApp());
  5. }
  6.  
  7. class MyApp extends StatelessWidget {
  8.   @override
  9.   Widget build(BuildContext context) {
  10.     return MaterialApp(
  11.       home: Scaffold(
  12.         appBar: AppBar(
  13.           title: Text("Gestur App"),
  14.         ),
  15.         body: Column(
  16.           children: [
  17.             HorizontalDrag(),
  18.             Divider(),
  19.             VerticalDrag(),
  20.             Divider(),
  21.             TapExample(),
  22.             Divider(),
  23.             DoubleTapExample(),
  24.             Divider(),
  25.             OnLongPressExample(),
  26.           ],
  27.         ),
  28.       ),
  29.     );
  30.   }
  31. }
  32.  
  33. class VerticalDrag extends StatefulWidget {
  34.   @override
  35.   State<VerticalDrag> createState() => _VerticalDragState();
  36. }
  37.  
  38. class _VerticalDragState extends State<VerticalDrag> {
  39.   bool _dragging = false;
  40.   Offset _move = Offset.zero;
  41.   int _dragCount = 0;
  42.  
  43.   @override
  44.   Widget build(BuildContext context) {
  45.     return GestureDetector(
  46.       onVerticalDragStart: (DragStartDetails details) {
  47.         setState(() {
  48.           _dragging = true;
  49.           //_move = Offset.zero;
  50.         });
  51.       },
  52.       onVerticalDragEnd: (DragEndDetails details) {
  53.         setState(() {
  54.           _dragging = false;
  55.           _dragCount++;
  56.         });
  57.       },
  58.       onVerticalDragUpdate: (DragUpdateDetails details) {
  59.         setState(() {
  60.           _move += details.delta;
  61.         });
  62.       },
  63.       child: Container(
  64.         color: Colors.grey,
  65.         child: Center(
  66.           child: Transform.translate(
  67.             offset: _move,
  68.             child: Text(
  69.               _dragging ? "DRAGGING!" : "Drag : $_dragCount",
  70.               style: Theme.of(context).textTheme.headline4,
  71.             ),
  72.           ),
  73.         ),
  74.       ),
  75.     );
  76.   }
  77. }
  78.  
  79. class HorizontalDrag extends StatefulWidget {
  80.   @override
  81.   State<HorizontalDrag> createState() => _HorizontalDragState();
  82. }
  83.  
  84. class _HorizontalDragState extends State<HorizontalDrag> {
  85.   bool _dragging = false;
  86.   Offset _move = Offset.zero;
  87.   int _dragCount = 0;
  88.  
  89.   @override
  90.   Widget build(BuildContext context) {
  91.     return GestureDetector(
  92.       onHorizontalDragStart: (DragStartDetails details) {
  93.         setState(() {
  94.           _dragging = true;
  95.           //_move = Offset.zero;
  96.         });
  97.       },
  98.       onHorizontalDragEnd: (DragEndDetails details) {
  99.         setState(() {
  100.           _dragging = false;
  101.           _dragCount++;
  102.         });
  103.       },
  104.       onHorizontalDragUpdate: (DragUpdateDetails details) {
  105.         setState(() {
  106.           _move += details.delta;
  107.         });
  108.       },
  109.       child: Container(
  110.         color: Colors.grey,
  111.         child: Center(
  112.           child: Transform.translate(
  113.             offset: _move,
  114.             child: Text(
  115.               _dragging ? "DRAGGING!" : "Drag : $_dragCount",
  116.               style: Theme.of(context).textTheme.headline4,
  117.             ),
  118.           ),
  119.         ),
  120.       ),
  121.     );
  122.   }
  123. }
  124.  
  125. class TapExample extends StatefulWidget {
  126.   @override
  127.   State<TapExample> createState() => _TapExampleState();
  128. }
  129.  
  130. class _TapExampleState extends State<TapExample> {
  131.   int _counter = 0;
  132.   @override
  133.   Widget build(BuildContext context) {
  134.     return GestureDetector(
  135.       onTap: () {
  136.         setState(() {
  137.           _counter++;
  138.         });
  139.       },
  140.       child: Container(
  141.         color: Colors.grey,
  142.         child: Center(
  143.           child: Text(
  144.             "Tap Count : $_counter",
  145.             style: Theme.of(context).textTheme.headline4,
  146.           ),
  147.         ),
  148.       ),
  149.     );
  150.   }
  151. }
  152.  
  153. class DoubleTapExample extends StatefulWidget {
  154.   @override
  155.   State<DoubleTapExample> createState() => _DoubleTapExampleState();
  156. }
  157.  
  158. class _DoubleTapExampleState extends State<DoubleTapExample> {
  159.   int _counter = 0;
  160.   @override
  161.   Widget build(BuildContext context) {
  162.     return GestureDetector(
  163.       onDoubleTap: () {
  164.         setState(() {
  165.           _counter++;
  166.         });
  167.       },
  168.       child: Container(
  169.         color: Colors.grey,
  170.         child: Center(
  171.           child: Text(
  172.             "Double Tap Count : $_counter",
  173.             style: Theme.of(context).textTheme.headline4,
  174.           ),
  175.         ),
  176.       ),
  177.     );
  178.   }
  179. }
  180.  
  181. class OnLongPressExample extends StatefulWidget {
  182.   @override
  183.   State<OnLongPressExample> createState() => _OnLongPressExampleState();
  184. }
  185.  
  186. class _OnLongPressExampleState extends State<OnLongPressExample> {
  187.   int _counter = 0;
  188.   @override
  189.   Widget build(BuildContext context) {
  190.     return GestureDetector(
  191.       onLongPress: () {
  192.         setState(() {
  193.           _counter++;
  194.         });
  195.       },
  196.       child: Container(
  197.         color: Colors.grey,
  198.         child: Center(
  199.           child: Text(
  200.             "On Long Press Count : $_counter",
  201.             style: Theme.of(context).textTheme.headline4,
  202.           ),
  203.         ),
  204.       ),
  205.     );
  206.   }
  207. }
  208.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement