Fireship · @fireship
Flutter Drag & Drop for Two-Year-Olds
Uploaded May 1, 2019 · Length 8:19
Summary
build a simple kids game with drag and drop feature using flutter and audio player plugin
- flutter drag and drop
- flutter kids game
- flutter audio player
- flutter game development
- flutter tutorial
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
yesterday my two-year-old was playing
- 0:01
with a book that has you connect a color
- 0:03
to a fruit and I realize that would be
- 0:05
the perfect feature to demonstrate drag
- 0:06
and drop and flutter in today's video
- 0:08
we'll build a simple kids game that
- 0:10
allows you to drag a fruit over to a
- 0:12
square with the corresponding color if
- 0:13
you drop it on the correct square it
- 0:15
will update the score and also give you
- 0:17
some audio feedback if you're new here
- 0:20
like and subscribe and you can find the
- 0:21
full source code on fire ship bio now
- 0:23
before we get started a lot of people
- 0:25
have asked me when I'm going to release
- 0:27
a full flutter course the answer is very
- 0:29
soon it'll be released before Google i/o
- 0:31
which is now only six days away so
- 0:32
expect more details on that in the next
- 0:34
few days now let's go ahead and take a
- 0:36
closer look at the app we're building
- 0:37
today you'll see two columns here and
- 0:39
you can grab an item from the column on
- 0:41
the left and then drag it to a target on
- 0:43
the right if it's the correct color it
- 0:45
will mark it as correct and then update
- 0:46
the score but if it's dropped on the
- 0:48
incorrect target then it will just go
- 0:49
back to its original position and then
- 0:51
we'll also randomize the ordering of the
- 0:53
targets for each round just so there's a
- 0:55
little bit of replay value and as an
- 0:56
added touch we'll play a little sound
- 0:58
effect every time the user makes a
- 0:59
successful drop if we jump into the code
- 1:03
the first thing we'll look at is the pub
- 1:04
spec amyl file the only dependency
- 1:06
outside of flutter is this audio players
- 1:08
plugin I really like this plug-in
- 1:10
because it works on both iOS and Android
- 1:11
and also allows you to play multiple
- 1:14
audio files simultaneously and that
- 1:15
tends to be pretty important if you're
- 1:17
building a game and you'll also notice
- 1:18
that we have an mp3 file here registered
- 1:20
in the assets directory and I've also
- 1:22
registered a custom font called press
- 1:24
Start which you can download from Google
- 1:25
Fonts that'll give you that kind of
- 1:27
pixelated retro look now moving on to
- 1:29
the source code I'm importing dart math
- 1:31
as well as the audio players plug-in
- 1:33
then we'll update the font family in our
- 1:35
theme data and then we'll set the home
- 1:37
page as this color game screen that
- 1:39
we're about to define now the screen
- 1:40
itself is a stateful widget and the
- 1:42
first property we'll define is the score
- 1:44
which just starts out as an empty map
- 1:46
eventually we'll update the keys on this
- 1:48
map when the user drags a draggable
- 1:50
widget on to the correct drag target the
- 1:52
next thing we'll define is a map of
- 1:53
choices and so each emoji which is a
- 1:55
string will map to a material color
- 1:57
emojis are really handy because they not
- 1:59
only provide a graphic that we can use


