From 58144657b7712689e8ca65d6002e127b0e54d711 Mon Sep 17 00:00:00 2001 From: SimpleLove520 <1960997571@qq.com> Date: Sat, 30 Nov 2024 16:00:03 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: SimpleLove520 <1960997571@qq.com> --- ohos/performance/list_view_demo/.gitignore | 44 +++++ .../list_view_demo/analysis_options.yaml | 29 +++ ohos/performance/list_view_demo/lib/main.dart | 171 ++++++++++++++++++ .../list_view_demo/ohos/.gitignore | 19 ++ .../list_view_demo/ohos/AppScope/app.json5 | 10 + .../resources/base/element/string.json | 8 + .../resources/base/media/app_icon.png | Bin 0 -> 6790 bytes .../list_view_demo/ohos/build-profile.json5 | 42 +++++ .../list_view_demo/ohos/entry/.gitignore | 7 + .../ohos/entry/build-profile.json5 | 29 +++ .../list_view_demo/ohos/entry/hvigorfile.ts | 17 ++ .../ohos/entry/oh-package.json5 | 9 + .../main/ets/entryability/EntryAbility.ets | 24 +++ .../ohos/entry/src/main/ets/pages/Index.ets | 38 ++++ .../ets/plugins/GeneratedPluginRegistrant.ets | 24 +++ .../ohos/entry/src/main/module.json5 | 53 ++++++ .../main/resources/base/element/color.json | 8 + .../main/resources/base/element/string.json | 16 ++ .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes .../resources/base/profile/main_pages.json | 5 + .../main/resources/en_US/element/string.json | 16 ++ .../main/resources/zh_CN/element/string.json | 16 ++ .../src/ohosTest/ets/test/Ability.test.ets | 50 +++++ .../entry/src/ohosTest/ets/test/List.test.ets | 20 ++ .../ohosTest/ets/testability/TestAbility.ets | 63 +++++++ .../ohosTest/ets/testability/pages/Index.ets | 49 +++++ .../ets/testrunner/OpenHarmonyTestRunner.ts | 64 +++++++ .../ohos/entry/src/ohosTest/module.json5 | 51 ++++++ .../resources/base/element/color.json | 8 + .../resources/base/element/string.json | 16 ++ .../ohosTest/resources/base/media/icon.png | Bin 0 -> 6790 bytes .../resources/base/profile/test_pages.json | 5 + .../ohos/hvigor/hvigor-config.json5 | 20 ++ .../list_view_demo/ohos/hvigorfile.ts | 21 +++ .../list_view_demo/ohos/oh-package.json5 | 33 ++++ ohos/performance/list_view_demo/pubspec.yaml | 104 +++++++++++ .../list_view_demo/test/widget_test.dart | 30 +++ 37 files changed, 1119 insertions(+) create mode 100644 ohos/performance/list_view_demo/.gitignore create mode 100644 ohos/performance/list_view_demo/analysis_options.yaml create mode 100644 ohos/performance/list_view_demo/lib/main.dart create mode 100644 ohos/performance/list_view_demo/ohos/.gitignore create mode 100644 ohos/performance/list_view_demo/ohos/AppScope/app.json5 create mode 100644 ohos/performance/list_view_demo/ohos/AppScope/resources/base/element/string.json create mode 100644 ohos/performance/list_view_demo/ohos/AppScope/resources/base/media/app_icon.png create mode 100644 ohos/performance/list_view_demo/ohos/build-profile.json5 create mode 100644 ohos/performance/list_view_demo/ohos/entry/.gitignore create mode 100644 ohos/performance/list_view_demo/ohos/entry/build-profile.json5 create mode 100644 ohos/performance/list_view_demo/ohos/entry/hvigorfile.ts create mode 100644 ohos/performance/list_view_demo/ohos/entry/oh-package.json5 create mode 100644 ohos/performance/list_view_demo/ohos/entry/src/main/ets/entryability/EntryAbility.ets create mode 100644 ohos/performance/list_view_demo/ohos/entry/src/main/ets/pages/Index.ets create mode 100644 ohos/performance/list_view_demo/ohos/entry/src/main/ets/plugins/GeneratedPluginRegistrant.ets create mode 100644 ohos/performance/list_view_demo/ohos/entry/src/main/module.json5 create mode 100644 ohos/performance/list_view_demo/ohos/entry/src/main/resources/base/element/color.json create mode 100644 ohos/performance/list_view_demo/ohos/entry/src/main/resources/base/element/string.json create mode 100644 ohos/performance/list_view_demo/ohos/entry/src/main/resources/base/media/icon.png create mode 100644 ohos/performance/list_view_demo/ohos/entry/src/main/resources/base/profile/main_pages.json create mode 100644 ohos/performance/list_view_demo/ohos/entry/src/main/resources/en_US/element/string.json create mode 100644 ohos/performance/list_view_demo/ohos/entry/src/main/resources/zh_CN/element/string.json create mode 100644 ohos/performance/list_view_demo/ohos/entry/src/ohosTest/ets/test/Ability.test.ets create mode 100644 ohos/performance/list_view_demo/ohos/entry/src/ohosTest/ets/test/List.test.ets create mode 100644 ohos/performance/list_view_demo/ohos/entry/src/ohosTest/ets/testability/TestAbility.ets create mode 100644 ohos/performance/list_view_demo/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets create mode 100644 ohos/performance/list_view_demo/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts create mode 100644 ohos/performance/list_view_demo/ohos/entry/src/ohosTest/module.json5 create mode 100644 ohos/performance/list_view_demo/ohos/entry/src/ohosTest/resources/base/element/color.json create mode 100644 ohos/performance/list_view_demo/ohos/entry/src/ohosTest/resources/base/element/string.json create mode 100644 ohos/performance/list_view_demo/ohos/entry/src/ohosTest/resources/base/media/icon.png create mode 100644 ohos/performance/list_view_demo/ohos/entry/src/ohosTest/resources/base/profile/test_pages.json create mode 100644 ohos/performance/list_view_demo/ohos/hvigor/hvigor-config.json5 create mode 100644 ohos/performance/list_view_demo/ohos/hvigorfile.ts create mode 100644 ohos/performance/list_view_demo/ohos/oh-package.json5 create mode 100644 ohos/performance/list_view_demo/pubspec.yaml create mode 100644 ohos/performance/list_view_demo/test/widget_test.dart diff --git a/ohos/performance/list_view_demo/.gitignore b/ohos/performance/list_view_demo/.gitignore new file mode 100644 index 00000000..24476c5d --- /dev/null +++ b/ohos/performance/list_view_demo/.gitignore @@ -0,0 +1,44 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +.packages +.pub-cache/ +.pub/ +/build/ + +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json + +# Android Studio will place build artifacts here +/android/app/debug +/android/app/profile +/android/app/release diff --git a/ohos/performance/list_view_demo/analysis_options.yaml b/ohos/performance/list_view_demo/analysis_options.yaml new file mode 100644 index 00000000..61b6c4de --- /dev/null +++ b/ohos/performance/list_view_demo/analysis_options.yaml @@ -0,0 +1,29 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at + # https://dart-lang.github.io/linter/lints/index.html. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/ohos/performance/list_view_demo/lib/main.dart b/ohos/performance/list_view_demo/lib/main.dart new file mode 100644 index 00000000..3a1810dd --- /dev/null +++ b/ohos/performance/list_view_demo/lib/main.dart @@ -0,0 +1,171 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import 'dart:async'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +/** +优化和解释 + +代码结构 + + 1. DataService + • 模拟数据源,提供分页数据。 + 2. DataProvider + • 负责管理数据逻辑,继承 ChangeNotifier 实现状态通知。 + • 包括分页逻辑、数据缓存、加载状态。 + 3. OptimizedAppWithProvider + • 使用 ChangeNotifierProvider 提供全局状态,管理 DataProvider。 + 4. PerformanceOptimizedScreen + • 使用 ListView.builder 构建懒加载列表,动态加载更多数据。 + +性能优化 + + 1. 懒加载 +使用 ListView.builder 只渲染当前可见区域的组件,减少内存占用。 + 2. 状态分离 +数据逻辑集中在 DataProvider,界面专注于 UI 构建,提升可维护性。 + 3. 异步操作 +使用 Future 和 async/await 分离主线程和网络延迟,避免阻塞。 + 4. 增量加载 +滚动到列表底部时加载下一页数据,而不是一次性加载所有数据。 + 5. Provider 状态管理 +使用 Provider 动态更新 UI,仅刷新必要的组件。 + +项目运行效果 + + • 页面加载时会显示第一页数据。 + • 滑动到列表底部时会自动加载更多。 + • 显示加载指示器,并在没有更多数据时显示“没有更多数据了”提示。 + + */ + +/// 数据服务类:模拟远程数据源 +class DataService { + // 模拟从服务器获取分页数据 + Future> fetchPage(int page, int pageSize) async { + if (page == 10) { + return []; + } + await Future.delayed(const Duration(seconds: 1)); // 模拟网络延迟 + return List.generate( + pageSize, + (index) => 'Item ${(page - 1) * pageSize + index + 1}', + ); + } +} + +/// 数据管理类:继承 ChangeNotifier,用于与 UI 通信 +class DataProvider extends ChangeNotifier { + final DataService dataService; + int _currentPage = 0; // 当前分页数 + final int pageSize; // 每页条目数 + final List _items = []; // 数据缓存 + bool _isLoading = false; // 是否正在加载 + bool _hasMore = true; // 是否还有更多数据 + + DataProvider({required this.dataService, this.pageSize = 20}); + + // 公开的属性 + List get items => _items; + bool get isLoading => _isLoading; + bool get hasMore => _hasMore; + + /// 加载下一页数据 + Future loadNextPage() async { + if (_isLoading || !_hasMore) return; // 防止重复加载 + _isLoading = true; + notifyListeners(); + + _currentPage++; + final newItems = await dataService.fetchPage(_currentPage, pageSize); + + if (newItems.isEmpty) { + _hasMore = false; // 没有更多数据了 + } else { + _items.addAll(newItems); + } + + _isLoading = false; + notifyListeners(); + } +} + +/// 使用 Provider 管理状态的主应用 +class OptimizedAppWithProvider extends StatelessWidget { + const OptimizedAppWithProvider({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return MaterialApp( + home: ChangeNotifierProvider( + // 提供 DataProvider 的实例给子组件 + create: (_) => DataProvider(dataService: DataService()), + child: const PerformanceOptimizedScreen(), + ), + ); + } +} + +/// 主屏幕:包含优化后的列表视图 +class PerformanceOptimizedScreen extends StatelessWidget { + const PerformanceOptimizedScreen({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + final dataProvider = Provider.of(context); + + return Scaffold( + appBar: AppBar(title: const Text('性能优化示例')), + body: Column( + children: [ + Expanded( + child: ListView.builder( + itemCount: dataProvider.items.length + 1, // 包括加载更多项 + itemBuilder: (context, index) { + if (index == dataProvider.items.length) { + // 构建加载提示或完成消息 + return dataProvider.hasMore + ? const Padding( + padding: EdgeInsets.all(16.0), + child: Center(child: CircularProgressIndicator()), + ) + : const Padding( + padding: EdgeInsets.all(16.0), + child: Center(child: Text('没有更多数据了')), + ); + } + + // 构建普通列表项 + return ListTile( + title: Text(dataProvider.items[index]), + ); + }, + ), + ), + if (dataProvider.isLoading) Container(), + ], + ), + floatingActionButton: FloatingActionButton( + onPressed: dataProvider.loadNextPage, // 手动触发加载更多 + child: const Icon(Icons.add), + ), + ); + } +} + +void main() { + runApp(const OptimizedAppWithProvider()); +} diff --git a/ohos/performance/list_view_demo/ohos/.gitignore b/ohos/performance/list_view_demo/ohos/.gitignore new file mode 100644 index 00000000..6ca13b31 --- /dev/null +++ b/ohos/performance/list_view_demo/ohos/.gitignore @@ -0,0 +1,19 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +*.har +**/BuildProfile.ets +**/oh-package-lock.json5 + +**/src/main/resources/rawfile/flutter_assets/ +**/libs/arm64-v8a/libapp.so +**/libs/arm64-v8a/libflutter.so +**/libs/arm64-v8a/libvmservice_snapshot.so diff --git a/ohos/performance/list_view_demo/ohos/AppScope/app.json5 b/ohos/performance/list_view_demo/ohos/AppScope/app.json5 new file mode 100644 index 00000000..24cfa988 --- /dev/null +++ b/ohos/performance/list_view_demo/ohos/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.example.list_view_demo", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/ohos/performance/list_view_demo/ohos/AppScope/resources/base/element/string.json b/ohos/performance/list_view_demo/ohos/AppScope/resources/base/element/string.json new file mode 100644 index 00000000..5bba794d --- /dev/null +++ b/ohos/performance/list_view_demo/ohos/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "list_view_demo" + } + ] +} diff --git a/ohos/performance/list_view_demo/ohos/AppScope/resources/base/media/app_icon.png b/ohos/performance/list_view_demo/ohos/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=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L{wsdrmPvf#a9OHyYLcwQD4Kcm)`LLwMh4WT~p29f7M!iafJSU`IV}QY5Wa z(n44-9oA}?J{a+ah*@31WTs#&J#o1`H98#6IQf;Wv0N_!);f&9g7o-k(lW5rWnDUR zQBFIRG+X=6NnsI@mxnwm;tf5;_Uxg?jZ8m-m0}&6+DA!qam(p$mN5R})yA_7m$q@| zFEd|dpS595rxQr-n#GjI5i-AhnUE>Cr;jpCqSrD~EwK_DqI^7%3#p5)%T_od!t3SOmH9MyXeeGO2(UQL;ax|x?Ncixmeo1=$ z{-);Au{*tfzOG?KQ~K|ak8-HQ?`Pekhe2WM(8s{xv-p>Zmu_6{G!-oE$7$mY`MOJorI=+mMx?H;`pr!;fVYz?5~yXBACruWB`Ph zZM}90_<^OBxIhyZ9BW$`>6JvO;%VFpqVr8|7t3~AmxYak6?`Pp#c;**_SYmi`&z23 z`p6_~ePvH)C6x-G9$hgL=eVALq`-AiamN>!3~Lxw&{H(b{B(7xSRm6<3<{%{yXiH# zos5Rv1L+8fUKJLo%P>4I&$}y { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', + JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy'); + } + + onForeground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground'); + } + + onBackground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground'); + } +} \ No newline at end of file diff --git a/ohos/performance/list_view_demo/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets b/ohos/performance/list_view_demo/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets new file mode 100644 index 00000000..cef0447c --- /dev/null +++ b/ohos/performance/list_view_demo/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import hilog from '@ohos.hilog'; + +@Entry +@Component +struct Index { + aboutToAppear() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear'); + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/ohos/performance/list_view_demo/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/ohos/performance/list_view_demo/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts new file mode 100644 index 00000000..1def08f2 --- /dev/null +++ b/ohos/performance/list_view_demo/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import hilog from '@ohos.hilog'; +import TestRunner from '@ohos.application.testRunner'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +async function onAbilityCreateCallback() { + hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + var debug = abilityDelegatorArguments.parameters['-D'] + if (debug == 'true') + { + cmd += ' -D' + } + hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? ''); + }) + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end'); + } +} \ No newline at end of file diff --git a/ohos/performance/list_view_demo/ohos/entry/src/ohosTest/module.json5 b/ohos/performance/list_view_demo/ohos/entry/src/ohosTest/module.json5 new file mode 100644 index 00000000..fab77ce2 --- /dev/null +++ b/ohos/performance/list_view_demo/ohos/entry/src/ohosTest/module.json5 @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/ohos/performance/list_view_demo/ohos/entry/src/ohosTest/resources/base/element/color.json b/ohos/performance/list_view_demo/ohos/entry/src/ohosTest/resources/base/element/color.json new file mode 100644 index 00000000..3c712962 --- /dev/null +++ b/ohos/performance/list_view_demo/ohos/entry/src/ohosTest/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ohos/performance/list_view_demo/ohos/entry/src/ohosTest/resources/base/element/string.json b/ohos/performance/list_view_demo/ohos/entry/src/ohosTest/resources/base/element/string.json new file mode 100644 index 00000000..65d8fa5a --- /dev/null +++ b/ohos/performance/list_view_demo/ohos/entry/src/ohosTest/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} \ No newline at end of file diff --git a/ohos/performance/list_view_demo/ohos/entry/src/ohosTest/resources/base/media/icon.png b/ohos/performance/list_view_demo/ohos/entry/src/ohosTest/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=4ZzgdeKtgoc+o5EvN9A1K1_<>M?MBqb#!ASf&# zEX?<)!RH(7>1P+j=jqG(58}TVN-$psA6K}atCuI!KTJD&FMmH-78ZejBm)0qc{ESp z|LuG1{QnBUJRg_E=h1#XMWt2%fcoN@l7eAS!Es?Q+;XsRNPhiiE=@AqlLkJzF`O18 zbsbSmKN=aaq8k3NFYZfDWpKmM!coBU0(XnL8R{4=i|wi{!uWYM2je{U{B*K2PVdu&=E zTq*-XsEsJ$u5H4g6DIm2Y!DN`>^v|AqlwuCD;w45K0@eqauiqWf7l&o)+YLHm~|L~ z7$0v5mkobriU!H<@mVJHLlmQqzQ3d6Rh_-|%Yy2li*tHO>_vcnuZ7OR_xkAIuIU&x z-|8Y0wj|6|a6_I(v91y%k_kNw6pnkNdxjqG8!%Vz_d%c_!X+6-;1`GC9_FpjoHev5fEV7RhJ>r=mh-jp$fqbqRJ=obwdgLDVP5+s zy1=_DWG0Y-Jb3t^WXmkr(d9~08k-|#Ly zaNOmT(^9tIb&eb4%CzIT zAm3CUtWSr1t4?h1kk#NBi{U|pJslvME{q|_eS^3En>SOqSxy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ak6?`Pp#c;**_SYmi`&z23 z`p6_~ePvH)C6x-G9$hgL=eVALq`-AiamN>!3~Lxw&{H(b{B(7xSRm6<3<{%{yXiH# zos5Rv1L+8fUKJLo%P>4I&$}y=2.19.6 <3.0.0' + +# Dependencies specify other packages that your package needs in order to work. +# To automatically upgrade your package dependencies to the latest versions +# consider running `flutter pub upgrade --major-versions`. Alternatively, +# dependencies can be manually updated by changing the version numbers below to +# the latest version available on pub.dev. To see which dependencies have newer +# versions available, run `flutter pub outdated`. +dependencies: + flutter: + sdk: flutter + + + # The following adds the Cupertino Icons font to your application. + # Use with the CupertinoIcons class for iOS style icons. + cupertino_icons: ^1.0.2 + provider: ^6.1.2 + +dev_dependencies: + flutter_test: + sdk: flutter + + # The "flutter_lints" package below contains a set of recommended lints to + # encourage good coding practices. The lint set provided by the package is + # activated in the `analysis_options.yaml` file located at the root of your + # package. See that file for information about deactivating specific lint + # rules and activating additional ones. + flutter_lints: ^2.0.0 + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter packages. +flutter: + + # The following line ensures that the Material Icons font is + # included with your application, so that you can use the icons in + # the material Icons class. + uses-material-design: true + + # To add assets to your application, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/assets-and-images/#resolution-aware + + # For details regarding adding assets from package dependencies, see + # https://flutter.dev/assets-and-images/#from-packages + + # To add custom fonts to your application, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts from package dependencies, + # see https://flutter.dev/custom-fonts/#from-packages diff --git a/ohos/performance/list_view_demo/test/widget_test.dart b/ohos/performance/list_view_demo/test/widget_test.dart new file mode 100644 index 00000000..a43d4bd5 --- /dev/null +++ b/ohos/performance/list_view_demo/test/widget_test.dart @@ -0,0 +1,30 @@ +// This is a basic Flutter widget test. +// +// To perform an interaction with a widget in your test, use the WidgetTester +// utility in the flutter_test package. For example, you can send tap and scroll +// gestures. You can also use WidgetTester to find child widgets in the widget +// tree, read text, and verify that the values of widget properties are correct. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'package:list_view_demo/main.dart'; + +void main() { + testWidgets('Counter increments smoke test', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(const MyApp()); + + // Verify that our counter starts at 0. + expect(find.text('0'), findsOneWidget); + expect(find.text('1'), findsNothing); + + // Tap the '+' icon and trigger a frame. + await tester.tap(find.byIcon(Icons.add)); + await tester.pump(); + + // Verify that our counter has incremented. + expect(find.text('0'), findsNothing); + expect(find.text('1'), findsOneWidget); + }); +} -- Gitee From 7fd17b3ce663d1a5b1f3758fabe79d991dcc908a Mon Sep 17 00:00:00 2001 From: SimpleLove520 <1960997571@qq.com> Date: Sat, 30 Nov 2024 16:42:42 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: SimpleLove520 <1960997571@qq.com> --- .../list_view_demo/lib/data_provider.dart | 54 ++++++++++ .../list_view_demo/lib/data_service.dart | 36 +++++++ ohos/performance/list_view_demo/lib/main.dart | 102 +----------------- .../lib/performance_optimized_screen.dart | 102 ++++++++++++++++++ .../list_view_demo/lib/product.dart | 57 ++++++++++ 5 files changed, 253 insertions(+), 98 deletions(-) create mode 100644 ohos/performance/list_view_demo/lib/data_provider.dart create mode 100644 ohos/performance/list_view_demo/lib/data_service.dart create mode 100644 ohos/performance/list_view_demo/lib/performance_optimized_screen.dart create mode 100644 ohos/performance/list_view_demo/lib/product.dart diff --git a/ohos/performance/list_view_demo/lib/data_provider.dart b/ohos/performance/list_view_demo/lib/data_provider.dart new file mode 100644 index 00000000..a35fd9fd --- /dev/null +++ b/ohos/performance/list_view_demo/lib/data_provider.dart @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import 'package:flutter/material.dart'; +import 'package:list_view_demo/data_service.dart'; +import 'package:list_view_demo/product.dart'; + +/// 数据管理类:管理商品数据 +class DataProvider extends ChangeNotifier { + final DataService dataService; + int _currentPage = 0; // 当前分页数 + final int pageSize; // 每页条目数 + final List _products = []; // 商品数据缓存 + bool _isLoading = false; // 是否正在加载 + bool _hasMore = true; // 是否还有更多数据 + + DataProvider({required this.dataService, this.pageSize = 20}); + + // 公开的属性 + List get products => _products; + bool get isLoading => _isLoading; + bool get hasMore => _hasMore; + + /// 加载下一页数据 + Future loadNextPage() async { + if (_isLoading || !_hasMore) return; // 防止重复加载 + _isLoading = true; + notifyListeners(); + + _currentPage++; + final newProducts = await dataService.fetchPage(_currentPage, pageSize); + + if (newProducts.isEmpty) { + _hasMore = false; // 没有更多数据了 + } else { + _products.addAll(newProducts); + } + + _isLoading = false; + notifyListeners(); + } +} diff --git a/ohos/performance/list_view_demo/lib/data_service.dart b/ohos/performance/list_view_demo/lib/data_service.dart new file mode 100644 index 00000000..1bb1829f --- /dev/null +++ b/ohos/performance/list_view_demo/lib/data_service.dart @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import 'package:list_view_demo/product.dart'; + +/// 数据服务类:模拟远程数据源 +class DataService { + // 模拟从服务器获取分页数据(商品列表) + Future> fetchPage(int page, int pageSize) async { + await Future.delayed(const Duration(seconds: 1)); // 模拟网络延迟 + if (page == 10) { + return []; + } + return List.generate( + pageSize, + (index) => Product( + id: (page - 1) * pageSize + index + 1, + name: '商品 ${(page - 1) * pageSize + index + 1}', + price: (index + 1) * 10.0, + description: '这是商品 ${(page - 1) * pageSize + index + 1} 的描述信息。', + ), + ); + } +} diff --git a/ohos/performance/list_view_demo/lib/main.dart b/ohos/performance/list_view_demo/lib/main.dart index 3a1810dd..9ffcd615 100644 --- a/ohos/performance/list_view_demo/lib/main.dart +++ b/ohos/performance/list_view_demo/lib/main.dart @@ -16,6 +16,10 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; + +import 'data_provider.dart'; +import 'data_service.dart'; +import 'performance_optimized_screen.dart'; /** 优化和解释 @@ -52,57 +56,6 @@ import 'package:provider/provider.dart'; */ -/// 数据服务类:模拟远程数据源 -class DataService { - // 模拟从服务器获取分页数据 - Future> fetchPage(int page, int pageSize) async { - if (page == 10) { - return []; - } - await Future.delayed(const Duration(seconds: 1)); // 模拟网络延迟 - return List.generate( - pageSize, - (index) => 'Item ${(page - 1) * pageSize + index + 1}', - ); - } -} - -/// 数据管理类:继承 ChangeNotifier,用于与 UI 通信 -class DataProvider extends ChangeNotifier { - final DataService dataService; - int _currentPage = 0; // 当前分页数 - final int pageSize; // 每页条目数 - final List _items = []; // 数据缓存 - bool _isLoading = false; // 是否正在加载 - bool _hasMore = true; // 是否还有更多数据 - - DataProvider({required this.dataService, this.pageSize = 20}); - - // 公开的属性 - List get items => _items; - bool get isLoading => _isLoading; - bool get hasMore => _hasMore; - - /// 加载下一页数据 - Future loadNextPage() async { - if (_isLoading || !_hasMore) return; // 防止重复加载 - _isLoading = true; - notifyListeners(); - - _currentPage++; - final newItems = await dataService.fetchPage(_currentPage, pageSize); - - if (newItems.isEmpty) { - _hasMore = false; // 没有更多数据了 - } else { - _items.addAll(newItems); - } - - _isLoading = false; - notifyListeners(); - } -} - /// 使用 Provider 管理状态的主应用 class OptimizedAppWithProvider extends StatelessWidget { const OptimizedAppWithProvider({Key? key}) : super(key: key); @@ -119,53 +72,6 @@ class OptimizedAppWithProvider extends StatelessWidget { } } -/// 主屏幕:包含优化后的列表视图 -class PerformanceOptimizedScreen extends StatelessWidget { - const PerformanceOptimizedScreen({Key? key}) : super(key: key); - - @override - Widget build(BuildContext context) { - final dataProvider = Provider.of(context); - - return Scaffold( - appBar: AppBar(title: const Text('性能优化示例')), - body: Column( - children: [ - Expanded( - child: ListView.builder( - itemCount: dataProvider.items.length + 1, // 包括加载更多项 - itemBuilder: (context, index) { - if (index == dataProvider.items.length) { - // 构建加载提示或完成消息 - return dataProvider.hasMore - ? const Padding( - padding: EdgeInsets.all(16.0), - child: Center(child: CircularProgressIndicator()), - ) - : const Padding( - padding: EdgeInsets.all(16.0), - child: Center(child: Text('没有更多数据了')), - ); - } - - // 构建普通列表项 - return ListTile( - title: Text(dataProvider.items[index]), - ); - }, - ), - ), - if (dataProvider.isLoading) Container(), - ], - ), - floatingActionButton: FloatingActionButton( - onPressed: dataProvider.loadNextPage, // 手动触发加载更多 - child: const Icon(Icons.add), - ), - ); - } -} - void main() { runApp(const OptimizedAppWithProvider()); } diff --git a/ohos/performance/list_view_demo/lib/performance_optimized_screen.dart b/ohos/performance/list_view_demo/lib/performance_optimized_screen.dart new file mode 100644 index 00000000..fe7dc4f8 --- /dev/null +++ b/ohos/performance/list_view_demo/lib/performance_optimized_screen.dart @@ -0,0 +1,102 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +import 'data_provider.dart'; +import 'product.dart'; + +/// 主屏幕:展示商品列表 +class PerformanceOptimizedScreen extends StatelessWidget { + const PerformanceOptimizedScreen({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + final dataProvider = Provider.of(context); + + return Scaffold( + appBar: AppBar(title: const Text('商品列表')), + body: Column( + children: [ + Expanded( + child: ListView.builder( + itemCount: dataProvider.products.length + 1, // 包括加载更多项 + itemBuilder: (context, index) { + if (index == dataProvider.products.length) { + // 构建加载提示或完成消息 + return dataProvider.hasMore + ? const Padding( + padding: EdgeInsets.all(16.0), + child: Center(child: CircularProgressIndicator()), + ) + : const Padding( + padding: EdgeInsets.all(16.0), + child: Center(child: Text('没有更多商品了')), + ); + } + + // 构建商品信息项 + return _buildProductItem(dataProvider.products[index]); + }, + ), + ), + if (dataProvider.isLoading) Container(), + ], + ), + floatingActionButton: FloatingActionButton( + onPressed: dataProvider.loadNextPage, // 手动触发加载更多 + child: const Icon(Icons.add), + ), + ); + } + + /// 构建商品列表项 + Widget _buildProductItem(Product product) { + return Card( + margin: const EdgeInsets.symmetric(vertical: 5, horizontal: 10), + elevation: 5, + shadowColor: Colors.grey.withOpacity(0.2), // 设置阴影颜色 + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10), // 圆角效果 + ), + child: Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + product.name, + style: const TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 8.0), + Text( + '价格:¥${product.price.toStringAsFixed(2)}', + style: const TextStyle(fontSize: 16, color: Colors.green), + ), + const SizedBox(height: 8.0), + Text( + product.description, + style: const TextStyle(fontSize: 14, color: Colors.grey), + ), + ], + ), + ), + ); + } +} diff --git a/ohos/performance/list_view_demo/lib/product.dart b/ohos/performance/list_view_demo/lib/product.dart new file mode 100644 index 00000000..926b4b2b --- /dev/null +++ b/ohos/performance/list_view_demo/lib/product.dart @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +///商品模型 +class Product { + final int id; + final String name; + final double price; + final String description; + // final String imageUrl; + // final bool inStock; + + Product({ + required this.id, + required this.name, + required this.price, + required this.description, + // required this.imageUrl, + // required this.inStock, + }); + + /// 从 JSON 创建商品对象 + factory Product.fromJson(Map json) { + return Product( + id: json['id'] as int, + name: json['name'] as String, + price: (json['price'] as num).toDouble(), + description: json['description'] as String, + // imageUrl: json['imageUrl'] as String, + // inStock: json['inStock'] as bool, + ); + } + + /// 转换商品对象为 JSON + Map toJson() { + return { + 'id': id, + 'name': name, + 'price': price, + 'description': description, + // 'imageUrl': imageUrl, + // 'inStock': inStock, + }; + } +} -- Gitee From 7108389998840f8fe85f606784d2d8144ba51cd0 Mon Sep 17 00:00:00 2001 From: SimpleLove520 <1960997571@qq.com> Date: Sat, 30 Nov 2024 17:05:29 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=89=88=E6=9D=83?= =?UTF-8?q?=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: SimpleLove520 <1960997571@qq.com> --- .../ets/plugins/GeneratedPluginRegistrant.ets | 15 +++++++++++++++ .../list_view_demo/test/widget_test.dart | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/ohos/performance/list_view_demo/ohos/entry/src/main/ets/plugins/GeneratedPluginRegistrant.ets b/ohos/performance/list_view_demo/ohos/entry/src/main/ets/plugins/GeneratedPluginRegistrant.ets index f28ced70..40f130cd 100644 --- a/ohos/performance/list_view_demo/ohos/entry/src/main/ets/plugins/GeneratedPluginRegistrant.ets +++ b/ohos/performance/list_view_demo/ohos/entry/src/main/ets/plugins/GeneratedPluginRegistrant.ets @@ -1,3 +1,18 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + import { FlutterEngine, Log } from '@ohos/flutter_ohos'; /** diff --git a/ohos/performance/list_view_demo/test/widget_test.dart b/ohos/performance/list_view_demo/test/widget_test.dart index a43d4bd5..23b2c631 100644 --- a/ohos/performance/list_view_demo/test/widget_test.dart +++ b/ohos/performance/list_view_demo/test/widget_test.dart @@ -1,3 +1,18 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + // This is a basic Flutter widget test. // // To perform an interaction with a widget in your test, use the WidgetTester -- Gitee