Skip to content

Instantly share code, notes, and snippets.

@deven98
Created November 17, 2018 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deven98/37fc4781d6b9c75961cc5d968e0ee0b4 to your computer and use it in GitHub Desktop.
Save deven98/37fc4781d6b9c75961cc5d968e0ee0b4 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:chess_vectors_flutter/chess_vectors_flutter.dart';
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey();
@override
Widget build(BuildContext context) {
return Scaffold(
key: scaffoldKey,
appBar: AppBar(),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Draggable(
data: 5,
child: Container(
width: 100.0,
height: 100.0,
child: Center(
child: Text(
"5",
style: TextStyle(color: Colors.white, fontSize: 22.0),
),
),
color: Colors.pink,
),
feedback: Container(
width: 100.0,
height: 100.0,
child: Center(
child: Text(
"5",
style: TextStyle(color: Colors.white, fontSize: 22.0),
),
),
color: Colors.pink,
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
width: 100.0,
height: 100.0,
color: Colors.green,
child: DragTarget(
builder:
(context, List<int> candidateData, rejectedData) {
print(candidateData);
return Center(child: Text("Even", style: TextStyle(color: Colors.white, fontSize: 22.0),));
},
onWillAccept: (data) {
return true;
},
onAccept: (data) {
if(data % 2 == 0) {
scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("Correct!")));
} else {
scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("Wrong!")));
}
},
),
),
Container(
width: 100.0,
height: 100.0,
color: Colors.deepPurple,
child: DragTarget(
builder:
(context, List<int> candidateData, rejectedData) {
return Center(child: Text("Odd", style: TextStyle(color: Colors.white, fontSize: 22.0),));
},
onWillAccept: (data) {
return true;
},
onAccept: (data) {
if(data % 2 != 0) {
scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("Correct!")));
} else {
scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("Wrong!")));
}
},
),
)
],
)
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment