60 Days of Flutter : Day 8 : Changing The Launcher Icon and Implementing GestureDetector
Today’s post is going to be a mix of few different things. We’re gonna start with quickly changing the app’s logo and then move on to the few things we had pending from yesterday.
How Do I Change the App’s Icon?
It’s pretty straightforward and we’ll be using flutter_launcher_icons to do it. This package generates all the necessary icon assets for both Android as well as iOS without us manually needing to provide them individually for both the OS. Let’s get started.
The first thing you need to do is grab the latest version of the package from pub.dev and add it to your dev_dependencies
in pubspec.yaml
. In our case it’s 0.7.2+1
.
dev_dependencies:
flutter_test:
sdk: flutter
flutter_launcher_icons: ^0.7.2+1
Next let’s define the icons. We’ll need three of them, the foreground, the background and the final resultant icon.
We’re putting them inside the asset/launcher
directory. Feel free to use whatever directory structure you feel convenient with. Let’s now define these icons in our pubspec.yaml
.
flutter_icons:
ios: true
android: true
image_path_ios: "assets/launcher/ic_launcher.png"
image_path_android: "assets/launcher/ic_launcher.png"
adaptive_icon_background: "assets/launcher/ic_background.png"
adaptive_icon_foreground: "assets/launcher/ic_foreground.png"
Next run the command to generate the icons:
flutter packages pub run flutter_launcher_icons:main
this will run the package and generate the necessary assets.
Build and run your app and you should see the app with new icons.
Let’s move to the next part !
Fixing The BottomSheet
I kept few items in TODO from yesterday’s post about bottomsheet. Let’s implement them one by one.
- You cannot swipe down to dismiss the sheet
We want our ChatList
Bottomsheet to be dismissed upon drag down. To achieve this I have first wrapped the NavigationPill
and the Title Text
inside another ListView
.
ListView(
shrinkWrap: true,
physics: ClampingScrollPhysics(),
children: <Widget>[
NavigationPillWidget(),
Center(
child: Text('Messages', style: Styles.textHeading)),
SizedBox(
height: 20,
),
])
We wrap this ListView
inside a GestureDetector
and use the onVerticalDragEnd event.
Here the primaryVelocity
is the average velocity of the user’s drag event (pixels/second). We want to make sure that it’s greater than 50 so that it’s a drag and not just an accidental touch.
- We need to extract out the InputWidget from the ConversationPage Widget to the outer ConversationPageSlide Widget
This wasn’t as simple as I thought it would be. Doing this made me learn some important concepts related to layouting in flutter. Here are few catches:
- A
Scaffold
creates the basic material design layout which contains theAppbar
, thebody
, etc. OurBottomSheet
depends on the InputWidget as well as the Scaffold. So if we’re moving theInputWidget
we’ll also need to move theScaffold
. - A
PageView
has a unbounded height and can never be directly nested in aColumn
. We have to wrap it inside aExpanded
widget to make it work.
I highly recommend you view the Code Changes section to understand what moved where:
We moved out the Scaffold
from the ConversationPage
but I wanted to keep the AppBar
in ConversationPage
, So I’ve used a Column
Widget.
BONUS: Moving the InputWidget also solves our third problem,which is,
- We need to hide/shadow the top toolbar from the current active chat.
Because after the above changes the ChatList easily flows over the toolbar like this.
Definitely a lot cleaner and smoother than what we built initially !
References
Flutter Deep Dive, Part 4: “RenderFlex children have non-zero flex…”
Code Changes
#8 DragDown Gesture for BottomSheet
How Can You Contribute?
- Open issues with suggestion of better approaches or ideas for the app.
- Connect with me on Twitter or Linkedin.
- Star the Github repository.
- Share the series on Twitter.
- Follow me on Github.
How Can You Contribute?
- Open issues with suggestion of better approaches or ideas for the app.
- Connect with me on Twitter or Linkedin or Instagram.
- Star the Github repository.
- Share the series on Twitter.
- Follow me on Github.
Posts In This Series
- 60 Days Of Flutter : Building a Messenger from Scratch
- 60 Days of Flutter : Day 1 : Creating the App
- 60 Days of Flutter : Day 2 : Setting Up A CI With Flutter
- 60 Days of Flutter : Day 3–4 : Building a Chat Screen in Flutter
- 60 Days of Flutter : Day 4–5 : Widget Testing With Flutter
- 60 Days of Flutter : Day 6–7 : Implementing a Slideable Widget Using Bottomsheet in Flutter
- 60 Days of Flutter : Day 8 : Changing The Launcher Icon and Implementing GestureDetector
- 60 Days of Flutter : Day 9–10–11 : Creating Awesome Register Screen in Flutter
- 60 Days of Flutter : Day 12–14 : Understanding BLoC Pattern in Flutter
- 60 Days of Flutter : Day 15–17 : Implementing Registration Screen using ‘flutter_bloc’
- 60 Days of Flutter : Day 18–19 : Unit Testing in Flutter using ‘ mockito’
- 60 Days of Flutter : Day 20–21 : Unit Testing a Bloc in Flutter
- 60 Days of Flutter : Day 22–23 : Building a Modern Contacts Page in Flutter
- 60 Days of Flutter : Day 24–26 : Building a Animated Progress Fab and the Contacts Bloc in Flutter
- 60 Days of Flutter : Day 27–29 : Sending and Retrieving Messages from Firebase using BLOC
- 60 Days of Flutter : Day 30–32 : Firebase Chat UI using Stream and Bloc
- 60 Days of Flutter : Day 33–35 : Paginating data from Firestore using Firebase Queries
- 60 Days of Flutter : Day 36–38 : Seamlessly Upload Files to Firebase Storage
- 60 Days of Flutter : Day 39–41 : One UI Inspired Attachments Showcase Page
- 60 Days of Flutter : Day 42–45 : Creating the Home Page & Quick Peek BottomSheet for Messages
- 60 Days of Flutter : Day 45–47 : Adding Dark Mode to a Flutter App
- 60 Days of Flutter : Day 48–50 : Creating the Settings Page using Bloc
- 60 Days of Flutter : Day 51–54 : Unit Testing Firebase Providers with Mockito
- 60 Days of Flutter : Day 55–56 : Deploying Firestore Security Rules using Firebase CLI
- 60 Days of Flutter : Day 60 : Wrapping It Up
Show Your Support
Press the clap button below if you liked reading this post. The more you clap the more it motivates me to write better!