Forráskód Böngészése

Add an option to view logs

vishnukvmd 3 éve
szülő
commit
474c9cc41d
2 módosított fájl, 125 hozzáadás és 29 törlés
  1. 56 0
      lib/ui/log_file_viewer.dart
  2. 69 29
      lib/utils/email_util.dart

+ 56 - 0
lib/ui/log_file_viewer.dart

@@ -0,0 +1,56 @@
+import 'dart:io';
+import 'dart:ui';
+
+import 'package:flutter/material.dart';
+import 'package:photos/ui/loading_widget.dart';
+
+class LogFileViewer extends StatefulWidget {
+  final File file;
+  const LogFileViewer(this.file, {Key key}) : super(key: key);
+
+  @override
+  _LogFileViewerState createState() => _LogFileViewerState();
+}
+
+class _LogFileViewerState extends State<LogFileViewer> {
+  String _logs;
+  @override
+  void initState() {
+    widget.file.readAsString().then((logs) {
+      setState(() {
+        _logs = logs;
+      });
+    });
+    super.initState();
+  }
+
+  @override
+  Widget build(BuildContext context) {
+    return Scaffold(
+      appBar: AppBar(
+        title: Text("today's logs"),
+      ),
+      body: _getBody(),
+    );
+  }
+
+  Widget _getBody() {
+    if (_logs == null) {
+      return loadWidget;
+    }
+    return Container(
+      padding: EdgeInsets.only(left: 12, right: 12),
+      child: SingleChildScrollView(
+        child: Text(
+          _logs,
+          style: TextStyle(
+            fontFeatures: const [
+              FontFeature.tabularFigures(),
+            ],
+            color: Colors.white.withOpacity(0.7),
+          ),
+        ),
+      ),
+    );
+  }
+}

+ 69 - 29
lib/utils/email_util.dart

@@ -6,8 +6,11 @@ import 'package:flutter/material.dart';
 import 'package:flutter/widgets.dart';
 import 'package:flutter_email_sender/flutter_email_sender.dart';
 import 'package:path_provider/path_provider.dart';
+import 'package:photos/ui/log_file_viewer.dart';
 import 'package:photos/utils/dialog_util.dart';
+import 'package:photos/utils/navigation_util.dart';
 import 'package:share/share.dart';
+import 'package:super_logging/super_logging.dart';
 
 bool isValidEmail(String email) {
   return EmailValidator.validate(email);
@@ -21,46 +24,83 @@ Future<void> sendLogs(
   String subject,
   String body,
 }) async {
-  final confirmation = AlertDialog(
-    title: Text(
-      title,
-      style: TextStyle(
-        fontSize: 18,
-      ),
-    ),
-    content: SingleChildScrollView(
-      child: Column(
-        mainAxisSize: MainAxisSize.min,
-        children: const [
+  final List<Widget> actions = [
+    TextButton(
+      child: Row(
+        mainAxisAlignment: MainAxisAlignment.start,
+        children: [
+          Icon(
+            Icons.feed_outlined,
+            color: Colors.white.withOpacity(0.85),
+          ),
+          Padding(padding: EdgeInsets.all(4)),
           Text(
-            "this will send across metrics and logs that will help us debug your issue better",
+            "view logs",
             style: TextStyle(
-              height: 1.5,
-              fontFamily: 'Ubuntu',
-              fontSize: 16,
+              color: Colors.white.withOpacity(0.85),
             ),
           ),
         ],
       ),
+      onPressed: () async {
+        // routeToPage(context, LogFileViewer(SuperLogging.logFile));
+        showDialog(
+          context: context,
+          builder: (BuildContext context) {
+            return LogFileViewer(SuperLogging.logFile);
+          },
+          barrierColor: Colors.black87,
+          barrierDismissible: false,
+        );
+      },
     ),
-    actions: [
-      TextButton(
-        child: Text(
-          title,
-          style: TextStyle(
-            color: Theme.of(context).buttonColor,
-          ),
+    TextButton(
+      child: Text(
+        title,
+        style: TextStyle(
+          color: Theme.of(context).buttonColor,
+        ),
+      ),
+      onPressed: () async {
+        Navigator.of(context, rootNavigator: true).pop('dialog');
+        await _sendLogs(context, toEmail, subject, body);
+        if (postShare != null) {
+          postShare();
+        }
+      },
+    ),
+  ];
+  final List<Widget> content = [];
+  content.addAll(
+    [
+      Text(
+        "this will send across logs and metrics that will help us debug your issue better",
+        style: TextStyle(
+          height: 1.5,
+          fontFamily: 'Ubuntu',
+          fontSize: 16,
         ),
-        onPressed: () async {
-          Navigator.of(context).pop();
-          await _sendLogs(context, toEmail, subject, body);
-          if (postShare != null) {
-            postShare();
-          }
-        },
+      ),
+      Padding(padding: EdgeInsets.all(12)),
+      Row(
+        mainAxisAlignment: MainAxisAlignment.spaceBetween,
+        children: actions,
       ),
     ],
   );
+  final confirmation = AlertDialog(
+    title: Text(
+      title,
+      style: TextStyle(
+        fontSize: 18,
+      ),
+    ),
+    content: SingleChildScrollView(
+      child: ListBody(
+        children: content,
+      ),
+    ),
+  );
   showDialog(
     context: context,
     builder: (_) {