Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/talker_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 5.1.17
- [talker_flutter] chore: bump share_plus from ^12.0.1 to ^13.0.0
- [talker_flutter] fix: remove share_plus dependency to avoid Flutter KGP warning from transitive Android plugin setup

Thanks to [PAzter1101](https://github.com/PAzter1101)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class TalkerViewController extends ChangeNotifier {

bool _expandedLogs;
bool _isLogOrderReversed;
String? _lastSavedLogsFileLocation;

/// Filter for selecting specific logs and errors
TalkerFilter get filter => _uiFilter;
Expand Down Expand Up @@ -63,7 +64,11 @@ class TalkerViewController extends ChangeNotifier {
notifyListeners();
}

Future<void> downloadLogsFile(String logs) async => await downloadFile(logs);
String? get lastSavedLogsFileLocation => _lastSavedLogsFileLocation;

Future<void> downloadLogsFile(String logs) async {
_lastSavedLogsFileLocation = await downloadFile(logs, DateTime.now());
}

/// Redefinition [notifyListeners]
void update() => notifyListeners();
Expand Down
30 changes: 23 additions & 7 deletions packages/talker_flutter/lib/src/ui/talker_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ class _TalkerViewState extends State<TalkerView> {
icon: Icons.delete_outline,
),
TalkerActionItem(
onTap: _shareLogsInFile,
title: 'Share logs file',
icon: Icons.ios_share_outlined,
onTap: _saveLogsToFile,
title: 'Save logs locally',
icon: Icons.save_alt_outlined,
),
],
talkerScreenTheme: widget.theme,
Expand All @@ -233,10 +233,26 @@ class _TalkerViewState extends State<TalkerView> {
);
}

Future<void> _shareLogsInFile() async {
await _controller.downloadLogsFile(
widget.talker.history.text(timeFormat: widget.talker.settings.timeFormat),
);
Future<void> _saveLogsToFile() async {
try {
await _controller.downloadLogsFile(
widget.talker.history.text(
timeFormat: widget.talker.settings.timeFormat,
),
);
if (!mounted) return;
final fileLocation = _controller.lastSavedLogsFileLocation;
_showSnackBar(
context,
fileLocation == null
? 'Logs file saved to temporary directory'
: 'Logs file saved: $fileLocation',
);
} catch (error, stackTrace) {
widget.talker.handle(error, stackTrace);
if (!mounted) return;
_showSnackBar(context, 'Failed to save logs file');
}
}

void _cleanHistory() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import 'dart:io';

import 'package:path_provider/path_provider.dart';
import 'package:share_plus/share_plus.dart';

Future<void> downloadFile(String logs) async {
final dir = await getTemporaryDirectory();
final dirPath = dir.path;
final fmtDate = DateTime.now().toString().replaceAll(":", " ");
final file =
await File('$dirPath/talker_logs_$fmtDate.txt').create(recursive: true);
await file.writeAsString(logs);
await SharePlus.instance.share(
ShareParams(files: <XFile>[XFile(file.path)]),
/// Saves logs to a temporary file in the system temp directory.
///
/// May throw [FileSystemException] while creating or writing the file.
Future<String> downloadFile(String logs, DateTime timestamp) async {
final dirPath = Directory.systemTemp.path;
final formattedDate = timestamp.toIso8601String().replaceAll(':', '-');
final file = await File('$dirPath/talker_logs_$formattedDate.txt').create(
recursive: true,
);
await file.writeAsString(logs);
return file.path;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ import 'dart:js_interop';

import 'package:web/web.dart';

Future<void> downloadFile(String logs) async {
Future<String> downloadFile(String logs, DateTime timestamp) async {
final jsArray = [logs.toJS].toJS;
final blob = Blob(jsArray, BlobPropertyBag(type: 'text/plain'));

final fmtDate = DateTime.now().toString().replaceAll(':', ' ');
final formattedDate = timestamp.toIso8601String().replaceAll(':', '-');
final fileName = 'talker_logs_$formattedDate.txt';

final anchor = HTMLAnchorElement()
..href = URL.createObjectURL(blob)
..download = 'talker_logs_$fmtDate.txt'
..download = fileName
..click()
..remove();

URL.revokeObjectURL(anchor.href);
return fileName;
}
2 changes: 0 additions & 2 deletions packages/talker_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ dependencies:

talker: ^5.1.17
group_button: ^5.3.4
path_provider: ^2.1.4
share_plus: ^13.0.0
web: ^1.1.0


Expand Down