Я хочу написать некоторый нативный код для принтера во флаттере, поэтому я написал некоторый код для связи между флаттером и android, но у меня возникает проблема, когда я пытаюсь создать еще один java-класс xml в папке android.Объясните мне, как создать новый XML-файл Java-класса в папке android флаттера.
флаттер:
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class ExamplemyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Sample Shared App Handler',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: SampleAppPage(),
);
}
}
class SampleAppPage extends StatefulWidget {
SampleAppPage({Key key}) : super(key: key);
@override
_SampleAppPageState createState() => _SampleAppPageState();
}
class _SampleAppPageState extends State<SampleAppPage> {
static const platform = const MethodChannel('app.channel.shared.data');
String dataShared = "Restos printer working";
@override
void initState() {
super.initState();
getSharedText();
}
@override
Widget build(BuildContext context) {
return Scaffold(body: Center(child: Text(dataShared)));
}
getSharedText() async {
var sharedData = await platform.invokeMethod("getSharedText");
if (sharedData != null) {
setState(() {
dataShared = sharedData;
});
}
}
}
ANDROID:
import android.os.Bundle;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import android.content.Intent;
import android.os.Bundle;
import java.nio.ByteBuffer;
import io.flutter.app.FlutterActivity;
import io.flutter.plugin.common.ActivityLifecycleListener;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
private String sharedText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type)) {
handleSendText(intent); // Handle text being sent
}
}
new MethodChannel(getFlutterView(), "app.channel.shared.data").setMethodCallHandler(
new MethodCallHandler() {
@Override
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
if (call.method.contentEquals("getSharedText")) {
result.success(sharedText);
sharedText = null;
}
}
});
}
void handleSendText(Intent intent) {
sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
}
}
Теперь я хочу выйти из основной активности.java другому активу для печати
, если я пытаюсь написать новый jav и получаю эту ошибку;
Unhandled exception:
FileSystemException: Cannot open file, path = 'build\app.dill.track.dill' (OS Error: The system cannot find the path specified.
, errno = 3)
#0 _File.open.<anonymous closure> (dart:io/file_impl.dart:368:9)
#1 _RootZone.runUnary (dart:async/zone.dart:1379:54)
#2 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#3 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:642:45)
#4 Future._propagateToListeners (dart:async/future_impl.dart:671:32)
#5 Future._completeWithValue (dart:async/future_impl.dart:486:5)
#6 Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:516:7)
#7 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#8 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#9 _runPendingImmediateCallback (dart:isolate/runtime/libisolate_patch.dart:115:13)
#10 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:172:5)
Unhandled exception:
SocketException: Write failed (OS Error: The pipe is being closed.
, errno = 232), port = 0
#0 _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:1112:29)
#1 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#2 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#3 _runPendingImmediateCallback (dart:isolate/runtime/libisolate_patch.dart:115:13)
#4 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:172:5)