参考链接: Python中的桌面通知程序

flutter开发桌面程序

1.始终取消您的流订阅: (1. Always cancel your stream subscription:)

When I started learning Flutter, I did not always think about canceling my stream subscription because that was something I never heard about.

当我开始学习Flutter时,我并不总是考虑取消流订阅,因为那是我从未听说过的事情。

But what I learned is that even if your widget is no longer alive, well, your stream subscription still is! And that can become a major issue when the widget is re-created a certain number of times, leading to possible process overload!

但是我了解到,即使您的小部件不再存在,您的流订阅仍然有效! 当重新创建窗口小部件一定次数时,这可能成为一个主要问题,从而可能导致进程过载!

To prevent that, you could just add a conditional block that checks if the widget is mounted, but that would still result in a useless loss of performance.

为防止这种情况,您可以只添加一个条件块来检查该窗口小部件是否已安装,但这仍然会导致无用的性能损失。

So to prevent that here is how you should manage your stream subscription in Flutter:

因此,为防止这种情况,您应该在Flutter中管理流订阅:

class MyWidget extends StatefulWidget {

@override

_MyWidgetState createState() => _MyWidgetState();

}

class _MyWidgetState extends State<MyWidget> {

StreamSubscription _streamSubscription;

int _counter = 0;

@override

void initState() {

super.initState();

_streamSubscription = Stream<void>.periodic(Duration(milliseconds: 500)).listen((void _) {

setState(() {

_counter++;

});

});

}

@override

Widget build(BuildContext context) {

return Text(_counter.toString());

}

@override

void dispose() {

super.dispose();

_streamSubscription.cancel();

}

}

But the easiest way can sometimes be to just use a StreamBuilder. It is a very powerful widget that will manage the state of its child depending on the stream provided! If you want to know more I would suggest that you read this article from Manzurur Rahman Khan.

但是最简单的方法有时可能是只使用StreamBuilder。 这是一个非常强大的小部件,它将根据提供的流来管理其子状态! 如果您想了解更多信息,建议您阅读Manzurur Ra​​hman Khan的这篇文章。

2.是否要从应用程序中的任何位置访问当前的导航器状态? 方法如下: (2. Do you want to access the current Navigator state from anywhere in your app? Here is how:)

Let’s say that whenever the user receives a certain type of notification, you want to push a view corresponding to the notification.

假设每当用户收到某种通知时,您都希望推送与该通知相对应的视图。

The problem would be that you don’t have access to any BuildContext object which will result in no way to access the current instance of the Navigator.

问题在于您无权访问任何BuildContext对象,这将导致无法访问导航器的当前实例。

The solution is to create an instance of GlobalKey and store it in a global variable anywhere you want. Then simply specify that the navigator key parameter of your MaterialApp instance should be this variable.

解决方案是创建GlobalKey的实例,并将其存储在全局变量中所需的任何位置。 然后,只需指定MaterialApp实例的导航键参数为该变量即可。

Now you can simply access the current Navigator state by using the GlobalKey!

现在,您只需使用GlobalKey即可访问当前的导航器状态!

3.始终在无状态小部件中使用最终变量。 (3. Always Use Final Variables In Your Stateless widgets.)

It can sometimes be tempting to instantiate non-final variables in stateless widgets but that’s something you should always avoid because stateless widgets are immutable which means that they are not supposed to change even a bit!

在无状态小部件中实例化非最终变量有时可能很诱人,但这是您应始终避免的事情,因为无状态小部件是不可变的,这意味着它们甚至不应改变!

If you need a non-final variable, consider using a Stateful widget instead!

如果需要非最终变量,请考虑使用有状态的小部件!

4. Flutter可能很冗长,不要偷懒,想想接下来会发生什么! (4. Flutter can be quite verbose, don’t be lazy, think of what’s ahead!)

If you already work with Flutter in your daily life, you probably know how Flutter can be extremely verbose, making you re-write the same code over and over!

如果您已经在日常生活中使用Flutter,那么您可能知道Flutter可能会非常冗长,从而使您一遍又一遍地重写相同的代码!

But, instead of being lazy and just copy-pasting your code, you should create reusable widgets! That will save you a ton of time and make your code more maintainable!

但是,您应该创建可重用的小部件,而不是懒惰并只复制粘贴您的代码! 这样可以节省大量时间,并使代码更易于维护!

If you don’t see how you could do that, you can check this article!

如果您看不到该怎么做,可以查看本文 !

5.不能使用const构造函数 (5. Use const Constructors when you cant)

Did you even know that Dart had a const constructor? A const constructor is pretty useful in terms of performance and the reason for it is simple!

您甚至不知道Dart具有const构造函数吗? const构造函数在性能方面非常有用,其原因很简单!

Let’s say that you create a simple text widget that displays ‘Hello World’. You want to display this text in different places of your app but the thing is that you don’t want to instantiate it more than once.

假设您创建了一个显示“ Hello World”的简单文本小部件。 您想在应用程序的不同位置显示此文本,但事实是您不想多次实例化它。

The solution that may come to your mind if you never heard about const constructors would be to define a global variable containing the text widget. But this solution is not really… esthetic.

如果您从未听说过const构造函数 ,可能想到的解决方案是定义一个包含文本小部件的全局变量。 但是这种解决方案并不是真的……美观。

As you probably guessed it, the good solution here would be to use a const constructor! A const constructor will store the instance and returns it wherever you create the same instance of your class with a const constructor!

您可能已经猜到了,这里的好解决方案是使用const构造函数! const构造函数将存储该实例,并在您使用const构造函数创建类的相同实例时将其返回!

So basically, you will only have one instance of your text widget if you always use it with a const constructor, no matter how many times you ‘instantiate’ it in your code.

因此,基本上,如果您始终将其与const构造函数一起使用,则您将只有一个文本小部件实例,无论您在代码中“实例化”多少次。

结束 (The End)

I hope you liked this article :)

希望您喜欢这篇文章:)

https://www.twitter.com/FlutterComm

https://www.twitter.com/FlutterComm

翻译自: https://medium.com/flutter-community/5-tips-to-know-before-you-start-developing-your-app-with-flutter-50771507dae0

flutter开发桌面程序

[转载] flutter开发桌面程序_在开始使用Flutter开发应用程序之前要了解的5条提示相关推荐

  1. flutter开发桌面应用_Flutter应用开发十大公司

    flutter开发桌面应用 Well, if you've already clicked on the link, there's no need to tell you what Flutter ...

  2. Flutter开发桌面应用,Google准备了三年!蓄势待发!

    已经三年了 Desktop Embedding for Flutter项目,从提交"Initial commit"(2018年2月15日)到现在,已经三年了. 一年前的官方文档仍然 ...

  3. flutter开发小程序_为什么我认为Flutter是移动应用程序开发的未来

    flutter开发小程序 I dabbled a bit in Android and iOS development quite a few years back using Java and Ob ...

  4. Flutter开发桌面应用

    一.开发windows桌面应用的一些配置:(注意.cpp文件里哪怕是注释都不能有中文,否则会报错,目前没有找到解决办法) 1.调整屏幕的大小: 将windows/runner里的main.cpp文件: ...

  5. 渐进式web应用程序_如何使用渐进式Web应用程序更快,更便宜地构建新应用程序...

    渐进式web应用程序 You need an app! The question is- which kind? 您需要一个应用程序! 问题是--哪种? For the last 8 years or ...

  6. 11无监听程序_腾讯开心鼠英语 小程序实践与总结

    腾讯开心鼠英语 团队中有很多小程序的项目,且后续还会很多小程序的开发和迭代规划,因此我们团队是小程序的重度使用者.在小程序的开发中,团队积累了一些技术和经验,也遇到了一些困难和挑战,还踩了很多坑,因此 ...

  7. plsql developer无监听程序_腾讯开心鼠英语 小程序实践与总结

    腾讯开心鼠英语 团队中有很多小程序的项目,且后续还会很多小程序的开发和迭代规划,因此我们团队是小程序的重度使用者.在小程序的开发中,团队积累了一些技术和经验,也遇到了一些困难和挑战,还踩了很多坑,因此 ...

  8. flutter release 版本 调试_腾讯课堂Flutter工程实践系列——接入篇

    前言 课堂目前的技术栈是React Native + Hybird + Native,随着技术的演进多端融合的趋势越来越明显,而RN的弊端也突显出来,jsBridge性能不是最优,占用前端人力,定位问 ...

  9. 一个完整的嵌入式程序_放下偏见,原来嵌入式程序员如此“妖娆”!

    感兴趣的小伙伴可以来我的Java交流群,可以获取免费的学习资料 828 697 593 对Java技术,架构技术感兴趣的同学,欢迎加群,一起学习,相互讨论. 竟然都看到最后了,给小编点个关注吧,小编还 ...

最新文章

  1. 【ACM】删数问题(待更)
  2. mybatis的一对一 一对多 多对多
  3. 2018python好找工作吗-2018年IT行业薪资大揭秘:你拖后腿了吗?
  4. 【Android 进程保活】应用进程拉活 ( 账户同步拉活 | 账号添加 | 源码资源 )
  5. 游戏对象的移动旋转缩放
  6. solr入门之參考淘宝搜索提示功能优化拼音加汉字搜索功能
  7. word List 08
  8. gulp webpack整合
  9. 简单搭建一个SSM项目(一)
  10. [置顶]       spring + jstl 实现java国际化的配置步骤
  11. C#中的深度学习:ML.NET中具有预训练模型的硬币识别
  12. React学习整理(一):React 安装
  13. 机器学习导论(一)绪论
  14. 华为ICT认证是什么意思?
  15. Java链表入门(超详细)
  16. 遗传算法优化SVM支持向量机分类预测的参数代码模型
  17. endnote如何导入txt文件_EndNote导入万方文献的方法 | 科研动力
  18. 砂糖橘文案:水果砂糖橘的文案,水果文案砂糖橘
  19. 接着前几期内容继续对单片机怎么学习来做一个了解
  20. 洛谷 P1007 独木桥

热门文章

  1. 【数控雕刻】【刀具路径】北京精雕JDPaint5.19+诺诚NC转换器4.0+SDU NCEdit1.0(什么是ENG和NC文件)
  2. 【编辑器】常用编程环境使用感受20190804
  3. linux asm函数,Linux 字符设备驱动—— ioremap() 函数解析
  4. 985 211 PHP,你们要的985、211高校官方报录比汇总来了
  5. python的几个实用命令_你不知道的几个Python命令,比Excel好用多了
  6. spring boot logback_logstash配合spring boot-logback项目实时传输日志
  7. _软件园三期西片区F地块举行招商推介会 超300家企业意向落户 - 本网原创
  8. C#基础9:虚函数与多态
  9. C#基础1:输入输出+变量定义
  10. 标识符的作用域与可见性