Top 10 Flutter Useful Package

In this article, I am going to discuss some of the most famous and useful flutter packages. 

1. shared_preferences

The shared_preferences package saves data in key-value pairs in your local storage, So it is a good package if you want to store small data in your app.

Save data

SharedPreferences preferences = await SharedPreferences.getInstance();
preferences.setString("username", username); //string dta
preferences.setInt("pin", 1234); //integer data
preferences.setBool("status", true); //boolean data
preferences.setDouble("width", 11.2); //double data

Read data

SharedPreferences preferences = await SharedPreferences.getInstance();
preferences.getString("username"); //string data
preferences.getInt("username"); // integer data
preferences.getBool("status"); // boolean data
preferences.getBool("width"); // double data

Remove data

SharedPreferences preferences = await SharedPreferences.getInstance();
preferences.remove("username"); // double data

Package link: https://pub.dev/packages/shared_preferences

2. cached_network_image

The cached_network_image package gets the image from the URL and shows it in the app and also it keeps the image in cached memory for future use.

//With a placeholder
CachedNetworkImage(
        imageUrl: "http://via.placeholder.com/350x150",
        placeholder: (context, url) => CircularProgressIndicator(),
        errorWidget: (context, url, error) => Icon(Icons.error),
     ),

//Or with a progress indicator 
CachedNetworkImage(
        imageUrl: "http://via.placeholder.com/350x150",
        progressIndicatorBuilder: (context, url, downloadProgress) => 
                CircularProgressIndicator(value: downloadProgress.progress),
        errorWidget: (context, url, error) => Icon(Icons.error),
     ),

Package link: https://pub.dev/packages/cached_network_image

3. http

The http package is used to send and receive HTTP requests and responses from the internet or in simple language you can say it is used to handle REST APIs.

var url = Uri.parse('https://example.com/whatsit/create');
var response = await http.post(url, body: {'name': 'doodle', 'color': 'blue'});
print('Response status: ${response.statusCode}');
print('Response body: ${response.body}');

print(await http.read('https://example.com/foobar.txt'));

Package link: https://pub.dev/packages/http

4. webview_flutter

If want to open a web URL in your app, then it is a good option to use it provides a web view widget in a flutter.

bool _isLoading = true;
  final _key = UniqueKey();
  String url;

  @override
  Widget build(BuildContext context) {
    final Completer<WebViewController> _controller =
        Completer<WebViewController>();
    final UserProvider userProvider = Provider.of<UserProvider>(context);
    url = "https://www.c-sharpcorner.com";
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text(“C# Corner"),
      ),
      body: Stack(
        children: <Widget>[
          WebView(
            key: _key,
            initialUrl: url,
            javascriptMode: JavascriptMode.unrestricted,
            onWebViewCreated: (WebViewController webViewController) {
              _controller.complete(webViewController);
            },
            onPageFinished: (finish) {
              setState(() {
                _isLoading = false;
              });
            },
          ),
          _isLoading
              ? Center(
                  child: CircularProgressIndicator(),
                )
              : Stack(),
        ],
      ),
    );
  }

Package link: https://pub.dev/packages/webview_flutter

5. url_launcher

When you want to open any URL from the app to your web browser then the url_launcher flutter package is a good choice, it’s open your URL in the web browser.

void launchUrl({String url}) async {
 if (await canLaunch(url)) {
   await launch(url);
 } else {
   throw 'Could not launch $url';
 }
}

launchUrl(url: “https://www.c-sharpcorner.com”);

Package link: https://pub.dev/packages/url_launcher

6. dio

The dio is a powerful flutter package that supports Interceptors, Global configuration, FormData, Request Cancellation, File downloading, ConnectionTimeout, etc.

Using the dio package you can perform GET, POST, File downloading, File Uploading, and many more.

I will suggest you read this article, It will help you to how to use dio in your app.

Package link: https://pub.dev/packages/dio

7. path_provider

The path_provider package gives the folder location path, so using that path you can easily save the file there.

Directory tempDir = await getTemporaryDirectory();
String tempPath = tempDir.path;

Directory appDocDir = await getApplicationDocumentsDirectory();
String appDocPath = appDocDir.path;

Package link: https://pub.dev/packages/path_provider

8. package_info

The package_info works as a bridge to fetch the application version information on both iOS and Android.

import 'package:package_info/package_info.dart';

PackageInfo packageInfo = await PackageInfo.fromPlatform();

String appName = packageInfo.appName;
String packageName = packageInfo.packageName;
String version = packageInfo.version;
String buildNumber = packageInfo.buildNumber;

Package link: https://pub.dev/packages/package_info

9. connectivity

The connectivity package allows flutter apps to discover network connectivity and configure accordingly. This plug-in has the ability to distinguish between cellular and WiFi connections.

import 'package:connectivity/connectivity.dart';

var connectivityResult = await (Connectivity().checkConnectivity());
if (connectivityResult == ConnectivityResult.mobile) {
  // I am connected to a mobile network.
} else if (connectivityResult == ConnectivityResult.wifi) {
  // I am connected to a wifi network.
}

Package link: https://pub.dev/packages/connectivity

10. flutter_share

The flutter_share plugin gives you the opportunity to share your content to other platforms.

Future<void> share(dynamic link, String title) async {
 await FlutterShare.share(
     title: title, text: title, linkUrl: link, chooserTitle: shareTitle);
}

Package link: https://pub.dev/packages/flutter_share

Conclusion

These are some of the most useful flutter plugins that flutter developers are using. There are more plugins that are also popular but this is based on my knowledge that I use as a flutter developer.  

Thanks for reading....


Similar Articles