mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-05-14 05:52:51 +00:00
Copy logs clipboard new function
This commit is contained in:
parent
58d6da2d9e
commit
f06c1fcafa
3 changed files with 8 additions and 17 deletions
|
@ -5,7 +5,7 @@ import 'package:provider/provider.dart';
|
|||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
import 'package:adguard_home_manager/widgets/custom_list_tile.dart';
|
||||
import 'package:adguard_home_manager/screens/app_logs/app_logs.dart';
|
||||
import 'package:adguard_home_manager/screens/settings/app_logs/app_logs.dart';
|
||||
|
||||
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
||||
|
||||
|
|
194
lib/screens/settings/app_logs/app_log_details_modal.dart
Normal file
194
lib/screens/settings/app_logs/app_log_details_modal.dart
Normal file
|
@ -0,0 +1,194 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
import 'package:adguard_home_manager/models/app_log.dart';
|
||||
|
||||
class AppLogDetailsModal extends StatefulWidget {
|
||||
final AppLog log;
|
||||
|
||||
const AppLogDetailsModal({
|
||||
Key? key,
|
||||
required this.log
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<AppLogDetailsModal> createState() => _AppLogDetailsModalState();
|
||||
}
|
||||
|
||||
class _AppLogDetailsModalState extends State<AppLogDetailsModal> {
|
||||
String valueToShow = 'message';
|
||||
|
||||
String generateBody() {
|
||||
switch (valueToShow) {
|
||||
case 'message':
|
||||
return widget.log.message;
|
||||
|
||||
case 'statusCode':
|
||||
return widget.log.statusCode != null
|
||||
? widget.log.statusCode.toString()
|
||||
: "[NO STAUS CODE]";
|
||||
|
||||
case 'body':
|
||||
return widget.log.resBody != null
|
||||
? widget.log.resBody.toString()
|
||||
: "[NO RESPONSE BODY]";
|
||||
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Column(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.description_rounded,
|
||||
size: 24,
|
||||
color: Theme.of(context).listTileTheme.iconColor,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
AppLocalizations.of(context)!.logDetails,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
color: Theme.of(context).colorScheme.onSurface
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
scrollable: true,
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const SizedBox(height: 20),
|
||||
Row(
|
||||
children: [
|
||||
Material(
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(15),
|
||||
bottomLeft: Radius.circular(15)
|
||||
),
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(15),
|
||||
bottomLeft: Radius.circular(15)
|
||||
),
|
||||
onTap: () => setState(() => valueToShow = 'message'),
|
||||
child: AnimatedContainer(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
|
||||
duration: const Duration(milliseconds: 200),
|
||||
curve: Curves.easeInOut,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(15),
|
||||
bottomLeft: Radius.circular(15)
|
||||
),
|
||||
border: Border.all(
|
||||
color: Theme.of(context).primaryColor
|
||||
),
|
||||
color: valueToShow == 'message'
|
||||
? Theme.of(context).primaryColor
|
||||
: Theme.of(context).primaryColor.withOpacity(0.05)
|
||||
),
|
||||
child: Text(
|
||||
"Message",
|
||||
style: TextStyle(
|
||||
color: valueToShow == 'message'
|
||||
? Colors.white
|
||||
: null
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () => setState(() => valueToShow = 'statusCode'),
|
||||
child: AnimatedContainer(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
|
||||
duration: const Duration(milliseconds: 200),
|
||||
curve: Curves.easeInOut,
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
top: BorderSide(
|
||||
color: Theme.of(context).primaryColor
|
||||
),
|
||||
bottom: BorderSide(
|
||||
color: Theme.of(context).primaryColor
|
||||
),
|
||||
),
|
||||
color: valueToShow == 'statusCode'
|
||||
? Theme.of(context).primaryColor
|
||||
: Theme.of(context).primaryColor.withOpacity(0.05)
|
||||
),
|
||||
child: Text(
|
||||
"Status code",
|
||||
style: TextStyle(
|
||||
color: valueToShow == 'statusCode'
|
||||
? Colors.white
|
||||
: null
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Material(
|
||||
borderRadius: const BorderRadius.only(
|
||||
topRight: Radius.circular(15),
|
||||
bottomRight: Radius.circular(15)
|
||||
),
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
borderRadius: const BorderRadius.only(
|
||||
topRight: Radius.circular(15),
|
||||
bottomRight: Radius.circular(15)
|
||||
),
|
||||
onTap: () => setState(() => valueToShow = 'body'),
|
||||
child: AnimatedContainer(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
|
||||
duration: const Duration(milliseconds: 200),
|
||||
curve: Curves.easeInOut,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: const BorderRadius.only(
|
||||
topRight: Radius.circular(15),
|
||||
bottomRight: Radius.circular(15)
|
||||
),
|
||||
border: Border.all(
|
||||
color: Theme.of(context).primaryColor
|
||||
),
|
||||
color: valueToShow == 'body'
|
||||
? Theme.of(context).primaryColor
|
||||
: Theme.of(context).primaryColor.withOpacity(0.05)
|
||||
),
|
||||
child: Text(
|
||||
"Body",
|
||||
style: TextStyle(
|
||||
color: valueToShow == 'body'
|
||||
? Colors.white
|
||||
: null
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Text(generateBody())
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text("Close")
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
82
lib/screens/settings/app_logs/app_logs.dart
Normal file
82
lib/screens/settings/app_logs/app_logs.dart
Normal file
|
@ -0,0 +1,82 @@
|
|||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:adguard_home_manager/functions/copy_clipboard.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
import 'package:adguard_home_manager/screens/settings/app_logs/app_log_details_modal.dart';
|
||||
|
||||
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
||||
|
||||
class AppLogs extends StatelessWidget {
|
||||
const AppLogs({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final appConfigProvider = Provider.of<AppConfigProvider>(context);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(AppLocalizations.of(context)!.logs),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: appConfigProvider.logs.isNotEmpty
|
||||
? () => copyToClipboard(
|
||||
context: context,
|
||||
value: jsonEncode(appConfigProvider.logs.map((log) => log.toMap()).toList()),
|
||||
successMessage: AppLocalizations.of(context)!.logsCopiedClipboard
|
||||
)
|
||||
: null,
|
||||
icon: const Icon(Icons.share),
|
||||
tooltip: AppLocalizations.of(context)!.copyLogsClipboard,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
],
|
||||
),
|
||||
body: appConfigProvider.logs.isNotEmpty
|
||||
? ListView.builder(
|
||||
padding: const EdgeInsets.only(top: 0),
|
||||
itemCount: appConfigProvider.logs.length,
|
||||
itemBuilder: (context, index) => ListTile(
|
||||
title: Text(
|
||||
appConfigProvider.logs[index].message,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.normal,
|
||||
color: Theme.of(context).colorScheme.onSurface
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
appConfigProvider.logs[index].dateTime.toString(),
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.normal,
|
||||
color: Theme.of(context).listTileTheme.textColor
|
||||
),
|
||||
),
|
||||
trailing: Text(appConfigProvider.logs[index].type),
|
||||
onTap: () => {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AppLogDetailsModal(
|
||||
log: appConfigProvider.logs[index]
|
||||
)
|
||||
)
|
||||
},
|
||||
)
|
||||
)
|
||||
: Center(
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.noSavedLogs,
|
||||
style: const TextStyle(
|
||||
fontSize: 24,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue