Flutter is an open-source mobile application development framework created by Google. It is used to develop native mobile applications for Android and iOS. Basically, it's a framework which allows you to write a single code which works on both mobile platforms.
You can install the
flutter SDK from here. Choosing Android Studio or IntelliJ as your development tool is totally your choice.
Let's get started, create a simple templated Flutter app, using the instructions in Getting Started with your first Flutter app.
Use an external package
In this step, you’ll start using an open-source package named
sms, which allows you to send, receive, query SMS messages, SMS delivery, and query contacts info. It exposes an easy to use and friendly set of API for developing a completely functional SMS app in Flutter.
You can find the sms package, as well as many other open source packages, on
The pubspec file manages the assets for a Flutter app. In pubspec.yaml, append
sms: ^0.2.0 to the dependencies list as below:
flutter: sdk: flutter sms: ^0.2.0 # add this line
flutter packages get in the console. This pulls the package into your project. You should see the following in the console:
flutter packages get
Running "flutter packages get" in app_name...
Process finished with exit code 0
In lib/main.dart, import the new package:
Querying SMS messages
SmsQuery query = new SmsQuery();
It creates an instance of the SmsQuery class.
Getting all SMS messages
List messages = await query.getAllSms;
Flutter uses Dart which is also developed by Google. Dart is a single-threaded programming language which helps you write non-blocking code hence if you won't write await, it will not wait for the line to execute and move to the next line. Await here waits for the instruction to be completed, before going to the new line. Also for using await in the code, you need to import the
async package from dart.
Once the above SmSQuery statement executes, the result is stored in the messages variable of type List.
You can try this sample code and log the value of messages, you will see all the message objects are logged in to the console.
In the next blog, we would look into How to listen for incoming messages in Flutter.