[英]What are the Windows and Linux native OS/system calls made from malloc()?
[英]How to open a specific native Mac OS, Windows and Linux system folder through Flutter desktop?
您可以使用 package file_picker ,它支持您需要的所有平台。
FilePickerResult? result = await FilePicker.platform.pickFiles();
if (result != null) {
File file = File(result.files.single.path);
} else {
// User canceled the picker
}
file_picker: ^4.4.0
这个 package 在所有平台上都标有
单个文件
FilePickerResult? result = await FilePicker.platform.pickFiles();
if (result != null) {
File file = File(result.files.single.path);
} else {
// User canceled the picker
}
多个文件
FilePickerResult? result = await FilePicker.platform.pickFiles(allowMultiple: true);
if (result != null) {
List<File> files = result.paths.map((path) => File(path)).toList();
} else {
// User canceled the picker
}
在 Windows 中是这样的:
完整示例代码:
import 'dart:io';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(MaterialApp(home: sta()));
}
// eyJlcnJvciI6IlVOS05PV05fRVJST1IifQ==
class sta extends StatefulWidget {
const sta({Key? key}) : super(key: key);
@override
State<sta> createState() => _staState();
}
class _staState extends State<sta> {
@override
Widget build(BuildContext context) {
// MediaQuery(
// data: MediaQuery.of(context).copyWith(
// textScaleFactor: 1.0,
// ),
return Scaffold(
appBar: AppBar(),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 100,
width: 100,
child: OutlinedButton(
onPressed: () {
Filepick();
},
child: Text("Pick File"),
),
),
],
),
),
],
));
}
Future<void> Filepick() async {
FilePickerResult? result = await FilePicker.platform.pickFiles();
if (result != null) {
File file = File(result.files.single.path ?? "");
} else {
// User canceled the picker
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.