my_print Flutter Package
Muhammad Atif Waheed
3+ Years of Experience in Flutter | Kotlin | Java | SDK Integrations | Firebase | ASO | MVC | Restful APIs | VCS | CI/CD Integration
my_print is the one of the best way to print anything in console while running the flutter application. Most of people uses print() which is not a good approach because it prints even if the app is in production mode which is really harmful for leakage of data.
From now onward, use my_print package available on pub.dev (https://pub.dev/) because it helps you in securing the production app. It will only print when app is running in debug Mode.
PACKAGE LINK: https://pub.dev/packages/my_print
ScreenShot
USAGE:
Add Package:
flutter pub add my_print
Or
dependencies:
? my_print: ^0.1.1
2. Import package:
import 'package:my_print/my_print.dart';
领英推荐
3. Use anywhere:
myPrint(
? screen: "YourScreen",
? data: "Container Button Pressed",
? type: "Tap Check",
);
Explanation of Parameters:
Use myPrint() function to print anything in the console.
screen: String type in which there would be Screen Name in which you are using myPrint function. Like, if you are in home screen then use "HomeScreen" and if you're in login screen then use "LoginScreen"
data: String type in which there would be your data variable which you were using in print(). Like, if you want to display logged in user then use it in String "${FirebaseAuth.instance.currentUser.uid}".
type: (Optional) String type in which there would be type of print. Like, if it is login button or something else. For Example, I'm on Edit Profile Screen and pressed upload image button then I will use type as "Image Upload Button".
Example:
import 'package:flutter/material.dart';
import 'package:my_print/my_print.dart';
class HomeScreenContainer extends StatelessWidget {
? const HomeScreenContainer({Key? key}) : super(key: key);
? @override
? Widget build(BuildContext context) {
? ? return Container(
? ? ? width: 200,
? ? ? ? height: 200,
? ? ? ? color: Colors.red,
? ? ? ? child: InkWell(
? ? ? ? ? onTap: (){
? ? ? ? ? ? myPrint(
? ? ? ? ? ? ? screen: "HomeScreenContainer",
? ? ? ? ? ? ? data: "Container Button Pressed",
? ? ? ? ? ? ? type: "Tap Check",
? ? ? ? ? ? );
? ? ? ? ? },
? ? ? ? ? child: Container(
? ? ? ? ? ? height: 30,
? ? ? ? ? ? width: 30,
? ? ? ? ? ? color: Colors.red,
? ? ? ? ? ),
? ? ? ? ),
? ? );
? }
}
Output:
[ DEBUG PRINT ] [ HomeScreenContainer ] [ Tap Check ] Container Button
CONCLUSION
In conclusion, it is important to be mindful of how we print data in console while running a Flutter application. The commonly used print() function can be risky as it prints even in production mode, potentially compromising sensitive information. The my_print package available on pub.dev provides a better alternative as it only prints when the app is running in debug mode, making it a more secure option. By using the myPrint() function and providing the screen, data, and optional type parameters, we can print the necessary information to the console in a more controlled and safe manner. Adopting this approach can help enhance the security of our Flutter applications and prevent the potential leakage of sensitive data.
Helping businesses turning ideas into powerful mobile apps that drive results
2 年Firstly, let me express my gratitude for the effort you've put into this package. However, I was wondering if there are any plans to improve it in the future, as adding a dependency of 7 lines of code might not be the most optimal solution.
Software Engineer | Flutter Developer
2 年I really appreciate your efforts. Great and keep it up ???? But, What about log("message") from "dart: developer" which is available by default?