Skip to content

Commit

Permalink
Merge pull request #566 from bannzai/add/function/debug_print
Browse files Browse the repository at this point in the history
Add debug print function
  • Loading branch information
bannzai authored Apr 17, 2022
2 parents 0e9d1cf + 262e54f commit 98dcddf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/entrypoint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import 'dart:io';

import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:pilll/analytics.dart';
import 'package:pilll/components/atoms/color.dart';
import 'package:pilll/components/atoms/font.dart';
import 'package:pilll/domain/root/root.dart';
import 'package:pilll/error/universal_error_page.dart';
import 'package:pilll/native/channel.dart';
import 'package:pilll/util/datetime/debug_print.dart';
import 'package:pilll/util/environment.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
Expand All @@ -21,6 +23,9 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
Future<void> entrypoint() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
if (kDebugMode) {
overrideDebugPrint();
}

if (Environment.isLocal) {
connectToEmulator();
Expand Down
18 changes: 18 additions & 0 deletions lib/util/datetime/debug_print.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:flutter/foundation.dart';

void overrideDebugPrint() {
debugPrint = printWrapped;
}

void printWrapped(String? _message, {int? wrapWidth}) {
final message = _message;

if (kDebugMode) {
if (message == null) {
print("null");
} else {
final pattern = RegExp('.{1,800}'); // 800 is the size of each chunk
pattern.allMatches(message).forEach((match) => print(match.group(0)));
}
}
}

0 comments on commit 98dcddf

Please sign in to comment.