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.