log_file_viewer.dart 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import 'dart:io';
  2. import 'dart:ui';
  3. import 'package:flutter/material.dart';
  4. import 'package:photos/ui/common/loading_widget.dart';
  5. class LogFileViewer extends StatefulWidget {
  6. final File file;
  7. const LogFileViewer(this.file, {Key? key}) : super(key: key);
  8. @override
  9. State<LogFileViewer> createState() => _LogFileViewerState();
  10. }
  11. class _LogFileViewerState extends State<LogFileViewer> {
  12. String? _logs;
  13. @override
  14. void initState() {
  15. widget.file.readAsString().then((logs) {
  16. setState(() {
  17. _logs = logs;
  18. });
  19. });
  20. super.initState();
  21. }
  22. @override
  23. Widget build(BuildContext context) {
  24. return Scaffold(
  25. appBar: AppBar(
  26. elevation: 0,
  27. title: const Text("Today's logs"),
  28. ),
  29. body: _getBody(),
  30. );
  31. }
  32. Widget _getBody() {
  33. if (_logs == null) {
  34. return const EnteLoadingWidget();
  35. }
  36. return Container(
  37. padding: const EdgeInsets.only(left: 12, top: 8, right: 12),
  38. child: SingleChildScrollView(
  39. child: Text(
  40. _logs!,
  41. style: const TextStyle(
  42. fontFeatures: [
  43. FontFeature.tabularFigures(),
  44. ],
  45. height: 1.2,
  46. ),
  47. ),
  48. ),
  49. );
  50. }
  51. }