【Flutter桌面篇】Flutter&Windows应用尝鲜(2)

Github上google的flutter-desktop-embedding是官方的桌面支持项目,

里面有很多官方提供的实用插件,可以下载看看。

git clone https://github.com/google/flutter-desktop-embedding.git

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

如果上面的main.dart有个×,八成是SDK没有配置好,可以在Settings...-->Languaes &Frameworks-->Flutter面板配置

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

可以看出这个项目引用了很多本地的插件,这些插件是目前桌面开发很宝贵的资源。

flutter pub get之后,就可以运行示例项目了

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

如果你的电脑没有在开发者模式,使用插件会出错。 你可以在设置-->更新和安全-->开发者选项里设置

Building with plugins requires symlink support. Please enable Developer Mode in your system settings

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

然后运行即可,项目运行效果如下:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传


2. 示例项目的几个插件
  • window_size屏幕尺寸插件

这个插件非常有用,桌面不同于手机。有窗口的概念,所以定义程序的窗口大小非常必要。

import ‘package:window_size/window_size.dart’ as window_size;

void main() {
// Try to resize and reposition the window to be half the width and height
// of its screen, centered horizontally and shifted up from center.
WidgetsFlutterBinding.ensureInitialized();
// 获取窗口信息,然后设置窗口信息
window_size.getWindowInfo().then((window) {
if (window.screen != null) {
final screenFrame = window.screen.visibleFrame;
final width = math.max((screenFrame.width / 2).roundToDouble(), 800.0);
final height = math.max((screenFrame.height / 2).roundToDouble(), 600.0);
final left = ((screenFrame.width - width) / 2).roundToDouble();
final top = ((screenFrame.height - height) / 3).roundToDouble();
final frame = Rect.fromLTWH(left, top, width, height);
//设置窗口信息
window_size.setWindowFrame(frame);
//设置窗口顶部标题
window_size
.setWindowTitle(‘Flutter Testbed on ${Platform.operatingSystem}’);

if (Platform.isMacOS) {
window_size.setWindowMinSize(Size(800, 600));
window_size.setWindowMaxSize(Size(1600, 1200));
}
}
});

runApp(new MyApp());
}


  • color_panel颜色选择插件

External Libraries#Flutter Plugin中 你可以看到插件信息,可以看到 color_panel插件没有支持Windows。

在点击左上角选择颜色时,并没有额外处理,所以会报错,这不太好。应该可以给个提示什么的。

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传


  • file_chooser文件选择插件

非常实用的插件,支持打开文件选择面板文件保存面板

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

FlatButton(
child: const Text(‘OPEN’),
onPressed: () async {
String initialDirectory;
if (Platform.isMacOS || Platform.isWindows) {
initialDirectory =
(await getApplicationDocumentsDirectory()).path;
}
//打开文件选择面板
final result = await showOpenPanel(
allowsMultipleSelection: true,
initialDirectory: initialDirectory);
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(_resultTextForFileChooserOperation(
_FileChooserType.open, result))));
},
)

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

FlatButton(
child: const Text(‘SAVE’),
onPressed: () {
//打开文件保存面板
showSavePanel(suggestedFileName: ‘save_test.txt’).then((result) {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(_resultTextForFileChooserOperation(
_FileChooserType.save, result)),
));
});
},
),

除此之外,还可以指定过滤类型

FlatButton(
child: const Text(‘OPEN MEDIA’),
onPressed: () async {
final result =
await showOpenPanel(allowedFileTypes: [
FileTypeFilterGroup(label: ‘Images’, fileExtensions: [
‘bmp’,
‘gif’,
‘jpeg’,
‘jpg’,
‘png’,
‘tiff’,
‘webp’,
]),
FileTypeFilterGroup(label: ‘Video’, fileExtensions: [
‘avi’,
‘mov’,
‘mpeg’,
‘mpg’,
‘webm’,
]),
]);
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(_resultTextForFileChooserOperation(
_FileChooserType.open, result))));
},
),


  • url_launcher、url_launcher_fde 插件

你会看到一些有fde结尾的 插件,它们在plugins\flutter_plugins里,包里面有windows支持。

使用的方式和之前一样,url_launcher主要用于一些链接的跳转。

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

FlatButton(
child: const Text(‘OPEN ON GITHUB’),
onPressed: () {
url_launcher
.launch(‘https://github.com/google/flutter-desktop-embedding’);
},
),


  • path_provider、path_provider_fde 插件

用于获取文件夹,这个非常有用。

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

void _showDir() async{
Directory tempDir = await getTemporaryDirectory();
Directory appDir = await getApplicationSupportDirectory();
Directory appDocDir = await getApplicationDocumentsDirectory();
print(‘----getTemporaryDirectory----- t e m p D i r . p a t h − − − − − − ′ ) ; p r i n t ( ′ − − − − g e t A p p l i c a t i o n S u p p o r t D i r e c t o r y − − − − − {tempDir.path}------'); print('----getApplicationSupportDirectory----- tempDir.path);print(getApplicationSupportDirectory{appDir.path}------’);
print(‘----getApplicationDocumentsDirectory-----${appDocDir.path}------’);
}


三、尾声
1. 说一下package和plugin的区别:

Flutter对于平台级的包是plugin,比如主要是和平台相关的功能,如path_provider、sqlfilte,

用纯Dart的开发的包是package,这和平台无关,可以跨平台使用,比如bloc、provider、flutter_star

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

目前plugin支持Windows的不多,支持Windows的sqlite数据库插件可以用moor_ffi

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传


2. 关于Windows项目:

一直觉得Flutter只是个中介者,每个平台的项目都是独立的。

并非是One For All(一者承担所有),而是All By One(所有的都可以做),比如

最后

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助

因此我收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门

如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门**

如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

  • 8
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据引用和引用可以得知,Flutter已经为Windows应用开发做好了准备,并且在Windows上推出了Flutter的支持。FlutterWindows版本结合了Dart框架和C引擎,通过嵌入层与Windows进行通信,并将UI绘制到屏幕上。这意味着开发者现在可以使用Flutter来构建和上架Windows应用程序。Flutter提供了跨平台的开发能力,使开发者能够同时为Android、iOS和Windows等多个平台开发应用程序。因此,如果开发者希望上架Windows应用,他们可以使用Flutter来构建应用,并通过Windows商店或其他途径将其上架。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Flutter稳定支持Windows,开发者做好准备了吗?](https://blog.csdn.net/weixin_39787030/article/details/122808516)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Flutter 稳定版支持 Windows,开发者还学的动吗?](https://blog.csdn.net/weixin_38754349/article/details/122994720)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值