Skip to content

talker_flutter: Expose shareLogsInFile #521

Description

@chdanielmueller

Is your feature request related to a problem? Please describe.
I would like to give my users a share ability for Logs without showing the logs to them.

Describe the solution you'd like
I would like to use the "Share" Feature of talker_flutter as a standalone function exported by talker_flutter.

Describe alternatives you've considered
Copying the code from the talker_view.dart all the way to the download utility.
This works but a convenience function would be great.

Additional context

Future<void> _shareLogsInFile() async {
await _controller.downloadLogsFile(
widget.talker.history.text(timeFormat: widget.talker.settings.timeFormat),
);
}

Future<void> downloadLogsFile(String logs) async => await downloadFile(logs);

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)]),
);
}

Sidenote:
donwload_logs.dart has a typo

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions