flutter_pro_tools 1.1.4
flutter_pro_tools: ^1.1.4 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.
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(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorKey: FlutterProTools.navigatorKey,
scaffoldMessengerKey: FlutterProTools.snackBarKey,
home: MyHomePage(),
);
}
}
Navigation push #
Pushes a new page onto the navigation stack.
FlutterProTools.navigationPush(YourPage());
Navigation replace #
Replaces the current page with a new page.
FlutterProTools.navigationReplace(YourPage());
Navigation and remove all the previous routes #
Navigate to a new page, and then remove all the previous navigation stack.
FlutterProTools.navigationRemoveAllPreviousPages(YourPage());
Showing a snack bar #
Display a simple snackBar for notifications:
FlutterProTools.showSnackBar(message: 'Hello, this is a snackBar!');
Showing a warning snack bar #
Display a warning snackBar
FlutterProTools.showWarningSnackBar(message: 'Warning! Something might be wrong.');
Showing a bar modal bottom sheet #
Show a customizable bar modal bottom sheet
FlutterProTools.showBarModal(
page: MyCustomPage(),
enableDrag: true,
isDismissible: true,
);
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();
}
}
Saving and retrieving local data #
Save and retrieve data locally using SharedPreferences:
// Save data locally
await FlutterProTools.saveLocalData(key: 'username', value: 'JohnDoe');
// Retrieve local data
String? username = await FlutterProTools.getLocalData(key: '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:
FlutterProTools.setPortraitDevice();
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": "موافق"
}
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"
}
You need it add this in each page you need to translate:
ref.watch(languageStatus);
Translates a key into the current locale's language
String translatedText = FlutterProTools.translate('hello');
To change app lang (supported only arabic and english):
var languageState = ref.watch(languageStatus);
languageState.changeLocale('ar');
Close page #
Closes the current modal or bar modal.
FlutterProTools.closePage();
Close keyboard #
Closes the keyboard if it is open.
FlutterProTools.closeKeyboard();
Get request #
Performs a GET HTTP request.
FlutterProTools.getRequest(
url: 'https://api.example.com/data',
data: { name: "name" }
authorization: 'Bearer token',
response: (http.Response response) {
print(response.body);
},
);
Send request #
Performs a POST HTTP request.
FlutterProTools.sendRequest(
url: 'https://api.example.com/data',
data: {name: "name example"},
authorization: 'Bearer token',
response: (http.Response response) {
print(response.body);
},
);
Delete request #
Performs a DELETE HTTP request.
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.
FlutterProTools.updateRequest(
url: 'https://api.example.com/data',
data: {name: "name example"},
authorization: 'Bearer token',
response: (http.Response response) {
print(response.body);
},
);
Show material model #
Shows a material bottom sheet modal.
FlutterProTools.showMaterialModel(MyModalPage());
Show alert dialog #
Shows an alert dialog.
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.
FlutterProTools.showErrorAlertDialog(() {
print('Retry action');
});
Save local data #
Saves a string to local storage.
FlutterProTools.saveLocalData(key: 'username', value: 'JohnDoe');
Save local data as integer #
Saves an integer to local storage
FlutterProTools.saveLocalDataAsInteger(key: 'userAge', value: 30);
Save local data as boolean #
Saves a boolean to local storage.
FlutterProTools.saveLocalDataAsBoolean(key: 'isLoggedIn', value: true);
Get local data #
Retrieves a string from local storage.
await FlutterProTools.getLocalData(key: 'username');
Remove local data #
Removes a key-value pair from local storage.
FlutterProTools.removeLocalData(key: 'username');
Get local data as boolean #
Retrieves a boolean from local storage.
await FlutterProTools.getLocalDataAsBoolean(key: 'isLoggedIn');
Get local data as integer #
Retrieves an integer from local storage.
await FlutterProTools.getLocalDataAsInteger(key: 'userAge');
Show notification #
Shows a notification with a title and body.
FlutterProTools.showNotification('Notification Title', 'This is the body of the notification.');
launchURL #
Navigate to external url
FlutterProTools.launchURL(String url, Function()? function);
Loading progress dialog #
Show loading dialog during request processing
FlutterProTools.showLoadingDialog();
Close loading dialog #
Close loading dialog when request ended
FlutterProTools.dismissLoadingDialog();
Log file #
To show log inside your app
FlutterProTools.logFile(message, name);
Get date formated #
get the date formated in form yyyy-MM-dd
FlutterProTools.getDate(date)
get random number #
get random number length :
FlutterProTools.getInteger(6);
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.