Plugins in Flutter | Plugins created by FlutterDevs
The road to cross-platform app development has been jam-packed lately, the main reason being its alluring nature of single codebase where developers have to write code once and that code can be used to develop apps for different platforms. I know! This is fun as,
- Single Codebase
- Reduced Development time
- Reduced Development Cost
and of course, there are disadvantages too, no doubt.
Flutter is the latest entry to the cross-platform app development, developed by Google and it’s gaining popularity day by day standing strong against its other competitors because of certain factors:
- Development Time
- Runtime performance
- Good tooling support
However, apart from the various merits that it had established there are few demerits, one being Limited set of libraries.
Even though Flutter is backed by Google but being a relatively new framework it lacks support for 3rd party frameworks and any cross-platform environment depends on the native platform features such as Camera, Bluetooth, Location, etc. which can be accessed using Plugins.
Plugins?
Plugins are the wrapper of the native code like android(java or kotlin) and iOS(swift or Objective C). Plugins are written in platform-specific code to access the platform-specific features.
Flutter does support using packages and plugins contributed by other developers to its ecosystem. You can access Flutter packages and plugins from here.
How do things work underneath the hood?
Flutter’s platform specific API depends on message passing technique, this takes place in two steps. Firstly, Flutter uses the Platform channel as the medium to communicate between the Flutter app and host, the host being the iOS or Android part of the app. Secondly, the host receives the messages through the Platform channel and then it invokes the platform-specific APIs using the native programming language of the platform and sends back the feedback to the Flutter app asynchronously.
In detail, on the client side, the MethodChannel is used to send the messages and on the host side, MethodChannel on Android and FlutterMethodChannel on iOS is used to receive and send messages. All of this is done to make sure that the least amount of boilerplate code is used.
Plugins developed by FlutterDevs team:
The team at FlutterDevs had developed their own plugins of basic day to day needs like an image plugin which picks the images from the storage called image_galley, a QR plugin which scans and generates qr code, a camera plugin, and a location plugin, let’s see about them in detail:
image_gallery:
A flutter plugin to show all your images from the storage. You can get the plugin from here.
usage:
Future<void> loadImageList() async {
List allImageTemp;
allImageTemp = await FlutterGallaryPlugin.getAllImages;
setState(() {
this.allImage = allImageTemp;
});
}
qr_utils:
A flutter plugin to generate and scan QR codes. This plugin can be used to scan 1D barcode and 2D QR code. You can get the plugin from here.
usages:
- Scan QR
final content = await QrUtils.scanQR;
2. Generate QR
Image image = await QrUtils.generateQR(content);
camera_utils:
A flutter plugin which does various works for you, it helps capture an image, pick an image, capture a video, pick a video and pick thumbnail from a video. You can get the plugin from here.
usages:
- Capture an Image
final path = await CameraUtils.captureImage;
2. Pick an Image
final path = await CameraUtils.pickImage;
3. Capture a Video
final path = await CameraUtils.captureVideo;
4. Pick a Video
final path = await CameraUtils.pickVideo;
5. Pick a thumbnail from a video
Future<String> thumbPath = CameraUtils.getThumbnail(path);
thumbPath.then((path) {
setState(() {
_thumbPath = path;
print(path);
});
});
geo_location_finder:
A flutter plugin to get an accurate location on Android and iOS devices. You can get the plugin from here.
usages:
Future<void> _getLocation() async {
Map<dynamic, dynamic> locationMap;
String result;
try {
locationMap = await GeoLocation.getLocation;
var status = locationMap["status"];
if ((status is String && status == "true") ||
(status is bool) && status) {
var lat = locationMap["latitude"];
var lng = locationMap["longitude"];
if (lat is String) {
result = "Location: ($lat, $lng)";
} else {
// lat and lng are not string, you need to check the data type and use accordingly.
// it might possible that else will be called in Android as we are getting double from it.
result = "Location: ($lat, $lng)";
}
} else {
result = locationMap["message"];
}
} on PlatformException {
result = 'Failed to get location';
}
if (!mounted) return;
setState(() {
_result = result;
});
}
These are some of the plugins generated by FlutterDevs. If you wanna create a plugin by yourself then you might want to read this article to walk you through the process of creating a plugin.
Creating a Flutter Plugin for Android and iOS | Image Gallery
Flutter plugin is the wrapper of the native code like android( Kotlin or java) and iOS(swift or objective c)…flutterdevs.com
I hope you liked the article and if you wanna convey something, be it a mistake then feel free to send the feedback in the comments.
Read other articles:
Developing Web Apps Using Flutter | Flutter for Web
Flutter was introduced back in May 2017 with the general idea of Cross-Platform app development initially for Android…medium.com
FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on Facebook, GitHub, and Twitter for any flutter related queries.