flutter_pro_tools 2.2.1 copy "flutter_pro_tools: ^2.2.1" to clipboard
flutter_pro_tools: ^2.2.1 copied to clipboard

is a Flutter package that provides a collection of utilities and tools to help streamline your development process.

flutter pro tools #

flutter_pro_tools is a comprehensive utility package designed to enhance your Flutter development experience. It provides a variety of tools and widgets, including navigation helpers, localization support, snackBar utilities, modal bottom sheets, Firebase integration, local data storage, responsive text, and socket connection management.

Features #

  • Navigation Helpers: Simplify navigation with global keys and custom route animations.
  • Localization Support: Easily translate and localize text within your app.
  • SnackBar Utilities: Quickly display customizable snackBars for notifications and warnings.
  • Modal Bottom Sheets: Show customizable modal bottom sheets with various configurations.
  • Firebase Integration: Initialize Firebase, handle notifications, and manage Firebase messaging.
  • Local Data Storage: Save and retrieve local data using SharedPreferences.
  • Responsive Text: Text widgets that adapt to different screen sizes.
  • Socket Connection: Efficiently manage socket connections.
  • API Requests: Simplify making HTTP requests (GET, POST, DELETE, PUT) with error handling and logging.
  • Image Handling: Choose and crop images with specified settings.
  • Geolocation: Detect and handle user location with permission checks.
  • Camera Capture Utility: Captures an image using the device's camera, crops the image, and ensures it does not exceed the specified file size.

Usage #

Importing the Package In any Dart file where you want to use the utilities from flutter_pro_tools, import the package:

import 'package:flutter_pro_tools/main.dart';

Examples #

Using navigation and snackBar keys #

add navigatorKey and snackBarKey to material app to use navigation and show snack message

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorKey: FlutterProTools.navigatorKey,
      scaffoldMessengerKey: FlutterProTools.snackBarKey,
      home: MyHomePage(),
    );
  }
}

Pushes a new page onto the navigation stack.

function() async {
  FlutterProTools.navigationPush(YourPage());
}

Replaces the current page with a new page.

function() async {
  FlutterProTools.navigationReplace(YourPage());
}

Navigate to a new page, and then remove all the previous navigation stack.

function() async {
  FlutterProTools.navigationRemoveAllPreviousPages(YourPage());
}

Showing a snack bar #

Display a simple snackBar for notifications:

function() async {
  FlutterProTools.showSnackBar(message: 'Hello, this is a snackBar!');
}

Showing a warning snack bar #

Display a warning snackBar

function() async {
  FlutterProTools.showWarningSnackBar(message: 'Warning! Something might be wrong.');
}

Showing a bar modal bottom sheet #

Show a customizable bar modal bottom sheet

function() async {
  FlutterProTools.showBarModal(
    page: MyCustomPage(),
    enableDrag: true,
    isDismissible: true,
  );
}

Showing a modal bottom sheet #

Show a modal bottom sheet

function() async {
  FlutterProTools.showMaterialModel(
    const MyCustomPage(),
  );
}

Firebase initialization #

Initialize Firebase and request notification permissions:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // add firebase project config
  FlutterProTools.setFirebaseProjectConfig(
    apiKey: 'your_api_key',
    appId: 'your_app_id',
    messagingSenderId: 'your_messaging_sender_id',
    projectId: 'your_project_id',
  );
  if (!kIsWeb) {
    // ask user for firebase permission and generate new token then send it to server
    await getFirebasePermissionAndToken(onValue: onValue);
    // init firebase background and all other firebase settings
    await FlutterProTools.initFlutterNotifications();
    // Listens for incoming Firebase Cloud Messaging (FCM) messages and shows a notification
    firebaseMessaging(function: (message) {
      // Handle FCM message.
    });
  }
}

Saving and retrieving local data #

// Save data locally
function() async {
  FlutterProTools.saveLocalDataAsInteger(
      key: 'userAge', value: 30); // Save a integer locally using SharedPreferences:
  await FlutterProTools.saveLocalDataAsBoolean(
      key: 'isLoggedIn', value: true); // Saves a boolean to local storage.
  await FlutterProTools.saveLocalData(
      key: "username", value: "JohnDoe");
  String? username =
  await FlutterProTools.getLocalData(key: "username");
  await FlutterProTools.getLocalData(key: 'username'); // Retrieves a string from local storage.
  FlutterProTools.removeLocalData(
      key: 'username'); // Removes a key-value pair from local storage.
  await FlutterProTools.getLocalDataAsBoolean(
      key: 'isLoggedIn'); // Retrieves a boolean from local storage.
  await FlutterProTools.getLocalDataAsInteger(
      key: 'userAge'); // Retrieves an integer from local storage.
  FlutterProTools.showAlertDialog(
    title: "Local Storage",
    content: ResponsiveText(
      "${FlutterProTools.translate("saved_username")}: $username",
    ),
  );
}

Responsive text widget #

Use the ResponsiveText widget to automatically adjust text size based on screen size:

import 'package:flutter/material.dart';
import 'package:flutter_pro_tools/main.dart';

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: ResponsiveText('Home Page'),
      ),
      body: Center(
        child: ResponsiveText('This text is responsive!'),
      ),
    );
  }
}

Set portrait device #

Sets the device orientation to portrait only:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await FlutterProTools.setPortraitDevice();
  runApp(
    const ProviderScope(
      child: MyApp(),
    ),
  );
}

Read current value #

Reads the current value from the specified ChangeNotifierProvider

function(){
  FlutterProTools.readStatus(providerVal);
}

Recall API #

Re-calls the given API by refreshing the provided Refreshable provider.

function(){
  FlutterProTools.recallAPI(provider);
}

Translate #

please add riverpod in pubspec.yaml

dependencies:
  flutter_riverpod: ^2.5.1

then add this functions

class MyApp extends ConsumerWidget {
  const MyApp({super.key, required this.page});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context, WidgetRef ref) {
    var state = ref.watch(languageStatus);
    return MaterialApp(
      locale: state.currentLocal,
      supportedLocales: AppLocale.supportedLocale(),
      localeResolutionCallback: AppLocale.localeResolutionCallback,
      localizationsDelegates: AppLocale.localizationsDelegates(),
    );
  }
}

then make this directory:

Project Directory Structure #

project
├── assets
│ ├── lang
│ │ ├── en.json
│ │ └── ar.json

Language JSON Files #

add those json file to your project:

assets/lang/ar.json #

{
  "connection_error": "فشل إتصال بالإنترنت",
  "connection_error_content": "أنت غير متصل حاليًا، يرجى التحقق من الاتصال والمحاولة مرة أخرى",
  "ok": "موافق",
  "home": "الرئيسية",
  "send_data_to_socket": "إرسال البيانات إلى السوكيت",
  "send_ack_data_to_socket": "إرسال بيانات Ack إلى السوكيت",
  "navigate_to_new_page": "انتقل إلى الصفحة الجديدة",
  "show_loading_dialog": "عرض مربع حوار التحميل",
  "loading_completed": "اكتمل التحميل",
  "perform_get_request": "أداء طلب GET",
  "no_data": "لا توجد بيانات",
  "save_and_retrieve_local_data": "حفظ واسترجاع البيانات المحلية",
  "saved_username": "اسم المستخدم المحفوظ",
  "change_language": "تغيير اللغة",
  "go_to_login_page": "اذهب إلى صفحة تسجيل الدخول",
  "remove_local_data": "إزالة البيانات المحلية",
  "loading_please_wait": "يتم العمل يرجى الإنتظار",
  "open_camera": "فتح الكميرا",
  "image_picker": "اختر صورة",
  "no_image_selected": "لا توجد صورة",
  "over_512k": "لقد اخترت صورة أصغر من 512kb يرجى اختيار صورة أصغر",
  "open_bar_model": "فتح نافذة من الأسفل",
  "open_material_model": "فتح صفحة جديدة من الأسفل",
  "get_current_language": "لغة التطبيق الحالية",
  "display_notification": "إظهار إشعار"
}

assets/lang/en.json #

{
  "connection_error": "Internet connection failed.",
  "connection_error_content": "You are currently offline please check your connection and try again",
  "ok": "OK",
  "home": "Home",
  "send_data_to_socket": "Send data to socket",
  "send_ack_data_to_socket": "Send Ack data to socket",
  "navigate_to_new_page": "Navigate to New Page",
  "show_loading_dialog": "Show Loading Dialog",
  "loading_completed": "Loading Completed",
  "perform_get_request": "Perform GET Request",
  "no_data": "No data",
  "save_and_retrieve_local_data": "Save and Retrieve Local Data",
  "saved_username": "Saved username",
  "change_language": "Change language",
  "go_to_login_page": "Go to login page",
  "remove_local_data": "Remove local data",
  "loading_please_wait": "Loading please wait",
  "open_camera": "Open camera",
  "image_picker": "Image picker",
  "no_image_selected": "No Image Selected",
  "over_512k": "your image is over than 512 kb please select smaller one",
  "open_bar_model": "Open bar model",
  "open_material_model": "Open material model",
  "get_current_language": "Get current language",
  "display_notification": "Display notification"
}

You need it add this in each page you need to translate:

class MyApp extends ConsumerWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context, WidgetRef ref) {
    var state = ref.watch(languageStatus); // this line
    return MaterialApp(
      home: const HomePage(),
      locale: state.locale,
    );
  }
}

Translates a key into the current locale's language


String translatedText = FlutterProTools.translate('hello');

To change application language (supported only arabic and english):

function() {
  FlutterProTools.getCurrentLanguage == "en"
      ? languageState.changeLanguage('ar')
      : languageState.changeLanguage('en');
}

To change the current language from outside the page (e.g: controller):

changeLanguage() {
  FlutterProTools.changeLanguage('ar');
}

Get current language #

To get current app language

function() async {
  String language = FlutterProTools.getCurrentLanguage;
}

Close page #

Closes the current modal or bar modal.

function() {
  FlutterProTools.closePage();
}

Close keyboard #

Closes the keyboard if it is open.

function() {
  FlutterProTools.closeKeyboard();
}

Get request #

  • notice that the response in this plugin handle to return as Map<String, dynamic> Performs a GET HTTP request.
function() {
  FlutterProTools.getRequest(
    url: "https://jsonplaceholder.typicode.com/posts/1",
    response: (data) =>
        FlutterProTools.showAlertDialog(
          title: "GET Request",
          content: ResponsiveText(
            data.body,
          ),
        ),
  );
}

Send request #

Performs a POST HTTP request.

function() {
  FlutterProTools.sendRequest(
    url: 'https://api.example.com/data',
    data: {name: "name example"},
    File ? file : file,
    String ? jsonFileKeyName : jsonFileKeyName,
    authorization: 'Bearer token',
    response: (http.Response response) {
      print(response.body);
    },
  );
}

Delete request #

Performs a DELETE HTTP request.

function() {
  FlutterProTools.deleteRequest(
    url: 'https://api.example.com/data',
    authorization: 'Bearer token',
    response: (http.Response response) {
      print(response.body);
    },
  );
}

Update request #

Performs a PUT HTTP request.

function() {
  FlutterProTools.updateRequest(
    url: 'https://api.example.com/data',
    data: {name: "name example"},
    File ? file : file,
    String ? jsonFileKeyName : jsonFileKeyName,
    authorization: 'Bearer token',
    response: (http.Response response) {
      print(response.body);
    },
  );
}

Show material model #

Shows a material bottom sheet modal.

function() {
  FlutterProTools.showMaterialModel(
    const ModelPage(),
  );
}

Show alert dialog #

Shows an alert dialog.

function() {
  FlutterProTools.showAlertDialog(
    content: Text('This is an alert dialog.'),
    title: 'Alert',
  );
}

Show error alert dialog #

Shows an error alert dialog and executes a function when "OK" is pressed.

function() {
  FlutterProTools.showErrorAlertDialog(() {
    print('Retry action');
  });
}

Save local data as integer #

Saves an integer to local storage

Show notification #

Shows a notification with a title and body.

function() {
  FlutterProTools.showNotification(
      title: 'Notification Title',
      body: 'This is the body of the notification.',
      otherData: {
        "title": "Payload title",
        "body": "Payload body",
      },
      function: (data) {
        FlutterProTools.logFile(message: data.payload!);
      });
}

launchURL #

Navigate to external url

function() {
  FlutterProTools.launchURL("https://google.com", () => print(ok));
}

Loading progress dialog #

Show loading dialog during request processing

function() {
  FlutterProTools.showLoadingDialog();
}

Close loading dialog #

Close loading dialog when request ended

function() {
  FlutterProTools.dismissLoadingDialog();
}

Log file #

To show log inside your app

function() {
  FlutterProTools.logFile(message: "this is log file", name: "log file");
}

Pretty log file #

To show log inside your app with Map data type

function() {
  FlutterProTools.prettyLogFile(message: data);
}

Get date formated #

get the date formated in form yyyy-MM-dd

function() {
  FlutterProTools.getDate(date);
}

get random number #

get random number length :

function() {
  print(FlutterProTools.getInteger(6));
}

Image handling #

Choose and crop images with specified settings.

function() async {
  Map<String, dynamic> result = await FlutterProTools.chooseImage();
}

Geolocation #

Detect the user's current location.

function() async {
  var result = await FlutterProTools.detectMyLocation();
}

Add the following to your "gradle.properties" file:

android.useAndroidX=true
android.enableJetifier=true

Make sure you set the compileSdkVersion in your "android/app/build.gradle" file to 34:

android {
compileSdkVersion 34

...
}

Add the following to your AndroidManifest.xml:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

Add the following if you want to receive you position in background to your AndroidManifest.xml:

<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

Image cropper #

Choose and crop images with specified settings.

function() async {
  XFile result = await FlutterProTools.cropImage();
}

Add in AndroidManifest.xml

<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>

Camera capture #

Captures an image using the device's camera, crops the image.

function() async {
  Map<String, dynamic> result = await FlutterProTools.cameraCapture();
}

License #

This project is licensed under a Custom App Usage License. You are permitted to use this software as part of your application, but you are not allowed to copy, modify, merge, publish, distribute, sublicense, or sell copies of the software, or permit others to do so.