二、官方桌面项目和一些桌面插件
1.运行官方桌面示例
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
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)
最后
感觉现在好多人都在说什么安卓快凉了,工作越来越难找了。又是说什么程序员中年危机啥的,为啥我这年近30的老农根本没有这种感觉,反倒觉得那些贩卖焦虑的都是瞎j8扯谈。当然,职业危机意识确实是要有的,但根本没到那种草木皆兵的地步好吗?
Android凉了都是弱者的借口和说辞。虽然 Android 没有前几年火热了,已经过去了会四大组件就能找到高薪职位的时代了。这只能说明 Android 中级以下的岗位饱和了,现在高级工程师还是比较缺少的,很多高级职位给的薪资真的特别高(钱多也不一定能找到合适的),所以努力让自己成为高级工程师才是最重要的。
所以,最后这里放上我耗时两个月,将自己8年Android开发的知识笔记整理成的Android开发者必知必会系统学习资料笔记,上述知识点在笔记中都有详细的解读,里面还包含了腾讯、字节跳动、阿里、百度2019-2021面试真题解析,并且把每个技术点整理成了视频和PDF(知识脉络 + 诸多细节)。
以上全套学习笔记面试宝典,吃透一半保你可以吊打面试官,只有自己真正强大了,有核心竞争力,你才有拒绝offer的权力,所以,奋斗吧!骚年们!千里之行,始于足下。种下一颗树最好的时间是十年前,其次,就是现在。
最后,赠与大家一句诗,共勉!
不驰于空想,不骛于虚声。不忘初心,方得始终。
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门即可获取!
34)]
以上全套学习笔记面试宝典,吃透一半保你可以吊打面试官,只有自己真正强大了,有核心竞争力,你才有拒绝offer的权力,所以,奋斗吧!骚年们!千里之行,始于足下。种下一颗树最好的时间是十年前,其次,就是现在。
最后,赠与大家一句诗,共勉!
不驰于空想,不骛于虚声。不忘初心,方得始终。