1

I would like to show the user the messages that appear for us developers, to be more specific I would like to show the user what appears to us in the terminal in the debugConsole tab, I would like to show the user the messages that appear there. example this information from the debug console in real time for the user

i try some packages but none got successed

Ramji
  • 904
  • 2
  • 5
  • 20

1 Answers1

0

I don't think this is possible for all kinds of logs that are triggered from different platforms inside a flutter app when it's released, there are many reasons such as when the log() from the dart:developer shows a statement in the console log only in the debug mode, not the release mode.

However, you can make it happen for your project's print(), debugPrint() by combining these methods with a StreamController, Stream like this :

1. First we create a StreamController:

StreamController streamController = StreamController<String>();

2. make new methods for print, debugPrint methods that notify that streamController every time:

   void customPrint(Object? object) {
     streamController.add(object.toString());
     print(object);
    }

3. listening to the Stream of StreamController to show the messages in the app, as an example :

   StreamBuilder<List<String>>(
        stream: streamController.stream, // the stream of the controller
        builder: (context, snapshot) {
          if (snapshot.hasData) {
            return ListView.builder(
                itemCount: snapshot.data.length,
                itemBuilder: (context, index) {
                  return ListTile(
                    title: Text(snapshot.data[index]),
                  );
                });
          } else {
            return Container();
          }
        }
      ), 

now you can change all your print() calls with the customPrint(), and every time it's called, it will be printed in the console log, and also be shown in the UI of the Flutter app.

Gwhyyy
  • 7,554
  • 3
  • 8
  • 35