GestureDetector ,Draggable,DragTarget

import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';

class WidgetGesture extends StatefulWidget {
@override
_WidgetGestureState createState() => _WidgetGestureState();
}

class _WidgetGestureState extends State<WidgetGesture> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: SingleChildScrollView(
child: Column(
children: [
_buildGestureDetector(),
Divider(),
_buildDraggable(),
Divider(),
_buildDragTarget(),
],
),
),
);
}
}

Draggable<int> _buildDraggable() {
return Draggable(
child: Column(
children: [
Icon(
Icons.palette,
color: Colors.deepOrange,
size: 48.0,
),
Text('Drag me below to change color'),
],
),
childWhenDragging: Icon(
Icons.palette,
color: Colors.grey,
size: 48.0,
),
feedback: Icon(
Icons.brush,
color: Colors.deepOrange,
size: 80.0,
),
data: Colors.deepOrange.value,
);
}

DragTarget<int> _buildDragTarget() {
Color _paintedColor;

return DragTarget<int>(
onAccept: (colorValue) {
_paintedColor = Color(colorValue);
},
builder: (BuildContext context, List<dynamic> acceptedValue,
List<dynamic> rejectedValue) =>
acceptedValue.isEmpty
? Text(
'Drag To and see color change',
style: TextStyle(color: _paintedColor),
)
: Text(
'Painting Color :$acceptedValue',
style: TextStyle(
color: Color(acceptedValue[0]),
fontWeight: FontWeight.bold),
),
);
}

class _buildGestureDetector extends StatefulWidget {
@override
__buildGestureDetectorState createState() => __buildGestureDetectorState();
}

class __buildGestureDetectorState extends State<_buildGestureDetector> {
String gestureDetected = '';

void _displayGesture(String g) {
setState(() {
gestureDetected = g;
});
}

@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
_displayGesture('onTap');
},
onDoubleTap: () {
_displayGesture('onDoubleTap');
},
onLongPress: () {
_displayGesture('onLongPress');
},
onPanUpdate: (DragUpdateDetails dragUpdateDetails) {
_displayGesture(dragUpdateDetails.toString());
},
child: Container(
color: Colors.green.shade100,
width: double.infinity,
padding: EdgeInsets.all(24.0),
child: Column(
children: [
Icon(
Icons.alarm,
size: 98,
),
SizedBox(
height: 15,
),
Text(
gestureDetected,
style: TextStyle(
fontSize: 40,
),
),
],
),
),
);
}
}
GestureDetector ,Draggable,DragTarget GestureDetector ,Draggable,DragTarget Reviewed by Admin on 11:26 PM Rating: 5

No comments:

Powered by Blogger.