import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, theme: ThemeData( primaryColor : Colors.blue ), home : Scaffold ( appBar: AppBar(title: Text("Drag and Drop"), centerTitle: true, ), body: Home(), ) ); } } class Home extends StatefulWidget { @override _HomeState createState() => _HomeState(); } class _HomeState extends State { GlobalKey scaffoldKey = new GlobalKey(); @override Widget build(BuildContext context) { return Scaffold( key: scaffoldKey, body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Draggable( data: 7, child: Container( width: 100.0, height: 100.0, child: Center( child: Text( "7", style: TextStyle(color: Colors.white, fontSize: 26.0), ), ), color: Colors.pink, ), feedback: Container( width: 100.0, height: 100.0, child: Center( child: Text( "7", style: TextStyle(color: Colors.white, fontSize: 26.0), ), ), color: Colors.pink, ), ), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Container( width: 100.0, height: 100.0, color: Colors.green, child: DragTarget( builder: (context, List candidateData, rejectedData) { print(candidateData); return Center(child: Text("Par", style: TextStyle(color: Colors.white, fontSize: 26.0),)); }, onWillAccept: (data) { return true; }, onAccept: (data) { if(data % 2 == 0) { scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("Parabéns!"))); } else { scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("Errado!"))); } }, ), ), Container( width: 100.0, height: 100.0, color: Colors.deepPurple, child: DragTarget( builder: (context, List candidateData, rejectedData) { return Center(child: Text("Ímpar", style: TextStyle(color: Colors.white, fontSize: 26.0),)); }, onWillAccept: (data) { return true; }, onAccept: (data) { if(data % 2 != 0) { scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("Parabéns!"))); } else { scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("Errado!"))); } }, ), ) ], ) ], ), ), ); } }