编程开源技术交流,分享技术与知识

网站首页 > 开源技术 正文

Flutter3.13新特性概述(flutter最新)

wxchong 2024-08-04 02:37:08 开源技术 30 ℃ 0 评论

#挑战30天在头条写日记#

在2023年8月16日发布了 Flutter3.13稳定版本,本次更新共合并了724个pull请求。


1 Engine 引擎方面

本次更新对新的图形渲染器做了一些改进,并为可折叠设备添加了新的引擎api。

2 Impeller

继续改进了Impeller在iOS上的性能,由于许多不同的优化,iOS上的 Impeller 渲染器现在不仅具有更低的延迟(通过完全消除着色器编译问题),而且在一些基准测试中也具有更高的平均吞吐量。特别是,在flutter/gallery 的过渡性能基准测试中,平均帧栅格化时间现在大约是Skia的一半。

3 Fidelity的改进

在3.10后,Impeller引擎下,支持使用广域色(wide gamut colors),在iOS平台默认使用。

4 新的 Engine Api 对折叠屏的支持

为了更好地支持可折叠设备,添加了一个新的API来检索显示器的各种属性。新的getter FlutterView。display返回一个显示对象。Display对象报告显示的物理大小、设备像素比率和刷新率。(后续有文章更新说明 setPreferredOrientations

5 TextField 新增字符识别

在iOS上使用TextField时,用户会自动看到一个使用设备摄像头识别字符并将其插入字段的选项。


6 平台自适应的对话框



7 CupertinoDatePicker 支持 年与月的选择


8 Check 与 radio 新增 ios风格



9 App生命周期的更新

添加了AppLifecycleListener类,用于侦听应用程序生命周期中的更改,并响应退出应用程序的请求。


核心使用代码如下 :

class AppLifecycleDisplay extends StatefulWidget {
  const AppLifecycleDisplay({super.key});

  @override
  State<AppLifecycleDisplay> createState() => _AppLifecycleDisplayState();
}

class _AppLifecycleDisplayState extends State<AppLifecycleDisplay> {
  late final AppLifecycleListener _listener;
  final ScrollController _scrollController = ScrollController();
  final List<String> _states = <String>[];
  late AppLifecycleState? _state;

  @override
  void initState() {
    super.initState();
    _state = SchedulerBinding.instance.lifecycleState;
    _listener = AppLifecycleListener(
      onShow: () => _handleTransition('show'),
      onResume: () => _handleTransition('resume'),
      onHide: () => _handleTransition('hide'),
      onInactive: () => _handleTransition('inactive'),
      onPause: () => _handleTransition('pause'),
      onDetach: () => _handleTransition('detach'),
      onRestart: () => _handleTransition('restart'),
      // This fires for each state change. Callbacks above fire only for
      // specific state transitions.
      onStateChange: _handleStateChange,
    );
    if (_state != null) {
      _states.add(_state!.name);
    }
  }

  @override
  void dispose() {
    _listener.dispose();
    super.dispose();
  }

  void _handleTransition(String name) {
    setState(() {
      _states.add(name);
    });
    _scrollController.animateTo(
      _scrollController.position.maxScrollExtent,
      duration: const Duration(milliseconds: 200),
      curve: Curves.easeOut,
    );
  }

  void _handleStateChange(AppLifecycleState state) {
    setState(() {
      _state = state;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: SizedBox(
        width: 300,
        child: SingleChildScrollView(
          controller: _scrollController,
          child: Column(
            children: <Widget>[
              Text('Current State: ${_state ?? 'Not initialized yet'}'),
              const SizedBox(height: 30),
              Text('State History:\n  ${_states.join('\n  ')}'),
            ],
          ),
        ),
      ),
    );
  }
}

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表