Flutter软件包的widgets.dart,material.dart和cupertino.dart有什么区别,以及使用哪一个? [英] What is the difference between Flutter packages widgets.dart, material.dart and cupertino.dart and which one to use?

查看:873
本文介绍了Flutter软件包的widgets.dart,material.dart和cupertino.dart有什么区别,以及使用哪一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用flutter时,我经常遇到一种由标准库中的不同包公开的类型.

When using flutter, I often come around a type being exposed by different packages in the standard library.

例如FlutterError,但其他小部件也是如此.在编写它并在VS Code中使用IntelliSense解析要导入的程序包以便提供FlutterError时,IntelliSense在多个不同的程序包中为我提供FlutterError:

For example the FlutterError but the same applies to other widgets. When writing it and using IntelliSense in VS Code to resolve the package to import so that FlutterError is available, IntelliSense offers me FlutterError in multiple different packages:

在这种情况下,可以从

  • package:flutter/widgets.dart
  • package:flutter/foundation.dart
  • package:flutter/material.dart
  • package:flutter/cupertino.dart
  • package:flutter/rendering.dart
  • package:flutter/widgets.dart
  • package:flutter/foundation.dart
  • package:flutter/material.dart
  • package:flutter/cupertino.dart
  • package:flutter/rendering.dart

我的理解是material.dartcupertino.dart提供了特定样式的小部件-但是剩下的是什么?我应该在应该独立于平台并且可以在iOS上运行的MaterialApp(..)中导入哪个包?

My understanding is that material.dart and cupertino.dart offer widgets in the particular style - but what is the rest and which package should I import in a MaterialApp(..) that should be platform independent and also run on iOS?

而且-如果有所不同-应该使用哪个,以便特定平台的小部件可以在Android&上自动使用iOS是否支持日期/时间选择器之类的本机功能,以便日期选择器自动成为Android上特定于平台的变体以及iOS上特定于平台的变体?

And - if it makes a difference - which one should be used so that platform-specific widgets are automatically used on Android & iOS for native functionality like Date/Timepickers so that a Datepicker is automatically the platform specific variant on Android and the platform specific variant on iOS?

推荐答案

发生的事情是,该类在框架的下部定义(此处为foundation,表示FlutterError)

What happens is, the class is defined in a lower part of the framework (here foundation for FlutterError)

然后,框架的高层使用export指令重新导出较低层的内容.

And then higher layers of the framework reexport the content of the lower layers, using the export directive.

这样做主要是为了确保开发人员在通常需要它们时都不必导入5种以上不同的东西.

This is done mainly to make sure that developers don't have to import 5+ different things when they usually need them all.

例如material.dart看起来像这样:

export 'package:flutter/widget.dart';

class RaisedButton { }

这篇关于Flutter软件包的widgets.dart,material.dart和cupertino.dart有什么区别,以及使用哪一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆