my_print Flutter Package

my_print Flutter Package

SAY NO TO USE PRINT('data')

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

No alt text provided for this image
Example Image of myPrint function

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.

Hashir Shoaib

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.

Muhammad Umair Bin Sajid

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?

要查看或添加评论,请登录

Muhammad Atif Waheed的更多文章

  • Flutter 3.7 - What's New In Flutter

    Flutter 3.7 - What's New In Flutter

    Flutter released its new edition i.e.

  • State Management in Flutter with Difference

    State Management in Flutter with Difference

    Flutter State Management. Author: FluXpert Flutter is a popular mobile application development framework created by…

    1 条评论
  • ChatGPT: Mind-Blowing AI (OpenAI)

    ChatGPT: Mind-Blowing AI (OpenAI)

    ChatGPT is a state-of-the-art language generation model developed by OpenAI. The model is based on the transformer…

  • Flutter 3.3.10 - What's New In Flutter

    Flutter 3.3.10 - What's New In Flutter

    Flutter is an open-source mobile application development framework created by Google. It allows developers to build…

社区洞察

其他会员也浏览了