Flutter android SMS inbox library based on Flutter SMS.
This package in turn uses the permission handler package for permission handling, Permission Handler.
You need to add it to your project:
dependencies:
permission_handler: ^10.2.0
Add the import statement for sms and create an instance of the SmsQuery class:
import 'package:flutter_sms_inbox/flutter_sms_inbox.dart';
void main() {
SmsQuery query = SmsQuery();
}
List<SmsMessage> messages = await query.getAllSms;
The method querySms
from the SmsQuery
class returns a list of sms depending of the supplied parameters. For example, for querying all the sms messages sent and received write the followed code:
await query.querySms(
kinds: [SmsQueryKind.inbox, SmsQueryKind.sent],
);
You can also query all the sms messages sent and received from a specific contact:
await query.querySms(
address: getContactAddress()
);