sim_number_picker 0.0.1
sim_number_picker: ^0.0.1 copied to clipboard
A Flutter package designed to streamline the process of retrieving phone number hints from the user's device.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:sim_number_picker/sim_number_picker.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _phoneNumber = '';
final _simNumberPickerPlugin = SimNumberPicker();
@override
void initState() {
super.initState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> getPhoneNumbers() async {
String phoneNumber;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
phoneNumber = await _simNumberPickerPlugin.getPhoneNumberHint() ??
'Unknown platform version';
} on PlatformException {
phoneNumber = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_phoneNumber = phoneNumber;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(child: _body2()),
),
);
}
Widget _body2() {
return InkWell(
child: Container(
width: 200,
height: 50,
decoration: BoxDecoration(
color: Colors.lightGreen, borderRadius: BorderRadius.circular(8)),
child: Center(
child: Text(
'Phone number: $_phoneNumber',
)),
),
onTap: () {
getPhoneNumbers();
},
);
}
}