From 0504f2336c135682ffc8d02d744fcae04d1f5cde Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Wed, 2 Nov 2022 20:07:27 -0600 Subject: [PATCH] debug popup --- .../advanced_settings/advanced_settings.dart | 25 +- .../advanced_settings/debug_info_dialog.dart | 308 +++++++++++++----- 2 files changed, 245 insertions(+), 88 deletions(-) diff --git a/lib/pages_desktop_specific/home/settings_menu/advanced_settings/advanced_settings.dart b/lib/pages_desktop_specific/home/settings_menu/advanced_settings/advanced_settings.dart index 1632576fd..8e89e3f67 100644 --- a/lib/pages_desktop_specific/home/settings_menu/advanced_settings/advanced_settings.dart +++ b/lib/pages_desktop_specific/home/settings_menu/advanced_settings/advanced_settings.dart @@ -10,6 +10,8 @@ import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/widgets/custom_buttons/draggable_switch_button.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart'; +import 'debug_info_dialog.dart'; + class AdvancedSettings extends ConsumerStatefulWidget { const AdvancedSettings({Key? key}) : super(key: key); @@ -226,16 +228,16 @@ class ShowLogsButton extends ConsumerWidget { }) : super(key: key); @override Widget build(BuildContext context, WidgetRef ref) { - // Future viewDebugLogs() async { - // await showDialog( - // context: context, - // useSafeArea: false, - // barrierDismissible: true, - // builder: (context) { - // return const DebugInfoDialog(); - // }, - // ); - // } + Future viewDebugLogs() async { + await showDialog( + context: context, + useSafeArea: false, + barrierDismissible: true, + builder: (context) { + return const DebugInfoDialog(); + }, + ); + } return SizedBox( width: 101, @@ -245,8 +247,7 @@ class ShowLogsButton extends ConsumerWidget { .extension()! .getPrimaryEnabledButtonColor(context), onPressed: () { - // - // viewDebugLogs(); + viewDebugLogs(); }, child: Text( "Show logs", diff --git a/lib/pages_desktop_specific/home/settings_menu/advanced_settings/debug_info_dialog.dart b/lib/pages_desktop_specific/home/settings_menu/advanced_settings/debug_info_dialog.dart index 342d9180a..0406a059f 100644 --- a/lib/pages_desktop_specific/home/settings_menu/advanced_settings/debug_info_dialog.dart +++ b/lib/pages_desktop_specific/home/settings_menu/advanced_settings/debug_info_dialog.dart @@ -1,29 +1,33 @@ import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; import 'package:stackwallet/models/isar/models/log.dart'; +import 'package:stackwallet/providers/global/debug_service_provider.dart'; +import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; +import 'package:stackwallet/utilities/enums/log_level_enum.dart'; import 'package:stackwallet/utilities/text_styles.dart'; +import 'package:stackwallet/utilities/theme/stack_colors.dart'; +import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/widgets/desktop/desktop_dialog.dart'; import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart'; import 'package:stackwallet/widgets/desktop/primary_button.dart'; import 'package:stackwallet/widgets/desktop/secondary_button.dart'; +import 'package:stackwallet/widgets/icon_widgets/x_icon.dart'; +import 'package:stackwallet/widgets/rounded_container.dart'; +import 'package:stackwallet/widgets/stack_text_field.dart'; +import 'package:stackwallet/widgets/textfield_icon_button.dart'; -// import '../../../utilities/assets.dart'; -// import '../../../utilities/util.dart'; -// import '../../../widgets/icon_widgets/x_icon.dart'; -// import '../../../widgets/stack_text_field.dart'; -// import '../../../widgets/textfield_icon_button.dart'; - -class DebugInfoDialog extends StatefulWidget { +class DebugInfoDialog extends ConsumerStatefulWidget { const DebugInfoDialog({Key? key}) : super(key: key); @override - State createState() => _DebugInfoDialog(); + ConsumerState createState() => _DebugInfoDialog(); } -class _DebugInfoDialog extends State { - final _searchController = TextEditingController(); - final _searchFocusNode = FocusNode(); +class _DebugInfoDialog extends ConsumerState { + late final TextEditingController searchDebugController; + late final FocusNode searchDebugFocusNode; final scrollController = ScrollController(); @@ -62,15 +66,19 @@ class _DebugInfoDialog extends State { @override void initState() { - // ref.read(debugServiceProvider).updateRecentLogs(); + searchDebugController = TextEditingController(); + searchDebugFocusNode = FocusNode(); + + ref.read(debugServiceProvider).updateRecentLogs(); super.initState(); } @override void dispose() { - _searchController.dispose(); + searchDebugFocusNode.dispose(); + searchDebugController.dispose(); + scrollController.dispose(); - _searchFocusNode.dispose(); super.dispose(); } @@ -78,7 +86,7 @@ class _DebugInfoDialog extends State { @override Widget build(BuildContext context) { return DesktopDialog( - maxHeight: 800, + maxHeight: 850, maxWidth: 600, child: Column( children: [ @@ -96,68 +104,216 @@ class _DebugInfoDialog extends State { const DesktopDialogCloseButton(), ], ), - Row( - children: [ - // ClipRRect( - // borderRadius: BorderRadius.circular( - // Constants.size.circularBorderRadius, - // ), - // child: TextField( - // key: const Key("desktopSettingDebugInfo"), - // autocorrect: Util.isDesktop ? false : true, - // enableSuggestions: Util.isDesktop ? false : true, - // controller: _searchController, - // focusNode: _searchFocusNode, - // // onChanged: (newString) { - // // setState(() => _searchTerm = newString); - // // }, - // style: STextStyles.field(context), - // decoration: standardInputDecoration( - // "Search", - // _searchFocusNode, - // context, - // ).copyWith( - // prefixIcon: Padding( - // padding: const EdgeInsets.symmetric( - // horizontal: 10, - // vertical: 16, - // ), - // child: SvgPicture.asset( - // Assets.svg.search, - // width: 16, - // height: 16, - // ), - // ), - // suffixIcon: _searchController.text.isNotEmpty - // ? Padding( - // padding: const EdgeInsets.only(right: 0), - // child: UnconstrainedBox( - // child: Row( - // children: [ - // TextFieldIconButton( - // child: const XIcon(), - // onTap: () async { - // setState(() { - // _searchController.text = ""; - // _searchTerm = ""; - // }); - // }, - // ), - // ], - // ), - // ), - // ) - // : null, - // ), - // ), - // ), - ], + Expanded( + flex: 24, + child: NestedScrollView( + floatHeaderSlivers: true, + headerSliverBuilder: (context, innerBoxIsScrolled) { + return [ + SliverOverlapAbsorber( + handle: NestedScrollView.sliverOverlapAbsorberHandleFor( + context), + sliver: SliverToBoxAdapter( + child: Padding( + padding: const EdgeInsets.symmetric( + vertical: 16, horizontal: 32), + child: Column( + children: [ + Padding( + padding: const EdgeInsets.only(bottom: 16), + child: ClipRRect( + borderRadius: BorderRadius.circular( + Constants.size.circularBorderRadius, + ), + child: TextField( + autocorrect: Util.isDesktop ? false : true, + enableSuggestions: + Util.isDesktop ? false : true, + controller: searchDebugController, + focusNode: searchDebugFocusNode, + onChanged: (newString) { + setState(() => _searchTerm = newString); + }, + style: STextStyles.field(context), + decoration: standardInputDecoration( + "Search", + searchDebugFocusNode, + context, + ).copyWith( + prefixIcon: Padding( + padding: const EdgeInsets.symmetric( + horizontal: 10, + vertical: 16, + ), + child: SvgPicture.asset( + Assets.svg.search, + width: 16, + height: 16, + ), + ), + suffixIcon: searchDebugController + .text.isNotEmpty + ? Padding( + padding: + const EdgeInsets.only(right: 0), + child: UnconstrainedBox( + child: Row( + children: [ + TextFieldIconButton( + child: const XIcon(), + onTap: () async { + setState(() { + searchDebugController + .text = ""; + _searchTerm = ""; + }); + }, + ), + ], + ), + ), + ) + : null, + ), + ), + ), + ), + const SizedBox( + height: 12, + ), + ], + ), + ), + ), + ), + ]; + }, + body: Builder( + builder: (context) { + final logs = filtered( + ref.watch(debugServiceProvider + .select((value) => value.recentLogs)), + _searchTerm) + .reversed + .toList(growable: false); + return CustomScrollView( + reverse: true, + // shrinkWrap: true, + controller: scrollController, + slivers: [ + SliverOverlapInjector( + handle: NestedScrollView.sliverOverlapAbsorberHandleFor( + context, + ), + ), + SliverList( + delegate: SliverChildBuilderDelegate( + (context, index) { + final log = logs[index]; + + return Container( + key: Key( + "log_${log.id}_${log.timestampInMillisUTC}"), + decoration: BoxDecoration( + color: Theme.of(context) + .extension()! + .popupBG, + borderRadius: _borderRadius(index, logs.length), + ), + child: Padding( + padding: const EdgeInsets.all(4), + child: Padding( + padding: const EdgeInsets.symmetric( + horizontal: 32), + child: RoundedContainer( + padding: const EdgeInsets.all(0), + color: Theme.of(context) + .extension()! + .popupBG, + child: Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Row( + children: [ + Text( + " [${log.logLevel.name}]", + style: STextStyles.baseXS(context) + .copyWith( + fontSize: 8, + color: (log.logLevel == + LogLevel.Info + ? Theme.of(context) + .extension< + StackColors>()! + .topNavIconGreen + : (log.logLevel == + LogLevel.Warning + ? Theme.of(context) + .extension< + StackColors>()! + .topNavIconYellow + : (log.logLevel == + LogLevel.Error + ? Colors.orange + : Theme.of(context) + .extension< + StackColors>()! + .topNavIconRed))), + ), + ), + Text( + "[${DateTime.fromMillisecondsSinceEpoch(log.timestampInMillisUTC, isUtc: true)}]: ", + style: STextStyles.baseXS(context) + .copyWith( + fontSize: 12, + color: Theme.of(context) + .extension()! + .textDark3, + ), + ), + ], + ), + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + const SizedBox( + width: 20, + ), + Flexible( + child: Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + SelectableText( + log.message, + style: STextStyles.baseXS( + context) + .copyWith( + fontSize: 11.5), + ), + ], + ), + ), + ], + ), + ], + ), + ), + ), + ), + ); + }, + childCount: logs.length, + ), + ), + ], + ); + }, + ), + ), ), - // Column( - // children: [ - // - // ], - // ), const Spacer(), Padding( padding: const EdgeInsets.all(32),