admin管理员组文章数量:1129794
My Code Look alike this
As we know that we can open .exe in flutter, but what i want is when user open any .exe launch it in same window instead of new or separated window.
//Here are all the dependencies
import 'dart:ffi';
import 'dart:io';
import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart';
import 'package:flutter/material.dart';
import 'package:flutter_native_view/flutter_native_view.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await FlutterNativeView.ensureInitialized();
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final controller = ScrollController();
final controllers = [
NativeViewController(
handle: FindWindow(
nullptr,
'CPRG'.toNativeUtf16(),
),
hitTestBehavior: HitTestBehavior.translucent,
),
NativeViewController(
handle: FindWindow(
nullptr,
'This PC'.toNativeUtf16(),
),
hitTestBehavior: HitTestBehavior.translucent,
),
];
Future<bool> openFile(String filePath) async {
try {
bool fileExists = await File(filePath).exists();
if (!fileExists) {
print("File does not exist at: $filePath");
return false;
}
if (Platform.isWindows) {
print('Attempting to run: $filePath');
try {
Process process = await Process.start(
filePath,
[],
mode: ProcessStartMode.detached,
runInShell: true,
);
print("Process started: $process");
return true;
} catch (e) {
print("Failed to start process: $e");
return false;
}
} else {
print("Opening files is not supported on this platform.");
return false;
}
} catch (e) {
print("Error opening file: $e");
return false;
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
floatingActionButton: ElevatedButton(
onPressed: () {
openFile('D:/ThermoverseExes/Products/Combipac RG/CPRG.exe');
},
child: Text('opne')),
appBar: AppBar(
title: const Text('flutter_native_view'),
),
body: ListView(
controller: controller,
padding: const EdgeInsets.symmetric(vertical: 16.0),
children: [
Padding(
padding:
const EdgeInsets.symmetric(vertical: 16.0, horizontal: 32.0),
child: NativeView(
controller: controllers[0],
width: 640.0,
height: 480.0,
),
),
Padding(
padding:
const EdgeInsets.symmetric(vertical: 16.0, horizontal: 32.0),
child: NativeView(
controller: controllers[1],
width: 640.0,
height: 480.0,
),
),
],
),
),
);
}
}
As we know that we can open .exe in flutter, but what i want is when user open any .exe launch it in same window instead of new or separated window.
本文标签: dartHow to open exe in same window in flutterStack Overflow
版权声明:本文标题:dart - How to open exe in same window in flutter - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736754390a1951208.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论