Skip to content
Open
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
24 changes: 19 additions & 5 deletions android/src/main/java/dev/pharsh/logcat/LogcatPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,30 @@
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import io.flutter.embedding.engine.plugins.FlutterPlugin;

/**
* LogcatPlugin
*/
public class LogcatPlugin implements MethodCallHandler {
public class LogcatPlugin implements FlutterPlugin, MethodCallHandler {
private static final String CHANNEL_NAME = "app.channel.logcat";
private MethodChannel channel;

public LogcatPlugin() {
}

/**
* Plugin registration.
*/
public static void registerWith(Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), "app.channel.logcat");
channel.setMethodCallHandler(new LogcatPlugin());
@Override
public void onAttachedToEngine(FlutterPluginBinding flutterPluginBinding) {
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), CHANNEL_NAME);
channel.setMethodCallHandler(this);
}

@Override
public void onDetachedFromEngine(FlutterPluginBinding flutterPluginBinding) {
channel.setMethodCallHandler(null);
}

@Override
Expand All @@ -45,10 +57,12 @@ String getLogs() {
String line;
while ((line = bufferedReader.readLine()) != null) {
log.append(line);
log.append('\n');
}
return log.toString();
} catch (IOException e) {
return "EXCEPTION" + e.toString();
}
}

}
8 changes: 5 additions & 3 deletions example/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:logcat_example/main.dart';
import '../lib/main.dart';

void main() {
testWidgets('Verify Platform version', (WidgetTester tester) async {
Expand All @@ -18,8 +18,10 @@ void main() {
// Verify that platform version is retrieved.
expect(
find.byWidgetPredicate(
(Widget widget) => widget is Text &&
widget.data.startsWith('Running on:'),
(Widget widget) =>
widget is Text &&
widget.data != null &&
widget.data!.startsWith('Running on:'),
),
findsOneWidget,
);
Expand Down
5 changes: 4 additions & 1 deletion lib/logcat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class Logcat {
/// [MethodChannel] used to communicate with the platform side.
static const platform = const MethodChannel('app.channel.logcat');

static Future<String> get platformVersion async =>
await platform.invokeMethod('getPlatformVersion') ?? '42';

/// Fetches the app logs by executing the logcat command-line tool.
/// May throw [PlatformException] from [MethodChannel].
static Future<String> execute() async {
Expand All @@ -20,7 +23,7 @@ class Logcat {
}
String logs;
try {
logs = await platform.invokeMethod('execLogcat');
logs = await platform.invokeMethod('execLogcat') ?? "";
} on PlatformException catch (e) {
logs = "Failed to get logs: '${e.message}'.";
}
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: logcat
description: Flutter plugin to get the system messages, stack traces etc using logcat command-line tool.
version: 1.0.2
version: 2.0.0
author: Harsh <pharsh.dev@gmail.com>
homepage: https://github.com/pharshdev/logcat

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: ">=2.12.0 <3.0.0"

dependencies:
flutter:
Expand Down