From 5806f35f54e20db49d42e3ce59f64009eda3b047 Mon Sep 17 00:00:00 2001 From: toly <1981462002@qq.com> Date: Sun, 29 Aug 2021 11:29:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=A9=BA=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/app/api/app_info.dart | 6 +- lib/app/api/category_api.dart | 10 +- .../res/style/shape/coupon_shape_border.dart | 20 +-- lib/app/res/style/shape/techno_shape.dart | 10 +- lib/app/router/router_utils.dart | 20 +-- lib/app/router/unit_router.dart | 6 +- lib/app/utils/Toast.dart | 4 +- lib/app/utils/http_utils/http_util.dart | 21 ++- .../utils/http_utils/logs_interceptor.dart | 30 ++-- lib/app/utils/http_utils/result_bean.dart | 6 +- .../utils/http_utils/token_interceptor.dart | 22 ++- lib/app/utils/stream_ext/backpressure.dart | 28 ++-- .../utils/stream_ext/forwarding_stream.dart | 8 +- lib/app/utils/stream_ext/timer_stream.dart | 10 +- lib/blocs/category/category_bloc.dart | 5 +- lib/blocs/category/category_event.dart | 34 +++-- .../category_widget/category_widget_bloc.dart | 2 +- lib/blocs/detail/detail_bloc.dart | 2 +- lib/blocs/detail/detail_state.dart | 2 +- lib/blocs/global/global_state.dart | 14 +- lib/blocs/like/like_bloc.dart | 2 +- lib/blocs/like/like_event.dart | 2 +- lib/blocs/like/like_state.dart | 2 +- lib/blocs/point/point_bloc.dart | 2 +- .../point_comment/point_comment_bloc.dart | 10 +- lib/blocs/search/search_bloc.dart | 4 +- lib/blocs/search/search_event.dart | 2 +- lib/blocs/widgets/widgets_bloc.dart | 2 +- lib/main.dart | 2 +- lib/model/category_model.dart | 26 ++-- lib/model/github/g/github_user.g.dart | 70 ++++----- lib/model/github/g/issue.g.dart | 20 +-- lib/model/github/g/issue_comment.g.dart | 12 +- lib/model/github/g/license.g.dart | 4 +- lib/model/github/g/repository.g.dart | 52 +++---- .../github/g/repository_permissions.g.dart | 6 +- lib/model/github/github_user.dart | 74 +++++----- lib/model/github/issue.dart | 32 ++--- lib/model/github/issue_comment.dart | 18 +-- lib/model/github/license.dart | 9 +- lib/model/github/repository.dart | 66 ++++----- lib/model/github/repository_permissions.dart | 6 +- lib/model/node_model.dart | 2 +- lib/model/widget_model.dart | 33 ++--- .../anim/bezier3_player/bezier3_palyer.dart | 6 +- .../anim/bezier3_player/touch_info.dart | 3 +- lib/painter_system/anim/circle_halo.dart | 4 +- .../anim/curve_shower/curve_anim_shower.dart | 4 +- lib/painter_system/anim/draw_path.dart | 6 +- lib/painter_system/anim/spring_widget.dart | 6 +- lib/painter_system/art/circle_packing.dart | 13 +- lib/painter_system/art/hypnotic_squares.dart | 2 +- lib/painter_system/art/joy_division.dart | 4 +- lib/painter_system/art/piet_mondrian.dart | 10 +- lib/painter_system/art/triangular_mesh.dart | 4 +- lib/painter_system/base/clock_widget.dart | 6 +- lib/painter_system/base/draw_picture.dart | 15 +- lib/painter_system/fun/stemp/stamp_data.dart | 28 ++-- lib/painter_system/fun/stemp/stamp_paper.dart | 4 +- lib/painter_system/gallery.dart | 4 +- lib/painter_system/gallery_detail_page.dart | 6 +- lib/painter_system/gallery_unit.dart | 15 +- lib/painter_system/particle/out/clock_fx.dart | 22 +-- .../particle/out/clock_widget.dart | 8 +- lib/painter_system/picture_frame.dart | 12 +- lib/painter_system/utils/coordinate.dart | 2 +- lib/repositories/bean/category_po.dart | 29 ++-- lib/repositories/bean/node_po.dart | 15 +- lib/repositories/bean/widget_po.dart | 19 +-- lib/repositories/dao/category_dao.dart | 4 +- lib/repositories/dao/like_dao.dart | 2 +- lib/repositories/local_db.dart | 22 +-- lib/repositories/local_storage.dart | 6 +- .../rep/impl/catagory_db_repository.dart | 4 +- .../rep/impl/widget_db_repository.dart | 6 +- lib/repositories/rep/widget_repository.dart | 2 +- lib/user_system/api/system_api.dart | 2 +- lib/user_system/api/user_api.dart | 4 +- lib/user_system/bloc/authentic/bloc.dart | 4 +- lib/user_system/bloc/authentic/event.dart | 2 +- lib/user_system/bloc/login/bloc.dart | 8 +- lib/user_system/bloc/login/event.dart | 2 +- lib/user_system/bloc/register/bloc.dart | 2 +- .../component/authentic_widget.dart | 2 +- lib/user_system/model/user.dart | 2 +- .../pages/register/arc_clipper.dart | 6 +- .../pages/register/register_page.dart | 2 +- lib/user_system/pages/register/send_code.dart | 8 +- .../components/drop_selectable_widget.dart | 18 +-- .../flutter/no_div_expansion_tile.dart | 33 +++-- .../components/permanent/burst_menu.dart | 60 ++++---- lib/views/components/permanent/circle.dart | 2 +- .../components/permanent/circle_image.dart | 8 +- .../components/permanent/circle_text.dart | 10 +- .../permanent/code/code_widget.dart | 4 +- .../permanent/code/high_light_code.dart | 64 +++++---- .../permanent/code/highlighter_style.dart | 18 +-- .../components/permanent/color_wrapper.dart | 8 +- .../components/permanent/edit_panel.dart | 12 +- .../components/permanent/feedback_widget.dart | 18 ++- .../components/permanent/icon_input.dart | 2 +- .../components/permanent/input_button.dart | 28 ++-- .../permanent/markdown/markdown_widget.dart | 10 +- .../markdown/syntax_high_lighter.dart | 88 ++++++------ .../components/permanent/math_runner.dart | 9 +- .../permanent/multi_chip_filter.dart | 6 +- lib/views/components/permanent/panel.dart | 6 +- lib/views/components/permanent/tag.dart | 2 +- .../components/permanent/text_typer.dart | 8 +- .../components/project/color_chooser.dart | 24 ++-- .../project/default/empty_shower.dart | 2 +- .../project/default/error_shower.dart | 2 +- .../project/default/loading_shower.dart | 2 +- .../dialogs/delete_category_dialog.dart | 2 +- .../project/items/category_list_item.dart | 14 +- .../items/collect_widget_list_item.dart | 10 +- .../items/gallery/gallery_card_item.dart | 11 +- .../items/widget/coupon_widget_list_item.dart | 6 +- .../items/widget/home_item_support.dart | 1 + .../items/widget/simple_widget_list_item.dart | 6 +- .../items/widget/techno_widget_list_item.dart | 6 +- .../project/nav/unit_bottom_bar.dart | 15 +- .../project/overlay_tool_wrapper.dart | 27 ++-- .../project/unit_drawer_header.dart | 2 +- .../components/project/widget_node_panel.dart | 14 +- .../project/wrapper/honour_wrapper.dart | 4 +- lib/views/pages/about/about_app_page.dart | 2 +- .../about/version/app_version_checker.dart | 20 +-- .../pages/about/version/version_shower.dart | 2 +- lib/views/pages/app/bloc_wrapper.dart | 2 +- lib/views/pages/app/unit_navigation.dart | 2 +- lib/views/pages/category/category_detail.dart | 8 +- lib/views/pages/category/category_page.dart | 4 +- lib/views/pages/category/collect_page.dart | 4 +- .../pages/category/edit_category_panel.dart | 24 ++-- .../pages/category/home_right_drawer.dart | 10 +- .../pages/category/sync/async_button.dart | 2 +- .../pages/data_manage/data_manage_page.dart | 2 +- lib/views/pages/gallery/gallery_page.dart | 4 +- lib/views/pages/issues_point/issue_item.dart | 10 +- .../pages/issues_point/issues_detail.dart | 28 ++-- .../pages/issues_point/issues_point_page.dart | 6 +- lib/views/pages/issues_point/repo_widget.dart | 10 +- .../pages/setting/code_style_setting.dart | 2 +- .../pages/setting/theme_color_setting.dart | 32 ++--- lib/views/pages/splash/flutter_unit_text.dart | 33 +++-- lib/views/pages/splash/unit_paint.dart | 12 +- lib/views/pages/splash/unit_splash.dart | 4 +- lib/views/pages/user/page_item.dart | 4 +- lib/views/pages/user/unit_drawer_header.dart | 2 +- .../widget_detail/category_end_drawer.dart | 6 +- .../widget_detail/widget_detail_page.dart | 6 +- lib/views/pages/widget_home/home_drawer.dart | 30 ++-- lib/views/pages/widget_home/home_page.dart | 8 +- lib/views/pages/widget_home/toly_app_bar.dart | 25 ++-- .../Flex/zz_node_play.dart | 8 +- .../Flow/node1_base.dart | 22 +-- .../Flow/node2_anim.dart | 30 ++-- .../Viewport/node1_base.dart | 2 +- .../Other/ListWheelViewport/node1_base.dart | 24 +++- .../ListWheelViewport/node2_perspective.dart | 54 ++++--- .../ListWheelViewport/node3_magnifier.dart | 25 +++- .../ListWheelViewport/node4_opacity.dart | 25 +++- .../widgets/Other/RawImage/node1_base.dart | 6 +- .../ProxyWidget/ChipTheme/node1_base.dart | 4 +- .../DefaultAssetBundle/node1_base.dart | 2 +- .../node1_base.dart | 12 +- .../InheritedWidget/node1_base.dart | 6 +- .../ProxyWidget/KeepAlive/node1_base.dart | 46 +++--- .../PrimaryScrollController/node1_base.dart | 2 +- .../ScrollConfiguration/node1_base.dart | 20 +-- .../ProxyWidget/SliderTheme/node2_diy.dart | 51 +++---- .../Align/node2_other.dart | 4 +- .../AnimatedSize/node1_base.dart | 2 +- .../ClipPath/node1_base.dart | 12 +- .../node1_base.dart | 5 +- .../CompositedTransformTarget/node1_base.dart | 4 +- .../CustomPaint/node1_clock.dart | 4 +- .../CustomPaint/node2_bezier.dart | 18 +-- .../CustomSingleChildLayout/node2_offset.dart | 4 +- .../FadeTransition/node1_base.dart | 3 +- .../RepaintBoundary/node1_base.dart | 18 +-- .../RepaintBoundary/node2_save.dart | 9 +- .../Transform/node1_skew.dart | 2 +- .../Transform/node2_translation.dart | 2 +- .../Transform/node3_scale.dart | 2 +- .../Transform/node4_rotate.dart | 4 +- .../Transform/node5_perspective.dart | 2 +- .../node1_base.dart | 22 +-- .../node1_base.dart | 24 ++-- .../Sliver/CustomScrollView/node1_base.dart | 20 +-- .../Sliver/FlexibleSpaceBar/node1_base.dart | 22 +-- .../Sliver/SliverAnimatedList/node1_base.dart | 38 +++-- .../Sliver/SliverAppBar/node1_base.dart | 23 ++- .../SliverFillRemaining/node1_base.dart | 24 ++-- .../Sliver/SliverFillViewport/node1_base.dart | 25 ++-- .../SliverFixedExtentList/node1_base.dart | 23 +-- .../SliverIgnorePointer/node1_base.dart | 25 ++-- .../SliverLayoutBuilder/node1_base.dart | 23 +-- .../widgets/Sliver/SliverList/node1_base.dart | 22 +-- .../SliverPersistentHeader/node1_base.dart | 28 ++-- .../SliverPrototypeExtentList.dart | 105 -------------- .../SliverPrototypeExtentList/node1_base.dart | 22 +-- .../Sliver/SliverToBoxAdapter/node1_base.dart | 22 +-- .../AlignTransition/node1_base.dart | 2 +- .../AnimatedAlign/node1_base.dart | 2 +- .../AnimatedBuilder/node1_base.dart | 2 +- .../AnimatedContainer/node1_base.dart | 6 +- .../AnimatedDefaultTextStyle/node1_base.dart | 2 +- .../AnimatedList/node1_base.dart | 42 +++--- .../AnimatedModalBarrier/node1_base.dart | 7 +- .../AnimatedPadding/node1_base.dart | 2 +- .../AnimatedTheme/node1_base.dart | 2 +- .../StatefulWidget/AppBar/node2_tab.dart | 4 +- .../AutomaticKeepAlive/node1_base.dart | 46 +++--- .../BottomNavigationBar/node2_page.dart | 2 +- .../StatefulWidget/Checkbox/node1_base.dart | 4 +- .../Checkbox/node2_tristate.dart | 6 +- .../CircularProgressIndicator/node1_base.dart | 2 +- .../CupertinoButton/node1_base.dart | 15 +- .../CupertinoScrollbar/node1_base.dart | 22 +-- .../node1_base.dart | 3 +- .../DecoratedBoxTransition/node1_base.dart | 2 +- .../DefaultTabController/node1_base.dart | 2 +- .../node1_base.dart | 2 +- .../Dismissible/node1_base.dart | 22 +-- .../Dismissible/node2_direction.dart | 22 +-- .../DraggableScrollableSheet/node1_base.dart | 42 +++--- .../DropdownButton/node1_base.dart | 2 +- .../DropdownButton/node2_style.dart | 10 +- .../DropdownButtonFormField/node1_base.dart | 16 ++- .../ExpansionPanelList/node1_base.dart | 22 +-- .../StatefulWidget/Form/node1_base.dart | 5 +- .../FutureBuilder/node1_base.dart | 4 +- .../node1_base.dart | 40 +++--- .../StatefulWidget/Hero/node1_base.dart | 8 +- .../InteractiveViewer/node3_controller.dart | 10 +- .../LinearProgressIndicator/node1_base.dart | 2 +- .../ListWheelScrollView/node1_base.dart | 22 +-- .../MergeableMaterial/node1_base.dart | 20 +-- .../StatefulWidget/Navigator/node1_base.dart | 18 +-- .../StatefulWidget/Overlay/node1_base.dart | 2 +- .../StatefulWidget/PageView/node1_base.dart | 22 +-- .../PageView/node2_direction.dart | 22 +-- .../PageView/node3_controller.dart | 24 ++-- .../PaginatedDataTable/node1_base.dart | 15 +- .../PositionedTransition/node1_base.dart | 2 +- .../StatefulWidget/Radio/node1_base.dart | 4 +- .../node1_base.dart | 16 ++- .../ReorderableListView/node1_base.dart | 23 +-- .../ReorderableListView/node2_direction.dart | 22 +-- .../RotationTransition/node1_base.dart | 24 +++- .../StatefulWidget/Scaffold/node1_base.dart | 6 +- .../ScaleTransition/node1_base.dart | 2 +- .../StatefulWidget/Scrollbar/node1_base.dart | 22 +-- .../SelectableText/node2_align.dart | 6 +- .../SizeTransition/node1_base.dart | 2 +- .../SlideTransition/node1_base.dart | 4 +- .../StatusTransitionWidget/node1_base.dart | 4 +- .../StatefulWidget/Stepper/node1_base.dart | 4 +- .../StatefulWidget/Stepper/node2_type.dart | 8 +- .../StatefulWidget/TabBarView/node1_base.dart | 2 +- .../StatefulWidget/TextField/node1_base.dart | 2 +- .../TextFormField/node1_base.dart | 7 +- .../TweenAnimationBuilder/node1_base.dart | 2 +- .../ValueListenableBuilder/node1_base.dart | 6 +- .../AnimatedIcon/node1_base.dart | 34 ++--- .../StatelessWidget/Banner/node1_base.dart | 40 ++---- .../BoxScrollView/node1_base.dart | 20 +-- .../StatelessWidget/Card/node2_shape.dart | 12 +- .../CupertinoTheme/node1_base.dart | 2 +- .../CupertinoTheme/node2_use.dart | 2 +- .../DataTable/node2_operation.dart | 6 +- .../StatelessWidget/Divider/node2_height.dart | 21 +-- .../node1_base.dart | 40 +++--- .../FadeInImage/node1_base.dart | 8 +- .../FilterChip/node1_base.dart | 4 +- .../FloatingActionButton/node3_shape.dart | 12 +- .../FlutterLogo/node2_style.dart | 19 +-- .../StatelessWidget/ListView/node1_base.dart | 22 +-- .../ListView/node2_direction.dart | 22 +-- .../ListView/node3_builder.dart | 22 +-- .../ListView/node4_separated.dart | 23 ++- .../PageStorage/node1_base.dart | 4 +- .../RadioListTile/node1_base.dart | 10 +- .../RadioListTile/node2_dense.dart | 35 +++-- .../ScrollView/node1_base.dart | 20 +-- .../SingleChildScrollView/node1_base.dart | 22 +-- .../node2_direction.dart | 22 +-- .../StatelessWidget/SnackBar/node1_base.dart | 2 +- .../StatelessWidget/TabBar/node1_base.dart | 2 +- .../TabBar/node2_noShadow.dart | 2 +- .../TabPageSelector/node1_base.dart | 2 +- .../StatelessWidget/Theme/node1_base.dart | 28 ++-- .../VerticalDivider/node2_height.dart | 4 +- plugins/install_plugin-2.0.1/.gitignore | 9 ++ plugins/install_plugin-2.0.1/.travis.yml | 19 +++ plugins/install_plugin-2.0.1/CHANGELOG.md | 31 ++++ plugins/install_plugin-2.0.1/LICENSE | 21 +++ plugins/install_plugin-2.0.1/README.md | 120 ++++++++++++++++ .../analysis_options.yaml | 11 ++ .../install_plugin-2.0.1/android/.gitignore | 8 ++ .../install_plugin-2.0.1/android/build.gradle | 46 ++++++ .../android/gradle.properties | 3 + .../android/settings.gradle | 1 + .../android/src/main/AndroidManifest.xml | 15 ++ .../com/zaihui/installplugin/InstallPlugin.kt | 134 ++++++++++++++++++ .../main/res/xml/provider_install_paths.xml | 6 + plugins/install_plugin-2.0.1/ios/.gitignore | 36 +++++ .../install_plugin-2.0.1/ios/Assets/.gitkeep | 0 .../ios/Classes/InstallPlugin.h | 4 + .../ios/Classes/InstallPlugin.m | 8 ++ .../ios/Classes/SwiftInstallPlugin.swift | 36 +++++ .../ios/install_plugin.podspec | 21 +++ .../lib/install_plugin.dart | 22 +++ plugins/install_plugin-2.0.1/pubspec.yaml | 24 ++++ .../test/install_plugin_test.dart | 45 ++++++ pubspec.lock | 30 ++-- pubspec.yaml | 27 ++-- 319 files changed, 2638 insertions(+), 2019 deletions(-) mode change 100755 => 100644 lib/app/utils/stream_ext/backpressure.dart mode change 100755 => 100644 lib/app/utils/stream_ext/forwarding_stream.dart delete mode 100644 lib/views/widgets/Sliver/SliverPrototypeExtentList/SliverPrototypeExtentList.dart create mode 100644 plugins/install_plugin-2.0.1/.gitignore create mode 100644 plugins/install_plugin-2.0.1/.travis.yml create mode 100644 plugins/install_plugin-2.0.1/CHANGELOG.md create mode 100644 plugins/install_plugin-2.0.1/LICENSE create mode 100644 plugins/install_plugin-2.0.1/README.md create mode 100644 plugins/install_plugin-2.0.1/analysis_options.yaml create mode 100644 plugins/install_plugin-2.0.1/android/.gitignore create mode 100644 plugins/install_plugin-2.0.1/android/build.gradle create mode 100644 plugins/install_plugin-2.0.1/android/gradle.properties create mode 100644 plugins/install_plugin-2.0.1/android/settings.gradle create mode 100644 plugins/install_plugin-2.0.1/android/src/main/AndroidManifest.xml create mode 100644 plugins/install_plugin-2.0.1/android/src/main/kotlin/com/zaihui/installplugin/InstallPlugin.kt create mode 100644 plugins/install_plugin-2.0.1/android/src/main/res/xml/provider_install_paths.xml create mode 100644 plugins/install_plugin-2.0.1/ios/.gitignore create mode 100644 plugins/install_plugin-2.0.1/ios/Assets/.gitkeep create mode 100644 plugins/install_plugin-2.0.1/ios/Classes/InstallPlugin.h create mode 100644 plugins/install_plugin-2.0.1/ios/Classes/InstallPlugin.m create mode 100644 plugins/install_plugin-2.0.1/ios/Classes/SwiftInstallPlugin.swift create mode 100644 plugins/install_plugin-2.0.1/ios/install_plugin.podspec create mode 100644 plugins/install_plugin-2.0.1/lib/install_plugin.dart create mode 100644 plugins/install_plugin-2.0.1/pubspec.yaml create mode 100644 plugins/install_plugin-2.0.1/test/install_plugin_test.dart diff --git a/lib/app/api/app_info.dart b/lib/app/api/app_info.dart index bb9bffb..777eea3 100644 --- a/lib/app/api/app_info.dart +++ b/lib/app/api/app_info.dart @@ -36,5 +36,9 @@ class AppInfo{ final String appVersion; final String appUrl; - AppInfo({this.appName, this.appVersion, this.appUrl}); + AppInfo({ + required this.appName, + required this.appVersion, + required this.appUrl, + }); } \ No newline at end of file diff --git a/lib/app/api/category_api.dart b/lib/app/api/category_api.dart index 93868d6..76eb094 100644 --- a/lib/app/api/category_api.dart +++ b/lib/app/api/category_api.dart @@ -8,13 +8,13 @@ import 'package:flutter_unit/app/utils/http_utils/result_bean.dart'; class CategoryApi { static Future> uploadCategoryData( - {String data, String likeData}) async { + {required String data, required String likeData}) async { String errorMsg = ""; var result = await HttpUtil.getInstance().client.post( PathUnit.categoryDataSync, data: {"data": data, "likeData": likeData}).catchError((err) { - errorMsg =err.toString(); + errorMsg = err.toString(); }); if (result.data != null) { @@ -54,7 +54,11 @@ class CategoryData{ final String data; final String likeData; - CategoryData({this.categoryDataId, this.userId, this.data, this.likeData}); + CategoryData( + {required this.categoryDataId, + required this.userId, + required this.data, + required this.likeData}); factory CategoryData.fromJson(Map map) { return CategoryData( diff --git a/lib/app/res/style/shape/coupon_shape_border.dart b/lib/app/res/style/shape/coupon_shape_border.dart index 4b6831f..7278b48 100644 --- a/lib/app/res/style/shape/coupon_shape_border.dart +++ b/lib/app/res/style/shape/coupon_shape_border.dart @@ -14,7 +14,7 @@ class CouponShapeBorder extends ShapeBorder { final Color color; final bool hasTopHole; final bool hasBottomHole; - final double edgeRadius; + final double? edgeRadius; CouponShapeBorder( {this.holeCount = 6, @@ -26,15 +26,15 @@ class CouponShapeBorder extends ShapeBorder { this.color = Colors.white,this.edgeRadius}); @override - EdgeInsetsGeometry get dimensions => null; + EdgeInsetsGeometry get dimensions => EdgeInsets.zero; @override - Path getInnerPath(Rect rect, {TextDirection textDirection}) { - return null; + Path getInnerPath(Rect rect, {TextDirection? textDirection}) { + return Path(); } @override - Path getOuterPath(Rect rect, {TextDirection textDirection}) { + Path getOuterPath(Rect rect, {TextDirection? textDirection}) { double w = rect.width; double h = rect.height; @@ -52,10 +52,10 @@ class CouponShapeBorder extends ShapeBorder { } if(edgeRadius!=null){ if(hasTopHole){ - _formHoleTop(path, rect, edgeRadius); + _formHoleTop(path, rect, edgeRadius!); } if(hasBottomHole){ - _formHoleBottom(path, rect, edgeRadius); + _formHoleBottom(path, rect, edgeRadius!); } } @@ -103,7 +103,7 @@ class CouponShapeBorder extends ShapeBorder { } @override - void paint(Canvas canvas, Rect rect, {TextDirection textDirection}) { + void paint(Canvas canvas, Rect rect, {TextDirection? textDirection}) { if(!hasLine) return; Paint paint = Paint() ..color = color @@ -131,7 +131,7 @@ class CouponShapeBorder extends ShapeBorder { @override ShapeBorder scale(double t) { - // TODO: implement scale - return null; + + return this; } } diff --git a/lib/app/res/style/shape/techno_shape.dart b/lib/app/res/style/shape/techno_shape.dart index ab1c329..d9b8eb5 100644 --- a/lib/app/res/style/shape/techno_shape.dart +++ b/lib/app/res/style/shape/techno_shape.dart @@ -32,17 +32,17 @@ class TechnoShapeBorder extends ShapeBorder { } @override - EdgeInsetsGeometry get dimensions => null; + EdgeInsetsGeometry get dimensions => EdgeInsets.zero; @override - Path getInnerPath(Rect rect, {TextDirection textDirection}) { + Path getInnerPath(Rect rect, {TextDirection? textDirection}) { Path path = Path(); path.addRRect(RRect.fromRectAndRadius(rect, Radius.circular(5))); return path; } @override - Path getOuterPath(Rect rect, {TextDirection textDirection}) { + Path getOuterPath(Rect rect, {TextDirection? textDirection}) { double width = rect.width; outLinePath @@ -64,7 +64,7 @@ class TechnoShapeBorder extends ShapeBorder { } @override - void paint(Canvas canvas, Rect rect, {TextDirection textDirection}) { + void paint(Canvas canvas, Rect rect, {TextDirection? textDirection}) { canvas.drawPath( outLinePath, _paint..style = PaintingStyle.stroke); @@ -81,6 +81,6 @@ class TechnoShapeBorder extends ShapeBorder { @override ShapeBorder scale(double t) { - return null; + return this; } } diff --git a/lib/app/router/router_utils.dart b/lib/app/router/router_utils.dart index 9bce89c..0370ece 100644 --- a/lib/app/router/router_utils.dart +++ b/lib/app/router/router_utils.dart @@ -5,7 +5,7 @@ class ScaleRouter extends PageRouteBuilder { final Widget child; final int durationMs; final Curve curve; - ScaleRouter({this.child, this.durationMs = 500,this.curve=Curves.fastOutSlowIn}) + ScaleRouter({required this.child, this.durationMs = 500,this.curve=Curves.fastOutSlowIn}) : super( pageBuilder: (context, animation, secondaryAnimation) => child, transitionDuration: Duration(milliseconds: durationMs), @@ -22,7 +22,7 @@ class FadeRouter extends PageRouteBuilder { final Widget child; final int durationMs; final Curve curve; - FadeRouter({this.child, this.durationMs = 500,this.curve=Curves.fastOutSlowIn}) + FadeRouter({required this.child, this.durationMs = 500,this.curve=Curves.fastOutSlowIn}) : super( pageBuilder: (context, animation, secondaryAnimation) => child, transitionDuration: Duration(milliseconds: durationMs), @@ -39,7 +39,7 @@ class RotateRouter extends PageRouteBuilder { final Widget child; final int durationMs; final Curve curve; - RotateRouter({this.child, this.durationMs = 500,this.curve=Curves.fastOutSlowIn}) + RotateRouter({required this.child, this.durationMs = 500,this.curve=Curves.fastOutSlowIn}) : super( pageBuilder: (context, animation, secondaryAnimation) => child, transitionDuration: Duration(milliseconds: durationMs), @@ -56,7 +56,7 @@ class Right2LeftRouter extends PageRouteBuilder { final Widget child; final int durationMs; final Curve curve; - Right2LeftRouter({this.child,this.durationMs=500,this.curve=Curves.fastOutSlowIn}) + Right2LeftRouter({required this.child,this.durationMs=500,this.curve=Curves.fastOutSlowIn}) :super( transitionDuration:Duration(milliseconds: durationMs), pageBuilder:(ctx,a1,a2)=>child, @@ -74,8 +74,8 @@ class Left2RightRouter extends PageRouteBuilder { final Widget child; final int durationMs; final Curve curve; - List mapper; - Left2RightRouter({this.child,this.durationMs=500,this.curve=Curves.fastOutSlowIn}) + + Left2RightRouter({required this.child,this.durationMs=500,this.curve=Curves.fastOutSlowIn}) :assert(true),super( transitionDuration:Duration(milliseconds: durationMs), pageBuilder:(ctx,a1,a2){return child;}, @@ -94,7 +94,7 @@ class Top2BottomRouter extends PageRouteBuilder { final Widget child; final int durationMs; final Curve curve; - Top2BottomRouter({this.child,this.durationMs=500,this.curve=Curves.fastOutSlowIn}) + Top2BottomRouter({required this.child,this.durationMs=500,this.curve=Curves.fastOutSlowIn}) :super( transitionDuration:Duration(milliseconds: durationMs), pageBuilder:(ctx,a1,a2){return child;}, @@ -113,7 +113,7 @@ class Bottom2TopRouter extends PageRouteBuilder { final Widget child; final int durationMs; final Curve curve; - Bottom2TopRouter({this.child,this.durationMs=500,this.curve=Curves.fastOutSlowIn}) + Bottom2TopRouter({required this.child,this.durationMs=500,this.curve=Curves.fastOutSlowIn}) :super( transitionDuration:Duration(milliseconds: durationMs), pageBuilder:(ctx,a1,a2)=> child, @@ -132,7 +132,7 @@ class ScaleFadeRotateRouter extends PageRouteBuilder { final Widget child; final int durationMs; final Curve curve; - ScaleFadeRotateRouter({this.child, this.durationMs = 1000,this.curve=Curves.fastOutSlowIn}) : super( + ScaleFadeRotateRouter({required this.child, this.durationMs = 1000,this.curve=Curves.fastOutSlowIn}) : super( transitionDuration: Duration(milliseconds: durationMs), pageBuilder: (ctx, a1, a2)=>child,//页面 transitionsBuilder: (ctx, a1, a2, Widget child,) => @@ -153,7 +153,7 @@ class ScaleFadeRotateRouter extends PageRouteBuilder { //无动画 class NoAnimRouter extends PageRouteBuilder { final Widget child; - NoAnimRouter({this.child}) + NoAnimRouter({required this.child}) : super( opaque: false, pageBuilder: (context, animation, secondaryAnimation) => child, diff --git a/lib/app/router/unit_router.dart b/lib/app/router/unit_router.dart index 0836a5c..a47ecab 100644 --- a/lib/app/router/unit_router.dart +++ b/lib/app/router/unit_router.dart @@ -1,4 +1,6 @@ import 'package:flutter/material.dart'; +import 'package:flutter_unit/model/category_model.dart'; +import 'package:flutter_unit/model/widget_model.dart'; import 'package:flutter_unit/views/pages/app/unit_navigation.dart'; import 'package:flutter_unit/views/pages/about/about_me_page.dart'; import 'package:flutter_unit/views/pages/about/about_app_page.dart'; @@ -66,7 +68,7 @@ class UnitRouter { // 组件详情页 case widget_detail: return Right2LeftRouter( - child: WidgetDetailPage(model: settings.arguments)); + child: WidgetDetailPage(model: settings.arguments as WidgetModel)); case search: return Right2LeftRouter(child: SearchPage()); @@ -119,7 +121,7 @@ class UnitRouter { case category_show: return Right2LeftRouter( child: CategoryShow( - model: settings.arguments, + model: settings.arguments as CategoryModel, )); default: diff --git a/lib/app/utils/Toast.dart b/lib/app/utils/Toast.dart index c353721..032ffbb 100644 --- a/lib/app/utils/Toast.dart +++ b/lib/app/utils/Toast.dart @@ -4,8 +4,8 @@ import 'package:flutter/material.dart'; class Toast { static toast(BuildContext context, String msg, {duration = const Duration(milliseconds: 600), - Color color, - SnackBarAction action}) { + Color? color, + SnackBarAction? action}) { Scaffold.of(context).showSnackBar(SnackBar( content: Text(msg), diff --git a/lib/app/utils/http_utils/http_util.dart b/lib/app/utils/http_utils/http_util.dart index 41bbec7..4ae2b52 100644 --- a/lib/app/utils/http_utils/http_util.dart +++ b/lib/app/utils/http_utils/http_util.dart @@ -11,16 +11,13 @@ const int _kConnectTimeout = 5000; class HttpUtil { static HttpUtil _instance = HttpUtil._internal(); - Dio _dio; - - - + Dio? _dio; static const CODE_SUCCESS = 200; static const CODE_TIME_OUT = -1; factory HttpUtil() => _instance; - TokenInterceptors tokenInterceptors; + TokenInterceptors? tokenInterceptors; ///通用全局单例,第一次使用时初始化 HttpUtil._internal() { @@ -31,7 +28,7 @@ class HttpUtil { receiveTimeout: _kConnectTimeout, sendTimeout: _kSendTimeout, )); - _dio.interceptors.add(LogsInterceptors()); + _dio!.interceptors.add(LogsInterceptors()); // _dio.interceptors.add(ResponseInterceptors()); } } @@ -41,26 +38,26 @@ class HttpUtil { } - Dio get client => _dio; + Dio get client => _dio!; void setToken(String token){ print('---token---$token-------'); tokenInterceptors = TokenInterceptors(token: token); - _dio.interceptors.add(tokenInterceptors); + _dio!.interceptors.add(tokenInterceptors!); } void deleteToken(){ - _dio.interceptors.remove(tokenInterceptors); + _dio!.interceptors.remove(tokenInterceptors); } void rebase(String baseIp) { - _dio.options.baseUrl = baseIp; + _dio!.options.baseUrl = baseIp; } //一般请求,默认域名 HttpUtil _default() { if (_dio != null) { - _dio.options.baseUrl=PathUnit.baseUrl; - _dio.options.headers = {}; + _dio!.options.baseUrl=PathUnit.baseUrl; + _dio!.options.headers = {}; } return this; } diff --git a/lib/app/utils/http_utils/logs_interceptor.dart b/lib/app/utils/http_utils/logs_interceptor.dart index 56d414e..18d3192 100644 --- a/lib/app/utils/http_utils/logs_interceptor.dart +++ b/lib/app/utils/http_utils/logs_interceptor.dart @@ -1,30 +1,32 @@ import 'package:dio/dio.dart'; class LogsInterceptors extends InterceptorsWrapper { + @override - onRequest(RequestOptions options) async{ + void onRequest(RequestOptions options, RequestInterceptorHandler handler) { // print("==========请求baseUrl:${options.baseUrl} =========="); // print("==========请求url:${options.path} =========="); // print('==========请求头: ' + options.headers.toString()+"=========="); // if (options.data != null) { // print('==========请求参数: ' + options.data.toString()+"=========="); // } - return options; + return handler.next(options); } @override - onResponse(Response response)async { - if (response != null) { - // var responseStr = response.toString(); - } - - return response; // continue - } - - @override - onError(DioError err) async{ + void onError(DioError err, ErrorInterceptorHandler handler) { print('==========请求异常: ' + err.toString()+"=========="); - print('==========请求异常信息: ' + err.response?.toString()+"==========" ?? "=========="); - return err; + if(err.response!=null){ + print('==========请求异常信息: ' + err.response.toString()+"=========="); + } + return handler.next(err); + } + + @override + void onResponse(Response response, ResponseInterceptorHandler handler) { + if (response != null) { + var responseStr = response.toString(); + } + return handler.next(response); // continue } } \ No newline at end of file diff --git a/lib/app/utils/http_utils/result_bean.dart b/lib/app/utils/http_utils/result_bean.dart index 545bfa9..5f3bdeb 100644 --- a/lib/app/utils/http_utils/result_bean.dart +++ b/lib/app/utils/http_utils/result_bean.dart @@ -1,9 +1,9 @@ class ResultBean { - T data; + T? data; bool status; String msg; - ResultBean({this.data, this.status, this.msg}); + ResultBean({this.data, this.status=false, this.msg=''}); @override String toString() { @@ -26,7 +26,7 @@ class ResultBean { ); } - static ResultBean ok(T data) { + static ResultBean ok(T? data) { return ResultBean( msg: '请求成功', data: data, diff --git a/lib/app/utils/http_utils/token_interceptor.dart b/lib/app/utils/http_utils/token_interceptor.dart index 398ae7f..a14c177 100644 --- a/lib/app/utils/http_utils/token_interceptor.dart +++ b/lib/app/utils/http_utils/token_interceptor.dart @@ -1,21 +1,29 @@ import 'package:dio/dio.dart'; +import 'package:jwt_decoder/jwt_decoder.dart'; const String _kTokenKey = 'Authorization'; const String _kTokenPrefix = 'Bearer '; class TokenInterceptors extends InterceptorsWrapper { - String token; + TokenInterceptors({this.token = ''}); - TokenInterceptors({this.token=''}); + void Function()? onTokenDisabled; @override - Future onRequest(RequestOptions options) async{ - // print('----RequestOptions---${options.path}------------'); - if(token.isNotEmpty){ + void onRequest(RequestOptions options, RequestInterceptorHandler handler) { + if (token != '') { + bool disable = JwtDecoder.isExpired(token); + if (disable) { + onTokenDisabled?.call(); + } + } + if (token != null&&token.isNotEmpty) { options.headers[_kTokenKey] = '$_kTokenPrefix$token'; } - return options; + return handler.next(options); } -} + + +} \ No newline at end of file diff --git a/lib/app/utils/stream_ext/backpressure.dart b/lib/app/utils/stream_ext/backpressure.dart old mode 100755 new mode 100644 index 29bebe9..f214b32 --- a/lib/app/utils/stream_ext/backpressure.dart +++ b/lib/app/utils/stream_ext/backpressure.dart @@ -59,17 +59,17 @@ enum WindowStrategy { class _BackpressureStreamSink implements ForwardingSink { final WindowStrategy _strategy; - final Stream Function(S event) _windowStreamFactory; - final T Function(S event) _onWindowStart; - final T Function(List queue) _onWindowEnd; + final Stream Function(S event)? _windowStreamFactory; + final T Function(S event)? _onWindowStart; + final T Function(List queue)? _onWindowEnd; final int _startBufferEvery; - final bool Function(List queue) _closeWindowWhen; + final bool Function(List queue)? _closeWindowWhen; final bool _ignoreEmptyWindows; final bool _dispatchOnClose; final queue = []; var skip = 0; var _hasData = false; - StreamSubscription _windowSubscription; + StreamSubscription? _windowSubscription; _BackpressureStreamSink( this._strategy, @@ -98,7 +98,7 @@ class _BackpressureStreamSink implements ForwardingSink { } @override - void addError(EventSink sink, dynamic e, [st]) => sink.addError(e, st); + void addError(EventSink sink, dynamic e, [StackTrace? st]) => sink.addError(e, st); @override void close(EventSink sink) { @@ -123,7 +123,7 @@ class _BackpressureStreamSink implements ForwardingSink { void onListen(EventSink sink) {} @override - void onPause(EventSink sink, [Future resumeSignal]) => + void onPause(EventSink sink, [Future? resumeSignal]) => _windowSubscription?.pause(resumeSignal); @override @@ -165,7 +165,7 @@ class _BackpressureStreamSink implements ForwardingSink { void maybeCloseWindow(EventSink sink) { if (_closeWindowWhen != null && - _closeWindowWhen(UnmodifiableListView(queue))) { + _closeWindowWhen!(UnmodifiableListView(queue))) { resolveWindowEnd(sink); } } @@ -191,7 +191,7 @@ class _BackpressureStreamSink implements ForwardingSink { _windowSubscription?.cancel(); - stream = _windowStreamFactory(event); + stream = _windowStreamFactory!(event); if (stream == null) { sink.addError(ArgumentError.notNull('windowStreamFactory')); @@ -202,7 +202,7 @@ class _BackpressureStreamSink implements ForwardingSink { void resolveWindowStart(S event, EventSink sink) { if (_onWindowStart != null) { - sink.add(_onWindowStart(event)); + sink.add(_onWindowStart!(event)); } } @@ -220,7 +220,7 @@ class _BackpressureStreamSink implements ForwardingSink { if (_hasData && (queue.isNotEmpty || !_ignoreEmptyWindows)) { if (_onWindowEnd != null) { - sink.add(_onWindowEnd(List.unmodifiable(queue))); + sink.add(_onWindowEnd!(List.unmodifiable(queue))); } // prepare the buffer for the next window. @@ -304,16 +304,16 @@ class BackpressureStreamTransformer extends StreamTransformerBase { final Stream Function(S event) windowStreamFactory; /// Handler which fires when the window opens - final T Function(S event) onWindowStart; + final T Function(S event)? onWindowStart; /// Handler which fires when the window closes - final T Function(List queue) onWindowEnd; + final T Function(List queue)? onWindowEnd; /// Used to skip an amount of events final int startBufferEvery; /// Predicate which determines when the current window should close - final bool Function(List queue) closeWindowWhen; + final bool Function(List queue)? closeWindowWhen; /// Toggle to prevent, or allow windows that contain /// no events to be dispatched diff --git a/lib/app/utils/stream_ext/forwarding_stream.dart b/lib/app/utils/stream_ext/forwarding_stream.dart old mode 100755 new mode 100644 index 6c46812..1474f02 --- a/lib/app/utils/stream_ext/forwarding_stream.dart +++ b/lib/app/utils/stream_ext/forwarding_stream.dart @@ -18,8 +18,8 @@ Stream forwardStream( ArgumentError.checkNotNull(stream, 'stream'); ArgumentError.checkNotNull(connectedSink, 'connectedSink'); - StreamController controller; - StreamSubscription subscription; + late StreamController controller; + late StreamSubscription subscription; void runCatching(void Function() block) { try { @@ -50,9 +50,9 @@ Stream forwardStream( return Future.wait(futures); }; - final onPause = ([Future resumeSignal]) { + final onPause = ([Future? resumeSignal]) { subscription.pause(resumeSignal); - runCatching(() => connectedSink.onPause(controller, resumeSignal)); + runCatching(() => connectedSink.onPause(controller, resumeSignal!)); }; final onResume = () { diff --git a/lib/app/utils/stream_ext/timer_stream.dart b/lib/app/utils/stream_ext/timer_stream.dart index be2ea0b..5d7ac42 100644 --- a/lib/app/utils/stream_ext/timer_stream.dart +++ b/lib/app/utils/stream_ext/timer_stream.dart @@ -14,8 +14,8 @@ class TimerStream extends Stream { : _controller = _buildController(value, duration); @override - StreamSubscription listen(void Function(T event) onData, - {Function onError, void Function() onDone, bool cancelOnError}) { + StreamSubscription listen(void Function(T event)? onData, + {Function? onError, void Function()? onDone, bool? cancelOnError}) { return _controller.stream.listen( onData, onError: onError, @@ -29,8 +29,8 @@ class TimerStream extends Stream { throw ArgumentError('duration cannot be null'); } - StreamSubscription subscription; - StreamController controller; + late StreamSubscription subscription; + late StreamController controller; controller = StreamController( sync: true, @@ -46,7 +46,7 @@ class TimerStream extends Stream { }, ); }, - onPause: ([Future resumeSignal]) => + onPause: ([Future? resumeSignal]) => subscription.pause(resumeSignal), onResume: () => subscription.resume(), onCancel: () => subscription.cancel(), diff --git a/lib/blocs/category/category_bloc.dart b/lib/blocs/category/category_bloc.dart index f8ef1b8..7b0b917 100644 --- a/lib/blocs/category/category_bloc.dart +++ b/lib/blocs/category/category_bloc.dart @@ -17,7 +17,7 @@ import 'category_state.dart'; class CategoryBloc extends Bloc { final CategoryRepository repository; - CategoryBloc({@required this.repository}) : super(const CategoryLoadingState()); + CategoryBloc({required this.repository}) : super(const CategoryLoadingState()); @override Stream mapEventToState(CategoryEvent event) async* { @@ -66,6 +66,7 @@ class CategoryBloc extends Bloc { priority: event.priority ?? 0, image: event.image ?? '', color: event.color ?? + ColorUtils.colorString(UnitColor.collectColorSupport[0]), info: event.info ?? '这里什么都没有...', updated: DateTime.now()); @@ -86,7 +87,7 @@ class CategoryBloc extends Bloc { if(state is CategoryLoadedState){ return (state as CategoryLoadedState).categories; }else{ - return null; + return []; } } } diff --git a/lib/blocs/category/category_event.dart b/lib/blocs/category/category_event.dart index 8d95d8a..9715477 100644 --- a/lib/blocs/category/category_event.dart +++ b/lib/blocs/category/category_event.dart @@ -1,5 +1,4 @@ import 'package:equatable/equatable.dart'; -import 'package:flutter/material.dart'; /// create by 张风捷特烈 on 2020-04-21 /// contact me by email 1981462002@qq.com @@ -8,7 +7,7 @@ import 'package:flutter/material.dart'; abstract class CategoryEvent extends Equatable{ const CategoryEvent(); @override - List get props => []; + List get props => []; } // 加载 收藏集 事件 class EventLoadCategory extends CategoryEvent{ @@ -21,7 +20,7 @@ class EventLoadCategory extends CategoryEvent{ class EventToggleWidget extends CategoryEvent{ final int widgetId; final int categoryId; - const EventToggleWidget({this.widgetId, this.categoryId}); + const EventToggleWidget({required this.widgetId, required this.categoryId}); @override List get props => [widgetId,categoryId]; @@ -31,7 +30,7 @@ class EventToggleWidget extends CategoryEvent{ class EventDeleteCategory extends CategoryEvent{ final int id; - const EventDeleteCategory({@required this.id}); + const EventDeleteCategory({required this.id}); @override List get props => [id]; @@ -40,26 +39,33 @@ class EventDeleteCategory extends CategoryEvent{ // 添加 收藏集 class EventAddCategory extends CategoryEvent{ final String name; - final String info; - final String color; + final String? info; + final String? color; - const EventAddCategory({@required this.name, this.info, this.color}); + const EventAddCategory( + {required this.name, required this.info, required this.color}); @override - List get props => [name,info,color]; + List get props => [name, info, color]; } // 更新 收藏集 class EventUpdateCategory extends CategoryEvent { final int id; final String name; - final String info; - final String color; - final int priority; - final String image; + final String? info; + final String? color; + final int? priority; + final String? image; - const EventUpdateCategory({@required this.name, this.info, this.color,this.priority,this.image,this.id}); + const EventUpdateCategory( + {required this.name, + required this.info, + required this.color, + this.priority, + this.image, + required this.id}); @override - List get props => [name, info, color,priority,image,id]; + List get props => [name, info, color, priority, image, id]; } \ No newline at end of file diff --git a/lib/blocs/category_widget/category_widget_bloc.dart b/lib/blocs/category_widget/category_widget_bloc.dart index de5ee92..4490d0c 100644 --- a/lib/blocs/category_widget/category_widget_bloc.dart +++ b/lib/blocs/category_widget/category_widget_bloc.dart @@ -15,7 +15,7 @@ class CategoryWidgetBloc extends Bloc { final CategoryBloc categoryBloc; - CategoryWidgetBloc({@required this.categoryBloc}) + CategoryWidgetBloc({required this.categoryBloc}) : super(CategoryWidgetEmptyState()); CategoryRepository get repository => categoryBloc.repository; diff --git a/lib/blocs/detail/detail_bloc.dart b/lib/blocs/detail/detail_bloc.dart index c477b7b..c7dfa65 100644 --- a/lib/blocs/detail/detail_bloc.dart +++ b/lib/blocs/detail/detail_bloc.dart @@ -13,7 +13,7 @@ import 'detail_state.dart'; class DetailBloc extends Bloc { final WidgetRepository repository; - DetailBloc({@required this.repository}):super(DetailLoading()); + DetailBloc({required this.repository}):super(DetailLoading()); @override diff --git a/lib/blocs/detail/detail_state.dart b/lib/blocs/detail/detail_state.dart index 6513557..ca0e835 100644 --- a/lib/blocs/detail/detail_state.dart +++ b/lib/blocs/detail/detail_state.dart @@ -19,7 +19,7 @@ class DetailWithData extends DetailState { final List links; final List nodes; - const DetailWithData({this.widgetModel, this.nodes,this.links}); + const DetailWithData({required this.widgetModel,required this.nodes,required this.links}); @override List get props => [widgetModel,nodes]; diff --git a/lib/blocs/global/global_state.dart b/lib/blocs/global/global_state.dart index 8d39f0a..1ca928a 100644 --- a/lib/blocs/global/global_state.dart +++ b/lib/blocs/global/global_state.dart @@ -43,13 +43,13 @@ class GlobalState extends Equatable { ]; GlobalState copyWith({ - double height, - String fontFamily, - MaterialColor themeColor, - bool showBackGround, - int codeStyleIndex, - int itemStyleIndex, - bool showPerformanceOverlay, + double? height, + String? fontFamily, + MaterialColor? themeColor, + bool? showBackGround, + int? codeStyleIndex, + int? itemStyleIndex, + bool? showPerformanceOverlay, }) => GlobalState( fontFamily: fontFamily ?? this.fontFamily, diff --git a/lib/blocs/like/like_bloc.dart b/lib/blocs/like/like_bloc.dart index 2072b76..d830657 100644 --- a/lib/blocs/like/like_bloc.dart +++ b/lib/blocs/like/like_bloc.dart @@ -13,7 +13,7 @@ import 'like_state.dart'; class LikeWidgetBloc extends Bloc { final WidgetRepository repository; - LikeWidgetBloc({@required this.repository}):super(LikeWidgetState(widgets: [])); + LikeWidgetBloc({required this.repository}):super(LikeWidgetState(widgets: [])); @override diff --git a/lib/blocs/like/like_event.dart b/lib/blocs/like/like_event.dart index 6a0c8e6..8593aad 100644 --- a/lib/blocs/like/like_event.dart +++ b/lib/blocs/like/like_event.dart @@ -13,7 +13,7 @@ class EventLoadLikeData extends LikeWidgetEvent { class ToggleLikeWidgetEvent extends LikeWidgetEvent { final int id; - ToggleLikeWidgetEvent({this.id}); + ToggleLikeWidgetEvent({required this.id}); @override // TODO: implement props diff --git a/lib/blocs/like/like_state.dart b/lib/blocs/like/like_state.dart index e4344ee..5c5ff5d 100644 --- a/lib/blocs/like/like_state.dart +++ b/lib/blocs/like/like_state.dart @@ -8,7 +8,7 @@ import 'package:flutter_unit/model/widget_model.dart'; class LikeWidgetState extends Equatable { final List widgets; - LikeWidgetState({this.widgets}); + LikeWidgetState({required this.widgets}); @override // TODO: implement props diff --git a/lib/blocs/point/point_bloc.dart b/lib/blocs/point/point_bloc.dart index 5014963..b1a6516 100644 --- a/lib/blocs/point/point_bloc.dart +++ b/lib/blocs/point/point_bloc.dart @@ -29,7 +29,7 @@ class PointBloc extends Bloc { yield PointLoaded(issues); } catch (err) { print(err); - yield PointLoadFailure(err); + yield PointLoadFailure(err.toString()); } } } diff --git a/lib/blocs/point_comment/point_comment_bloc.dart b/lib/blocs/point_comment/point_comment_bloc.dart index b07e160..3274d7d 100644 --- a/lib/blocs/point_comment/point_comment_bloc.dart +++ b/lib/blocs/point_comment/point_comment_bloc.dart @@ -1,6 +1,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_unit/app/api/issues_api.dart'; +import 'package:flutter_unit/model/github/issue_comment.dart'; import 'point_comment_event.dart'; @@ -26,13 +27,16 @@ class PointCommentBloc extends Bloc { Stream _mapLoadWidgetToState(EventLoadPointComment event) async* { yield PointCommentLoading(event.point); + if(event.point.number==null){ + yield PointCommentLoadFailure('point id 为空'); + } try { - final comments = await IssuesApi.getIssuesComment(event.point.number); - comments.sort((a,b)=>a.createdAt.compareTo(b.createdAt)); + final List comments = await IssuesApi.getIssuesComment(event.point.number!); + comments.sort((a,b)=>a.createdAt!.compareTo(b.createdAt!)); yield PointCommentLoaded(event.point,comments); } catch (err) { print(err); - yield PointCommentLoadFailure(err); + yield PointCommentLoadFailure(err.toString()); } } } diff --git a/lib/blocs/search/search_bloc.dart b/lib/blocs/search/search_bloc.dart index 27309f7..2e7981a 100644 --- a/lib/blocs/search/search_bloc.dart +++ b/lib/blocs/search/search_bloc.dart @@ -10,14 +10,14 @@ import 'package:flutter_unit/app/utils/stream_ext/ext.dart'; class SearchBloc extends Bloc { final WidgetRepository repository; - SearchBloc({@required this.repository}):super(SearchStateNoSearch()); + SearchBloc({required this.repository}):super(SearchStateNoSearch()); @override Stream> transformEvents( Stream events, TransitionFunction transitionFn) { return super.transformEvents(events - .debounceTime(Duration(milliseconds: 500),), + .debounceTime(const Duration(milliseconds: 500),), transitionFn, ); } diff --git a/lib/blocs/search/search_event.dart b/lib/blocs/search/search_event.dart index c14bff1..bd08586 100644 --- a/lib/blocs/search/search_event.dart +++ b/lib/blocs/search/search_event.dart @@ -7,5 +7,5 @@ abstract class SearchEvent{//事件基 class SearchWidgetEvent extends SearchEvent { final SearchArgs args;//参数 - const SearchWidgetEvent({this.args}); + const SearchWidgetEvent({required this.args}); } diff --git a/lib/blocs/widgets/widgets_bloc.dart b/lib/blocs/widgets/widgets_bloc.dart index d624c23..32998c2 100644 --- a/lib/blocs/widgets/widgets_bloc.dart +++ b/lib/blocs/widgets/widgets_bloc.dart @@ -15,7 +15,7 @@ import 'widgets_state.dart'; class WidgetsBloc extends Bloc { final WidgetRepository repository; - WidgetsBloc({@required this.repository}):super(WidgetsLoading(WidgetFamily.statelessWidget)); + WidgetsBloc({required this.repository}):super(WidgetsLoading(WidgetFamily.statelessWidget)); diff --git a/lib/main.dart b/lib/main.dart index 95bab34..d96bc24 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -6,7 +6,7 @@ import 'views/pages/app/flutter_unit.dart'; void main() { WidgetsFlutterBinding.ensureInitialized(); //滚动性能优化 1.22.0 - GestureBinding.instance.resamplingEnabled = true; + GestureBinding.instance?.resamplingEnabled = true; runApp(BlocWrapper(child: FlutterUnit())); } diff --git a/lib/model/category_model.dart b/lib/model/category_model.dart index da1f3ef..54d42ee 100644 --- a/lib/model/category_model.dart +++ b/lib/model/category_model.dart @@ -9,31 +9,31 @@ import 'package:intl/intl.dart'; /// 说明: 收藏夹展示数据模型 class CategoryModel extends Equatable { - final int id; + final int? id; final String name; final String info; - final String createDate; - final String imageCover; - final int count; + final String? createDate; + final String? imageCover; + final int? count; final Color color; CategoryModel( - {this.name, - this.id, - this.info, + {required this.name, + required this.id, + required this.info, this.createDate, this.imageCover, this.count, - this.color}); + required this.color}); - bool get canDelete => id > 1; + bool get canDelete => id != null && id! > 1; static CategoryModel fromPo(CategoryPo po) { return CategoryModel( id: po.id, name: po.name, info: po.info, - createDate: DateFormat('yyyy-MM-dd HH:mm').format(po.created), + createDate:po.created!=null? DateFormat('yyyy-MM-dd HH:mm').format(po.created!):null, imageCover: po.image, count: po.count, color: ColorUtils.parse(po.color), @@ -41,7 +41,7 @@ class CategoryModel extends Equatable { } @override - List get props => [ + List get props => [ id, name, info, @@ -62,9 +62,9 @@ class CategoryModel extends Equatable { class CategoryTo{ final CategoryPo model; final List widgetIds; - final List likesData; + final List? likesData; - CategoryTo({this.model, this.widgetIds,this.likesData}); + CategoryTo({required this.model,required this.widgetIds, this.likesData}); Map toJson() => { "model": this.model, diff --git a/lib/model/github/g/github_user.g.dart b/lib/model/github/g/github_user.g.dart index 96866eb..4c1bd8c 100644 --- a/lib/model/github/g/github_user.g.dart +++ b/lib/model/github/g/github_user.g.dart @@ -8,47 +8,47 @@ part of '../github_user.dart'; GithubUser _$UserFromJson(Map json) { return GithubUser( - json['login'] as String, - json['id'] as int, - json['node_id'] as String, - json['avatar_url'] as String, - json['gravatar_id'] as String, - json['url'] as String, - json['html_url'] as String, - json['followers_url'] as String, - json['following_url'] as String, - json['gists_url'] as String, - json['starred_url'] as String, - json['subscriptions_url'] as String, - json['organizations_url'] as String, - json['repos_url'] as String, - json['events_url'] as String, - json['received_events_url'] as String, - json['type'] as String, - json['site_admin'] as bool, - json['name'] as String, - json['company'] as String, - json['blog'] as String, - json['location'] as String, - json['email'] as String, - json['starred'] as String, - json['bio'] as String, - json['public_repos'] as int, - json['public_gists'] as int, - json['followers'] as int, - json['following'] as int, + json['login'] as String?, + json['id'] as int?, + json['node_id'] as String?, + json['avatar_url'] as String?, + json['gravatar_id'] as String?, + json['url'] as String?, + json['html_url'] as String?, + json['followers_url'] as String?, + json['following_url'] as String?, + json['gists_url'] as String?, + json['starred_url'] as String?, + json['subscriptions_url'] as String?, + json['organizations_url'] as String?, + json['repos_url'] as String?, + json['events_url'] as String?, + json['received_events_url'] as String?, + json['type'] as String?, + json['site_admin'] as bool?, + json['name'] as String?, + json['company'] as String?, + json['blog'] as String?, + json['location'] as String?, + json['email'] as String?, + json['starred'] as String?, + json['bio'] as String?, + json['public_repos'] as int?, + json['public_gists'] as int?, + json['followers'] as int?, + json['following'] as int?, json['created_at'] == null ? null : DateTime.parse(json['created_at'] as String), json['updated_at'] == null ? null : DateTime.parse(json['updated_at'] as String), - json['private_gists'] as int, - json['total_private_repos'] as int, - json['owned_private_repos'] as int, - json['disk_usage'] as int, - json['collaborators'] as int, - json['two_factor_authentication'] as bool, + json['private_gists'] as int?, + json['total_private_repos'] as int?, + json['owned_private_repos'] as int?, + json['disk_usage'] as int?, + json['collaborators'] as int?, + json['two_factor_authentication'] as bool?, ); } diff --git a/lib/model/github/g/issue.g.dart b/lib/model/github/g/issue.g.dart index 193380c..a22583a 100644 --- a/lib/model/github/g/issue.g.dart +++ b/lib/model/github/g/issue.g.dart @@ -8,12 +8,12 @@ part of '../issue.dart'; Issue _$IssueFromJson(dynamic json) { return Issue( - json['id'] as int, - json['number'] as int, - json['title'] as String, - json['state'] as String, - json['locked'] as bool, - json['comments'] as int, + json['id'] as int?, + json['number'] as int?, + json['title'] as String?, + json['state'] as String?, + json['locked'] as bool?, + json['comments'] as int?, json['created_at'] == null ? null : DateTime.parse(json['created_at'] as String), @@ -23,13 +23,13 @@ Issue _$IssueFromJson(dynamic json) { json['closed_at'] == null ? null : DateTime.parse(json['closed_at'] as String), - json['body'] as String, - json['body_html'] as String, + json['body'] as String?, + json['body_html'] as String?, json['user'] == null ? null : GithubUser.fromJson(json['user'] as Map), - json['repository_url'] as String, - json['html_url'] as String, + json['repository_url'] as String?, + json['html_url'] as String?, json['closed_by'] == null ? null : GithubUser.fromJson(json['closed_by'] as Map), diff --git a/lib/model/github/g/issue_comment.g.dart b/lib/model/github/g/issue_comment.g.dart index 65c20fd..0050ac1 100644 --- a/lib/model/github/g/issue_comment.g.dart +++ b/lib/model/github/g/issue_comment.g.dart @@ -8,7 +8,7 @@ part of '../issue_comment.dart'; IssueComment _$IssueEventFromJson(Map json) { return IssueComment( - json['id'] as int, + json['id'] as int?, json['user'] == null ? null : GithubUser.fromJson(json['user'] as Map), @@ -18,11 +18,11 @@ IssueComment _$IssueEventFromJson(Map json) { json['updated_at'] == null ? null : DateTime.parse(json['updated_at'] as String), - json['author_association'] as String, - json['body'] as String, - json['body_html'] as String, - json['event'] as String, - json['html_url'] as String, + json['author_association'] as String?, + json['body'] as String?, + json['body_html'] as String?, + json['event'] as String?, + json['html_url'] as String?, ); } diff --git a/lib/model/github/g/license.g.dart b/lib/model/github/g/license.g.dart index a38d6f0..baa97dd 100644 --- a/lib/model/github/g/license.g.dart +++ b/lib/model/github/g/license.g.dart @@ -8,8 +8,8 @@ part of '../license.dart'; License _$LicenseFromJson(Map json) { return License( - json['name'] as String, - json['spdx_id'] as String, + json['name'] as String?, + json['spdx_id'] as String?, ); } diff --git a/lib/model/github/g/repository.g.dart b/lib/model/github/g/repository.g.dart index 089d10f..5c60285 100644 --- a/lib/model/github/g/repository.g.dart +++ b/lib/model/github/g/repository.g.dart @@ -8,17 +8,17 @@ part of '../repository.dart'; Repository _$RepositoryFromJson(Map json) { return Repository( - json['id'] as int, - json['size'] as int, - json['name'] as String, - json['full_name'] as String, - json['html_url'] as String, - json['description'] as String, - json['language'] as String, + json['id'] as int?, + json['size'] as int?, + json['name'] as String?, + json['full_name'] as String?, + json['html_url'] as String?, + json['description'] as String?, + json['language'] as String?, json['license'] == null ? null : License.fromJson(json['license'] as Map), - json['default_branch'] as String, + json['default_branch'] as String?, json['created_at'] == null ? null : DateTime.parse(json['created_at'] as String), @@ -28,22 +28,22 @@ Repository _$RepositoryFromJson(Map json) { json['pushed_at'] == null ? null : DateTime.parse(json['pushed_at'] as String), - json['git_url'] as String, - json['ssh_url'] as String, - json['clone_url'] as String, - json['svn_url'] as String, - json['stargazers_count'] as int, - json['watchers_count'] as int, - json['forks_count'] as int, - json['open_issues_count'] as int, - json['subscribers_count'] as int, - json['private'] as bool, - json['fork'] as bool, - json['has_issues'] as bool, - json['has_projects'] as bool, - json['has_downloads'] as bool, - json['has_wiki'] as bool, - json['has_pages'] as bool, + json['git_url'] as String?, + json['ssh_url'] as String?, + json['clone_url'] as String?, + json['svn_url'] as String?, + json['stargazers_count'] as int?, + json['watchers_count'] as int?, + json['forks_count'] as int?, + json['open_issues_count'] as int?, + json['subscribers_count'] as int?, + json['private'] as bool?, + json['fork'] as bool?, + json['has_issues'] as bool?, + json['has_projects'] as bool?, + json['has_downloads'] as bool?, + json['has_wiki'] as bool?, + json['has_pages'] as bool?, json['owner'] == null ? null : GithubUser.fromJson(json['owner'] as Map), @@ -54,8 +54,8 @@ Repository _$RepositoryFromJson(Map json) { ? null : RepositoryPermissions.fromJson( json['permissions'] as Map), - (json['topics'] as List)?.map((e) => e as String)?.toList(), - )..allIssueCount = json['allIssueCount'] as int; + (json['topics'] as List?)?.map((e) => e as String).toList(), + )..allIssueCount = json['allIssueCount'] as int?; } Map _$RepositoryToJson(Repository instance) => diff --git a/lib/model/github/g/repository_permissions.g.dart b/lib/model/github/g/repository_permissions.g.dart index 699ed7c..201c8fb 100644 --- a/lib/model/github/g/repository_permissions.g.dart +++ b/lib/model/github/g/repository_permissions.g.dart @@ -9,9 +9,9 @@ part of '../repository_permissions.dart'; RepositoryPermissions _$RepositoryPermissionsFromJson( Map json) { return RepositoryPermissions( - json['admin'] as bool, - json['push'] as bool, - json['pull'] as bool, + json['admin'] as bool?, + json['push'] as bool?, + json['pull'] as bool?, ); } diff --git a/lib/model/github/github_user.dart b/lib/model/github/github_user.dart index 1558c03..dce5c30 100644 --- a/lib/model/github/github_user.dart +++ b/lib/model/github/github_user.dart @@ -44,43 +44,43 @@ class GithubUser { this.collaborators, this.twoFactorAuthentication); - String login; - int id; - String nodeId; - String avatarUrl; - String gravatarId; - String url; - String htmlUrl; - String followersUrl; - String followingUrl; - String gistsUrl; - String starredUrl; - String subscriptionsUrl; - String organizationsUrl; - String reposUrl; - String eventsUrl; - String receivedEventsUrl; - String type; - bool siteAdmin; - String name; - String company; - String blog; - String location; - String email; - String starred; - String bio; - int publicRepos; - int publicGists; - int followers; - int following; - DateTime createdAt; - DateTime updatedAt; - int privateGists; - int totalPrivateRepos; - int ownedPrivateRepos; - int diskUsage; - int collaborators; - bool twoFactorAuthentication; + String? login; + int? id; + String? nodeId; + String? avatarUrl; + String? gravatarId; + String? url; + String? htmlUrl; + String? followersUrl; + String? followingUrl; + String? gistsUrl; + String? starredUrl; + String? subscriptionsUrl; + String? organizationsUrl; + String? reposUrl; + String? eventsUrl; + String? receivedEventsUrl; + String? type; + bool? siteAdmin; + String? name; + String? company; + String? blog; + String? location; + String? email; + String? starred; + String? bio; + int? publicRepos; + int? publicGists; + int? followers; + int? following; + DateTime? createdAt; + DateTime? updatedAt; + int? privateGists; + int? totalPrivateRepos; + int? ownedPrivateRepos; + int? diskUsage; + int? collaborators; + bool? twoFactorAuthentication; factory GithubUser.fromJson(Map json) => _$UserFromJson(json); diff --git a/lib/model/github/issue.dart b/lib/model/github/issue.dart index 62634e8..bf10520 100644 --- a/lib/model/github/issue.dart +++ b/lib/model/github/issue.dart @@ -4,30 +4,30 @@ import 'package:flutter_unit/model/github/github_user.dart'; part 'g/issue.g.dart'; class Issue extends Equatable { - final int id; - final int number; - final String title; - final String state; - final bool locked; + final int? id; + final int? number; + final String? title; + final String? state; + final bool? locked; - final int commentNum; + final int? commentNum; - final DateTime createdAt; + final DateTime? createdAt; - final DateTime updatedAt; + final DateTime? updatedAt; - final DateTime closedAt; - final String body; + final DateTime? closedAt; + final String? body; - final String bodyHtml; + final String? bodyHtml; - final GithubUser user; + final GithubUser? user; - final String repoUrl; + final String? repoUrl; - final String htmlUrl; + final String? htmlUrl; - final GithubUser closeBy; + final GithubUser? closeBy; Issue( this.id, @@ -57,7 +57,7 @@ class Issue extends Equatable { } @override - List get props => [ + List get props => [ id, number, title, diff --git a/lib/model/github/issue_comment.dart b/lib/model/github/issue_comment.dart index c426f2d..821cbe3 100644 --- a/lib/model/github/issue_comment.dart +++ b/lib/model/github/issue_comment.dart @@ -4,19 +4,19 @@ part 'g/issue_comment.g.dart'; class IssueComment{ - int id; - GithubUser user; + int? id; + GithubUser? user; - DateTime createdAt; + DateTime? createdAt; - DateTime updatedAt; + DateTime? updatedAt; - String authorAssociation; - String body; + String? authorAssociation; + String? body; - String bodyHtml; - String type; - String htmlUrl; + String? bodyHtml; + String? type; + String? htmlUrl; IssueComment( this.id, diff --git a/lib/model/github/license.dart b/lib/model/github/license.dart index d9f70d1..e793788 100644 --- a/lib/model/github/license.dart +++ b/lib/model/github/license.dart @@ -3,11 +3,16 @@ part 'g/license.g.dart'; class License { - String name; - String spdxId; + String? name; + String? spdxId; License(this.name,this.spdxId); + String get type { + return spdxId ==null?"未知":spdxId!; + } + + factory License.fromJson(Map json) => _$LicenseFromJson(json); Map toJson() => _$LicenseToJson(this); diff --git a/lib/model/github/repository.dart b/lib/model/github/repository.dart index 1ab7931..98c96e1 100644 --- a/lib/model/github/repository.dart +++ b/lib/model/github/repository.dart @@ -8,85 +8,85 @@ import 'repository_permissions.dart'; part 'g/repository.g.dart'; class Repository { - int id; + int? id; - int size; + int? size; - String name; + String? name; - String fullName; + String? fullName; - String htmlUrl; + String? htmlUrl; - String description; + String? description; - String language; + String? language; - String defaultBranch; + String? defaultBranch; - DateTime createdAt; + DateTime? createdAt; - DateTime updatedAt; + DateTime? updatedAt; - DateTime pushedAt; + DateTime? pushedAt; - String gitUrl; + String? gitUrl; - String sshUrl; + String? sshUrl; - String cloneUrl; + String? cloneUrl; - String svnUrl; + String? svnUrl; - int stargazersCount; + int? stargazersCount; - int watchersCount; + int? watchersCount; - int forksCount; + int? forksCount; - int openIssuesCount; + int? openIssuesCount; - int subscribersCount; + int? subscribersCount; - bool private; + bool? private; - bool fork; + bool? fork; - bool hasIssues; + bool? hasIssues; - bool hasProjects; + bool? hasProjects; - bool hasDownloads; + bool? hasDownloads; - bool hasWiki; + bool? hasWiki; - bool hasPages; + bool? hasPages; - GithubUser owner; + GithubUser? owner; - License license; + License? license; - Repository parent; + Repository? parent; - RepositoryPermissions permissions; + RepositoryPermissions? permissions; - List topics; + List? topics; - int allIssueCount; + int? allIssueCount; Repository( this.id, diff --git a/lib/model/github/repository_permissions.dart b/lib/model/github/repository_permissions.dart index 5372306..f6b3896 100644 --- a/lib/model/github/repository_permissions.dart +++ b/lib/model/github/repository_permissions.dart @@ -3,9 +3,9 @@ part 'g/repository_permissions.g.dart'; class RepositoryPermissions { - bool admin; - bool push; - bool pull; + bool? admin; + bool? push; + bool? pull; RepositoryPermissions( this.admin, diff --git a/lib/model/node_model.dart b/lib/model/node_model.dart index 591937c..9364c17 100644 --- a/lib/model/node_model.dart +++ b/lib/model/node_model.dart @@ -10,7 +10,7 @@ class NodeModel extends Equatable { final String subtitle; final String code; - const NodeModel({this.name, this.subtitle, this.code}); + const NodeModel({required this.name,required this.subtitle,required this.code}); @override List get props => [name, subtitle, code]; diff --git a/lib/model/widget_model.dart b/lib/model/widget_model.dart index 406d334..857f0bc 100644 --- a/lib/model/widget_model.dart +++ b/lib/model/widget_model.dart @@ -10,15 +10,6 @@ import 'package:flutter_unit/repositories/bean/widget_po.dart'; /// 说明: 组件信息-展示-数据模型 /// -enum WidgetType { - singe_show, //单一展示型 0 - structure, //结构型 1 - shape, //可形变 2 - event, //事件型 3 - ability, //功能型 4 - layout, //布局型 5 - scroll, //滚动型 -} class WidgetModel extends Equatable { final int id; @@ -26,25 +17,25 @@ class WidgetModel extends Equatable { final String nameCN; final WidgetFamily family; final bool deprecated; - final WidgetType type; final List links; final double lever; - final ImageProvider image; + final ImageProvider? image; final String info; Color get color => Color(Cons.tabColors[family.index]); const WidgetModel( - {this.id, - this.name, - this.nameCN, - this.family, - this.deprecated, - this.links, - this.type, - this.lever, + { + required this.id, + required this.name, + required this.nameCN, + required this.family, + this.deprecated =false, + required this.links, + // required this.type, + required this.lever, this.image, - this.info}); + required this.info}); @override List get props => [id]; @@ -71,7 +62,7 @@ class WidgetModel extends Equatable { @override String toString() { - return 'WidgetModel{id: $id, name: $name, nameCN: $nameCN, family: $family, deprecated: $deprecated, type: $type, links: $links, lever: $lever, image: $image, info: $info}'; + return 'WidgetModel{id: $id, name: $name, nameCN: $nameCN, family: $family, deprecated: $deprecated, links: $links, lever: $lever, image: $image, info: $info}'; } static List formatLinkTo(String links) { diff --git a/lib/painter_system/anim/bezier3_player/bezier3_palyer.dart b/lib/painter_system/anim/bezier3_player/bezier3_palyer.dart index dc535a5..193ed3f 100644 --- a/lib/painter_system/anim/bezier3_player/bezier3_palyer.dart +++ b/lib/painter_system/anim/bezier3_player/bezier3_palyer.dart @@ -83,8 +83,8 @@ class PaperPainter extends CustomPainter { final TouchInfo repaint; - PaperPainter({this.repaint}) : super(repaint: repaint); - List pos; + PaperPainter({required this.repaint}) : super(repaint: repaint); + List pos=[]; @override void paint(Canvas canvas, Size size) { @@ -118,7 +118,7 @@ class PaperPainter extends CustomPainter { } void _drawSelectPos(Canvas canvas,Size size) { - Offset selectPos = repaint.selectPoint; + Offset? selectPos = repaint.selectPoint; if (selectPos == null) return; selectPos = selectPos.translate(-size.width / 2, -size.height / 2); canvas.drawCircle( diff --git a/lib/painter_system/anim/bezier3_player/touch_info.dart b/lib/painter_system/anim/bezier3_player/touch_info.dart index 3dc7f89..a6d142a 100644 --- a/lib/painter_system/anim/bezier3_player/touch_info.dart +++ b/lib/painter_system/anim/bezier3_player/touch_info.dart @@ -13,7 +13,6 @@ class TouchInfo extends ChangeNotifier { List get points => _points; set selectIndex(int value) { - assert(value != null); if (_selectIndex == value) return; _selectIndex = value; @@ -36,6 +35,6 @@ class TouchInfo extends ChangeNotifier { notifyListeners(); } - Offset get selectPoint => + Offset? get selectPoint => _selectIndex == -1 ? null : _points[_selectIndex]; } diff --git a/lib/painter_system/anim/circle_halo.dart b/lib/painter_system/anim/circle_halo.dart index a077fd6..08ed0fd 100644 --- a/lib/painter_system/anim/circle_halo.dart +++ b/lib/painter_system/anim/circle_halo.dart @@ -4,7 +4,7 @@ import 'dart:ui' as ui; import 'package:flutter/material.dart'; class CircleHalo extends StatefulWidget { - const CircleHalo({Key key}) : super(key: key); + const CircleHalo({Key? key}) : super(key: key); @override _CircleHaloState createState() => _CircleHaloState(); @@ -12,7 +12,7 @@ class CircleHalo extends StatefulWidget { class _CircleHaloState extends State with SingleTickerProviderStateMixin { - AnimationController _ctrl; + late AnimationController _ctrl; @override void initState() { diff --git a/lib/painter_system/anim/curve_shower/curve_anim_shower.dart b/lib/painter_system/anim/curve_shower/curve_anim_shower.dart index b1fda17..2da73c0 100644 --- a/lib/painter_system/anim/curve_shower/curve_anim_shower.dart +++ b/lib/painter_system/anim/curve_shower/curve_anim_shower.dart @@ -17,11 +17,11 @@ class _CurveAnimShowerState extends State with SingleTickerProviderStateMixin { PointData points = PointData(); - AnimationController _ctrl; + late AnimationController _ctrl; final Duration animDuration = const Duration(milliseconds: 1000); - Animation curveAnim; + late Animation curveAnim; Map maps = { 'bounceOut': Curves.bounceOut, diff --git a/lib/painter_system/anim/draw_path.dart b/lib/painter_system/anim/draw_path.dart index 682066c..b8ca9cc 100644 --- a/lib/painter_system/anim/draw_path.dart +++ b/lib/painter_system/anim/draw_path.dart @@ -15,7 +15,7 @@ class DrawPath extends StatefulWidget { } class _DrawPathState extends State with SingleTickerProviderStateMixin { - AnimationController _controller; + late AnimationController _controller; @override void initState() { @@ -112,10 +112,10 @@ class PaperPainter extends CustomPainter { PathMetrics pms = path.computeMetrics(); pms.forEach((pm) { - Tangent tangent = pm.getTangentForOffset(pm.length * repaint.value); + Tangent? tangent = pm.getTangentForOffset(pm.length * repaint.value); canvas.drawPath(pm.extractPath(0, pm.length * repaint.value), paint); canvas.drawCircle( - tangent.position, 5, Paint()..color = Colors.blue); + tangent?.position??Offset.zero, 5, Paint()..color = Colors.blue); }); } diff --git a/lib/painter_system/anim/spring_widget.dart b/lib/painter_system/anim/spring_widget.dart index a4716ad..0b3c5a3 100644 --- a/lib/painter_system/anim/spring_widget.dart +++ b/lib/painter_system/anim/spring_widget.dart @@ -17,12 +17,12 @@ const double _kK = 3; class _SpringWidgetState extends State with SingleTickerProviderStateMixin { ValueNotifier height = ValueNotifier(_kDefaultSpringHeight); - AnimationController _ctrl; + late AnimationController _ctrl; double s = 0; // 移动距离 double laseMoveLen = 0; - Animation animation; + late Animation animation; final Duration animDuration = const Duration(milliseconds: 500); @@ -98,7 +98,7 @@ class SpringPainter extends CustomPainter { final int count; final ValueListenable height; - SpringPainter({this.count = 20, this.height}):super(repaint: height); + SpringPainter({this.count = 20,required this.height}):super(repaint: height); Paint _paint = Paint() ..style = PaintingStyle.stroke diff --git a/lib/painter_system/art/circle_packing.dart b/lib/painter_system/art/circle_packing.dart index ee04b02..46d824b 100644 --- a/lib/painter_system/art/circle_packing.dart +++ b/lib/painter_system/art/circle_packing.dart @@ -4,9 +4,9 @@ import 'package:flutter/material.dart'; import '../utils/colors.dart'; class Circle { - Point center; - double radius; - Color color; + Point center = Point(0,0); + double radius = 10; + Color color = Colors.black; } class CirclePacking extends StatefulWidget { @@ -39,11 +39,12 @@ class CirclePackingPainter extends CustomPainter { Random random = Random(); void _createCircles(Canvas canvas, Size size) { - Circle circle; + Circle circle= Circle(); + bool circleSafeToDraw = false; for (int i = 0; i < createCircleAttemps; i++) { - circle = Circle() + circle ..radius = minRaidus ..center = Point( random.nextDouble() * size.width, @@ -82,7 +83,7 @@ class CirclePackingPainter extends CustomPainter { circles.asMap().forEach((key, circle) { paint.color = Colors.black; - Offset offset = Offset(circle.center.x, circle.center.y); + Offset offset = Offset(circle.center.x.toDouble(), circle.center.y.toDouble()); canvas.drawCircle(offset, circle.radius, paint); }); } diff --git a/lib/painter_system/art/hypnotic_squares.dart b/lib/painter_system/art/hypnotic_squares.dart index 08292c7..013f8f8 100644 --- a/lib/painter_system/art/hypnotic_squares.dart +++ b/lib/painter_system/art/hypnotic_squares.dart @@ -26,7 +26,7 @@ class _HypnoticSquaresState extends State { } class HypnoticSquaresPainter extends CustomPainter { - double startSteps; + double startSteps = 1; double offset = 4.0; double finalSize = 10.0; Random random = Random(); diff --git a/lib/painter_system/art/joy_division.dart b/lib/painter_system/art/joy_division.dart index 7d7f8e8..a33ede2 100644 --- a/lib/painter_system/art/joy_division.dart +++ b/lib/painter_system/art/joy_division.dart @@ -53,14 +53,14 @@ class JoyDivisionPainter extends CustomPainter { for (int i = 5; i < lines.length; i++) { Point p1 = lines[i][0]; - Path path = Path()..moveTo(p1.x, p1.y); + Path path = Path()..moveTo(p1.x.toDouble(), p1.y.toDouble()); for (int j = 0; j < lines[i].length - 2; j++) { double xc = (lines[i][j].x + lines[i][j + 1].x) / 2; double yc = (lines[i][j].y + lines[i][j + 1].y) / 2; Point p2 = lines[i][j]; - path.quadraticBezierTo(p2.x, p2.y, xc, yc); + path.quadraticBezierTo(p2.x.toDouble(), p2.y.toDouble(), xc, yc); canvas.drawPath(path, paint); } } diff --git a/lib/painter_system/art/piet_mondrian.dart b/lib/painter_system/art/piet_mondrian.dart index 323b2e5..af77b0c 100644 --- a/lib/painter_system/art/piet_mondrian.dart +++ b/lib/painter_system/art/piet_mondrian.dart @@ -33,11 +33,11 @@ class Square { final Color color; Square({ - this.x, - this.y, - this.width, - this.height, - this.color, + required this.x, + required this.y, + required this.width, + required this.height, + required this.color, }); Map toJson() { diff --git a/lib/painter_system/art/triangular_mesh.dart b/lib/painter_system/art/triangular_mesh.dart index fde7467..e215a64 100644 --- a/lib/painter_system/art/triangular_mesh.dart +++ b/lib/painter_system/art/triangular_mesh.dart @@ -4,8 +4,8 @@ import 'package:flutter/material.dart'; import '../utils/colors.dart'; class Point { - double x; - double y; + double x=0; + double y=0; } class TriangularMesh extends StatefulWidget { diff --git a/lib/painter_system/base/clock_widget.dart b/lib/painter_system/base/clock_widget.dart index 0c0483b..4f53745 100644 --- a/lib/painter_system/base/clock_widget.dart +++ b/lib/painter_system/base/clock_widget.dart @@ -12,7 +12,7 @@ import 'package:flutter/scheduler.dart'; class ClockWidget extends StatefulWidget { final double radius; - const ClockWidget({Key key, this.radius = 100}) : super(key: key); + const ClockWidget({Key? key, this.radius = 100}) : super(key: key); @override _ClockWidgetState createState() => _ClockWidgetState(); @@ -20,7 +20,7 @@ class ClockWidget extends StatefulWidget { class _ClockWidgetState extends State with SingleTickerProviderStateMixin { - Ticker _ticker; + late Ticker _ticker; ValueNotifier time = ValueNotifier(DateTime.now()); @override @@ -209,7 +209,7 @@ class ClockPainter extends CustomPainter { final double radius; final ValueListenable listenable; - ClockPainter({this.listenable, this.radius = 100}) + ClockPainter({required this.listenable, this.radius = 100}) : super(repaint: listenable); @override diff --git a/lib/painter_system/base/draw_picture.dart b/lib/painter_system/base/draw_picture.dart index 55ab1ca..945c80e 100644 --- a/lib/painter_system/base/draw_picture.dart +++ b/lib/painter_system/base/draw_picture.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:typed_data'; import 'package:flutter/material.dart'; import 'dart:ui' as ui; @@ -15,7 +16,7 @@ class DrawPicture extends StatefulWidget { } class _DrawPictureState extends State { - ui.Image _image; + ui.Image? _image; @override void initState() { @@ -33,7 +34,7 @@ class _DrawPictureState extends State { ByteData data = await rootBundle.load(path); List bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes); - return decodeImageFromList(bytes); + return decodeImageFromList(Uint8List.fromList(bytes)); } @override @@ -49,7 +50,7 @@ class PaperPainter extends CustomPainter { final double strokeWidth = 0.5; final Color color = Colors.blue; - final ui.Image image; + final ui.Image? image; PaperPainter(this.image) : _paint = Paint() @@ -76,11 +77,11 @@ class PaperPainter extends CustomPainter { void _drawImage(Canvas canvas, Size size) { if (image != null) { canvas.drawImageRect( - image, + image!, Rect.fromCenter( - center: Offset(image.width / 2, image.height / 2), - width: image.width * 1.0, - height: image.width * 1.0), + center: Offset(image!.width / 2, image!.height / 2), + width: image!.width * 1.0, + height: image!.width * 1.0), Rect.fromLTRB(0, 0, size.width, size.height), _paint); } diff --git a/lib/painter_system/fun/stemp/stamp_data.dart b/lib/painter_system/fun/stemp/stamp_data.dart index 9b9a21f..4e85622 100644 --- a/lib/painter_system/fun/stemp/stamp_data.dart +++ b/lib/painter_system/fun/stemp/stamp_data.dart @@ -106,9 +106,9 @@ class Stamp { Offset center; double radius; - Stamp({this.color = Colors.blue, this.center, this.radius = 20}); + Stamp({this.color = Colors.blue, this.center = Offset.zero, this.radius = 20}); - Path _path; + Path? _path; Path get path { if (_path == null) { @@ -116,21 +116,21 @@ class Stamp { double r = radius; double rad = 30 / 180 * pi; - _path..moveTo(center.dx, center.dy); - _path.relativeMoveTo(r * cos(rad), -r * sin(rad)); - _path.relativeLineTo(-2 * r * cos(rad), 0); - _path.relativeLineTo(r * cos(rad), r + r * sin(rad)); - _path.relativeLineTo(r * cos(rad), -(r + r * sin(rad))); + _path!..moveTo(center.dx, center.dy); + _path!.relativeMoveTo(r * cos(rad), -r * sin(rad)); + _path!.relativeLineTo(-2 * r * cos(rad), 0); + _path!.relativeLineTo(r * cos(rad), r + r * sin(rad)); + _path!.relativeLineTo(r * cos(rad), -(r + r * sin(rad))); - _path..moveTo(center.dx, center.dy); - _path.relativeMoveTo(0, -r); - _path.relativeLineTo(-r * cos(rad), r + r * sin(rad)); - _path.relativeLineTo(2 * r * cos(rad), 0); - _path.relativeLineTo(-r * cos(rad), -(r + r * sin(rad))); + _path!..moveTo(center.dx, center.dy); + _path!.relativeMoveTo(0, -r); + _path!.relativeLineTo(-r * cos(rad), r + r * sin(rad)); + _path!.relativeLineTo(2 * r * cos(rad), 0); + _path!.relativeLineTo(-r * cos(rad), -(r + r * sin(rad))); - return _path; + return _path!; } else { - return _path; + return _path!; } } diff --git a/lib/painter_system/fun/stemp/stamp_paper.dart b/lib/painter_system/fun/stemp/stamp_paper.dart index 3739d94..18c6643 100644 --- a/lib/painter_system/fun/stemp/stamp_paper.dart +++ b/lib/painter_system/fun/stemp/stamp_paper.dart @@ -20,7 +20,7 @@ class _StampPaperState extends State bool get gameOver => gameState != GameState.doing; // 定义动画器 - AnimationController _controller; + late AnimationController _controller; final Duration animDuration = const Duration(milliseconds: 200); @override @@ -193,7 +193,7 @@ class StampPainter extends CustomPainter { ..color = Colors.white ..style = PaintingStyle.stroke; - StampPainter({this.stamps, this.count = 3}) : super(repaint: stamps); + StampPainter({required this.stamps, this.count = 3}) : super(repaint: stamps); @override void paint(Canvas canvas, Size size) { diff --git a/lib/painter_system/gallery.dart b/lib/painter_system/gallery.dart index 6d0f392..99922bf 100644 --- a/lib/painter_system/gallery.dart +++ b/lib/painter_system/gallery.dart @@ -126,12 +126,12 @@ class FrameShower extends StatelessWidget { final Widget content; FrameShower( - {Key key, + {Key? key, this.title = "", this.author = "", this.srcUrl = "", this.info = "", - @required this.content}) + required this.content}) : super(key: key); @override diff --git a/lib/painter_system/gallery_detail_page.dart b/lib/painter_system/gallery_detail_page.dart index 2c96a84..116c859 100644 --- a/lib/painter_system/gallery_detail_page.dart +++ b/lib/painter_system/gallery_detail_page.dart @@ -11,7 +11,7 @@ class GalleryDetailPage extends StatefulWidget { final GalleryInfo galleryInfo; final List children; - GalleryDetailPage({Key key, this.galleryInfo, this.children = const []}) + GalleryDetailPage({Key? key,required this.galleryInfo, this.children = const []}) : super(key: key); @override @@ -19,7 +19,7 @@ class GalleryDetailPage extends StatefulWidget { } class _GalleryDetailPageState extends State { - PageController _ctrl; + late PageController _ctrl; final ValueNotifier _currentIndex = ValueNotifier(0); @override @@ -200,7 +200,7 @@ class _GalleryDetailPageState extends State { ); } - Widget _buildIndicatorText(BuildContext context, int value, Widget child) { + Widget _buildIndicatorText(BuildContext context, int value, Widget? child) { String indicatorText = "${widget.children.length != 0 ? (value + 1) : 0} / ${widget.children.length}"; diff --git a/lib/painter_system/gallery_unit.dart b/lib/painter_system/gallery_unit.dart index 3abc4eb..24bab66 100644 --- a/lib/painter_system/gallery_unit.dart +++ b/lib/painter_system/gallery_unit.dart @@ -22,7 +22,7 @@ class GalleryUnit extends StatefulWidget { class _GalleryUnitState extends State { final ValueNotifier factor = ValueNotifier(0); - PageController _ctrl; + late PageController _ctrl; final int _firstOffset = 1000; //初始偏移 int _position = 0; //页面位置 @@ -38,8 +38,11 @@ class _GalleryUnitState extends State { viewportFraction: 0.9, initialPage: _position, )..addListener(() { - double value = (_ctrl.page - _firstOffset + 1) % 5 / 5; + if(_ctrl.page!=null){ + double value = (_ctrl.page! - _firstOffset + 1) % 5 / 5; factor.value = value == 0 ? 1 : value; + } + }); } @@ -76,7 +79,7 @@ class _GalleryUnitState extends State { ], ), valueListenable: factor, - builder: (_, value, child) => Container( + builder: (_,double value, child) => Container( color: Color.lerp( color, nextColor, @@ -161,10 +164,10 @@ class _GalleryUnitState extends State { )); } - Widget _buildAnimItemByIndex(BuildContext context, Widget child, int index) { + Widget _buildAnimItemByIndex(BuildContext context, Widget? child, int index) { double value; - if (_ctrl.position.haveDimensions) { - value = _ctrl.page - index; + if (_ctrl.position.haveDimensions&&_ctrl.page!=null) { + value = _ctrl.page! - index; } else { value = (_position - index).toDouble(); } diff --git a/lib/painter_system/particle/out/clock_fx.dart b/lib/painter_system/particle/out/clock_fx.dart index 0a09c56..9c72e5c 100644 --- a/lib/painter_system/particle/out/clock_fx.dart +++ b/lib/painter_system/particle/out/clock_fx.dart @@ -23,25 +23,25 @@ final jellyDistributionLmt = 97; class ClockFx with ChangeNotifier { - double width; //宽 - double height;//高 - double sizeMin; // 宽高最小值 - Offset center; //画布中心 - Rect spawnArea; // 粒子活动区域 + double width=0; //宽 + double height=0;//高 + double sizeMin=0; // 宽高最小值 + Offset center=Offset.zero; //画布中心 + Rect spawnArea=Rect.zero; // 粒子活动区域 - List particles; // 所有粒子 + List particles=[]; // 所有粒子 - int numParticles;// 最大粒子数 + int numParticles=0;// 最大粒子数 - DateTime time; //时间 + late DateTime time; //时间 ClockFx({ - @required Size size, - @required DateTime time, + required Size size, + required DateTime time, this.numParticles = 5000, }) { this.time = time; - particles = List.filled(numParticles, null); + particles = List.filled(numParticles, Particle()); setSize(size); } diff --git a/lib/painter_system/particle/out/clock_widget.dart b/lib/painter_system/particle/out/clock_widget.dart index 6cd5039..5f05a00 100644 --- a/lib/painter_system/particle/out/clock_widget.dart +++ b/lib/painter_system/particle/out/clock_widget.dart @@ -14,7 +14,7 @@ import 'clock_fx.dart'; class ClockWidget extends StatefulWidget { final double radius; - const ClockWidget({Key key, this.radius = 100}) : super(key: key); + const ClockWidget({Key? key, this.radius = 100}) : super(key: key); @override _ClockWidgetState createState() => _ClockWidgetState(); @@ -22,8 +22,8 @@ class ClockWidget extends StatefulWidget { class _ClockWidgetState extends State with SingleTickerProviderStateMixin { - Ticker _ticker; - ClockFx _fx; + late Ticker _ticker; + late ClockFx _fx; @override void initState() { @@ -64,7 +64,7 @@ const double noiseAlpha = 160; class ClockFxPainter extends CustomPainter { final ClockFx fx; - ClockFxPainter({@required this.fx}) : super(repaint: fx); + ClockFxPainter({required this.fx}) : super(repaint: fx); @override void paint(Canvas canvas, Size size) { diff --git a/lib/painter_system/picture_frame.dart b/lib/painter_system/picture_frame.dart index 9d2fc78..87743b1 100644 --- a/lib/painter_system/picture_frame.dart +++ b/lib/painter_system/picture_frame.dart @@ -3,12 +3,12 @@ import 'dart:ui'; import 'package:flutter/material.dart'; class PictureFrame extends StatelessWidget { - final Widget child; - final double width; - final double height; - final Color color; - final Alignment alignment; - final EdgeInsetsGeometry marge; + final Widget? child; + final double? width; + final double? height; + final Color? color; + final Alignment? alignment; + final EdgeInsetsGeometry? marge; const PictureFrame( {this.child, diff --git a/lib/painter_system/utils/coordinate.dart b/lib/painter_system/utils/coordinate.dart index b996ecc..aad2371 100644 --- a/lib/painter_system/utils/coordinate.dart +++ b/lib/painter_system/utils/coordinate.dart @@ -120,7 +120,7 @@ class Coordinate { } void _drawAxisText(Canvas canvas, String str, - {Color color = Colors.black, bool x = false}) { + {Color color = Colors.black, bool? x = false}) { TextSpan text = TextSpan( text: str, style: TextStyle( diff --git a/lib/repositories/bean/category_po.dart b/lib/repositories/bean/category_po.dart index 1f31230..1d36154 100644 --- a/lib/repositories/bean/category_po.dart +++ b/lib/repositories/bean/category_po.dart @@ -17,26 +17,27 @@ import 'package:equatable/equatable.dart'; // );"""; //建表语句 class CategoryPo extends Equatable { - final int id; + final int? id; final String name; final String color; final String info; - final DateTime created; + final DateTime? created; final DateTime updated; final String image; final int count; final int priority; - const CategoryPo( - {this.id, - this.name, - this.color = '#FFF2F2F2', - this.created, - this.updated, - this.count = 0, - this.priority = 0, - this.info = '这里什么都没有...', - this.image = ''}); + const CategoryPo({ + this.id, + required this.name, + this.color = '#FFF2F2F2', + this.created, + required this.updated, + this.count = 0, + this.priority = 0, + this.info = '这里什么都没有...', + this.image = '', + }); factory CategoryPo.fromJson(Map map) { return CategoryPo( @@ -68,7 +69,7 @@ class CategoryPo extends Equatable { "id": this.id, "name": this.name, "info": this.info, - "created": this.created.millisecondsSinceEpoch, + "created": this.created?.millisecondsSinceEpoch, "updated": this.updated.millisecondsSinceEpoch, "image": this.image, "count": this.count, @@ -82,6 +83,6 @@ class CategoryPo extends Equatable { } @override - List get props => + List get props => [id, name, color, created, image, info, updated, priority,count]; } diff --git a/lib/repositories/bean/node_po.dart b/lib/repositories/bean/node_po.dart index 56db220..16bfd81 100644 --- a/lib/repositories/bean/node_po.dart +++ b/lib/repositories/bean/node_po.dart @@ -11,13 +11,14 @@ class NodePo { final String subtitle; final String code; - const NodePo( - {this.id, - this.widgetId, - this.name, - this.priority, - this.subtitle, - this.code}); + const NodePo({ + required this.id, + required this.widgetId, + required this.name, + required this.priority, + required this.subtitle, + required this.code, + }); factory NodePo.fromJson(Map map) { return NodePo( diff --git a/lib/repositories/bean/widget_po.dart b/lib/repositories/bean/widget_po.dart index fcb8953..29e2021 100644 --- a/lib/repositories/bean/widget_po.dart +++ b/lib/repositories/bean/widget_po.dart @@ -15,15 +15,16 @@ class WidgetPo extends Equatable { final String info; final String linkWidget; - const WidgetPo( - {this.id, - this.name, - this.nameCN, - this.deprecated, - this.family, - this.lever, - this.linkWidget, - this.info}); + const WidgetPo({ + required this.id, + required this.name, + required this.nameCN, + required this.deprecated, + required this.family, + required this.lever, + required this.linkWidget, + required this.info, + }); factory WidgetPo.fromJson(Map map) { return WidgetPo( diff --git a/lib/repositories/dao/category_dao.dart b/lib/repositories/dao/category_dao.dart index 941036b..ffdb223 100644 --- a/lib/repositories/dao/category_dao.dart +++ b/lib/repositories/dao/category_dao.dart @@ -38,7 +38,7 @@ class CategoryDao { category.info, category.priority, category.image, - category.created.toIso8601String(), + category.created?.toIso8601String(), category.updated.toIso8601String(), ])); } @@ -197,6 +197,6 @@ class CategoryDao { "ORDER BY lever DESC"; var data = await db.rawQuery(querySql,[categoryId]); - return data.map((e) => e["id"]).toList(); + return data.map((e) => e["id"] as int).toList(); } } diff --git a/lib/repositories/dao/like_dao.dart b/lib/repositories/dao/like_dao.dart index 605ed48..38e6184 100644 --- a/lib/repositories/dao/like_dao.dart +++ b/lib/repositories/dao/like_dao.dart @@ -7,7 +7,7 @@ class LikeDao { Future> likeWidgetIds() async { var result = await db.rawQuery("SELECT widget_id FROM like_widget"); - var ids = result.map((e) => e['widget_id']).toList(); + var ids = result.map((e) => e['widget_id'] as int).toList(); return ids; } diff --git a/lib/repositories/local_db.dart b/lib/repositories/local_db.dart index 9434647..12d1eea 100644 --- a/lib/repositories/local_db.dart +++ b/lib/repositories/local_db.dart @@ -7,16 +7,16 @@ import 'dao/node_dao.dart'; import 'dao/widget_dao.dart'; class LocalDb { - Database _database; + Database? _database; LocalDb._(); static LocalDb instance = LocalDb._(); - WidgetDao _widgetDao; - CategoryDao _categoryDao; - NodeDao _nodeDao; - LikeDao _likeDao; + late WidgetDao _widgetDao; + late CategoryDao _categoryDao; + late NodeDao _nodeDao; + late LikeDao _likeDao; WidgetDao get widgetDao => _widgetDao; @@ -26,7 +26,7 @@ class LocalDb { LikeDao get likeDao => _likeDao; - Database get db => _database; + Database get db => _database!; Future initDb({String name = "flutter.db"}) async { if (_database != null) return; @@ -35,16 +35,16 @@ class LocalDb { _database = await openDatabase(dbPath); - _widgetDao = WidgetDao(_database); - _categoryDao = CategoryDao(_database); - _nodeDao = NodeDao(_database); - _likeDao = LikeDao(_database); + _widgetDao = WidgetDao(_database!); + _categoryDao = CategoryDao(_database!); + _nodeDao = NodeDao(_database!); + _likeDao = LikeDao(_database!); print('初始化数据库....'); } Future closeDb() async { - await _database.close(); + await _database?.close(); _database = null; } } diff --git a/lib/repositories/local_storage.dart b/lib/repositories/local_storage.dart index 3eb9afe..a06e15d 100644 --- a/lib/repositories/local_storage.dart +++ b/lib/repositories/local_storage.dart @@ -10,14 +10,14 @@ class LocalStorage { static String userKey= "user_key"; static String dbVersionKey= "db_version_key"; - static SharedPreferences _sp; + static SharedPreferences? _sp; // 如果_sp已存在,直接返回,为null时创建 static Future get sp async { if (_sp == null) { _sp = await SharedPreferences.getInstance(); } - return _sp; + return _sp!; } static Future save(String key, String value) async { @@ -32,7 +32,7 @@ class LocalStorage { return (await sp).setInt(key, value); } - static Future getInt(String key) async { + static Future getInt(String key) async { return (await sp).getInt(key); } diff --git a/lib/repositories/rep/impl/catagory_db_repository.dart b/lib/repositories/rep/impl/catagory_db_repository.dart index 784156a..dda8a14 100644 --- a/lib/repositories/rep/impl/catagory_db_repository.dart +++ b/lib/repositories/rep/impl/catagory_db_repository.dart @@ -103,8 +103,8 @@ class CategoryDbRepository implements CategoryRepository { CategoryPo po = CategoryPo.fromNetJson(dataMap[i]["model"]); List widgetIds = dataMap[i]["widgetIds"]; await addCategory(po); - if (widgetIds.isNotEmpty) { - await _categoryDao.addWidgets(po.id, widgetIds); + if (widgetIds.isNotEmpty&&po.id!=null) { + await _categoryDao.addWidgets(po.id!, widgetIds); } } List likeWidgets = (json.decode(likeData) as List).map((e) => e).toList(); diff --git a/lib/repositories/rep/impl/widget_db_repository.dart b/lib/repositories/rep/impl/widget_db_repository.dart index fa5aa5e..3293a83 100644 --- a/lib/repositories/rep/impl/widget_db_repository.dart +++ b/lib/repositories/rep/impl/widget_db_repository.dart @@ -61,7 +61,7 @@ class WidgetDbRepository implements WidgetRepository { List> data = await _widgetDao.queryByIds(id); List widgets = data.map((e) => WidgetPo.fromJson(e)).toList(); if (widgets.length > 0) return widgets.map(WidgetModel.fromPo).toList(); - return null; + return []; } @override @@ -73,7 +73,7 @@ class WidgetDbRepository implements WidgetRepository { @override - Future collected(int id) async{ - return await _likeDao.like(id); + Future collected(int id) async{ + return await _likeDao.like(id); } } diff --git a/lib/repositories/rep/widget_repository.dart b/lib/repositories/rep/widget_repository.dart index 507195c..ce74aea 100644 --- a/lib/repositories/rep/widget_repository.dart +++ b/lib/repositories/rep/widget_repository.dart @@ -19,5 +19,5 @@ abstract class WidgetRepository { Future> loadLikeWidgets(); - Future collected(int id); + Future collected(int id); } diff --git a/lib/user_system/api/system_api.dart b/lib/user_system/api/system_api.dart index 69363e9..71c700e 100644 --- a/lib/user_system/api/system_api.dart +++ b/lib/user_system/api/system_api.dart @@ -8,7 +8,7 @@ import 'package:flutter_unit/app/utils/http_utils/result_bean.dart'; /// 说明: class SystemApi { - static Future> sendEmail({@required String email}) async { + static Future> sendEmail({required String email}) async { var result = await HttpUtil.getInstance().client.post(PathUnit.sendEmail + "$email"); diff --git a/lib/user_system/api/user_api.dart b/lib/user_system/api/user_api.dart index 03dee88..e514671 100644 --- a/lib/user_system/api/user_api.dart +++ b/lib/user_system/api/user_api.dart @@ -8,7 +8,7 @@ import 'package:flutter_unit/user_system/model/user.dart'; /// 说明: class UserApi { - static Future> register({String email, String code}) async { + static Future> register({required String email,required String code}) async { String errorMsg = ""; var result = await HttpUtil.getInstance().client.post(PathUnit.register, @@ -24,7 +24,7 @@ class UserApi { } static Future> login( - {String username, String password}) async { + {required String username,required String password}) async { String errorMsg = ""; var result = await HttpUtil.getInstance().client.post(PathUnit.login, diff --git a/lib/user_system/bloc/authentic/bloc.dart b/lib/user_system/bloc/authentic/bloc.dart index 3c9328b..3caba56 100644 --- a/lib/user_system/bloc/authentic/bloc.dart +++ b/lib/user_system/bloc/authentic/bloc.dart @@ -18,8 +18,8 @@ class AuthenticBloc extends Bloc { AuthEvent event, ) async* { if (event is AppStarted) { - String token = await LocalStorage.get(LocalStorage.tokenKey); - String userJson = await LocalStorage.get(LocalStorage.userKey); + String? token = await LocalStorage.get(LocalStorage.tokenKey); + String? userJson = await LocalStorage.get(LocalStorage.userKey); if (token != null && userJson != null) { bool disable = JwtDecoder.isExpired(token); if (!disable) { diff --git a/lib/user_system/bloc/authentic/event.dart b/lib/user_system/bloc/authentic/event.dart index 974a60a..c26df29 100644 --- a/lib/user_system/bloc/authentic/event.dart +++ b/lib/user_system/bloc/authentic/event.dart @@ -21,7 +21,7 @@ class LoginOver extends AuthEvent { final String token; final User user; - const LoginOver({@required this.token,this.user}); + const LoginOver({required this.token,required this.user}); @override List get props => [token]; diff --git a/lib/user_system/bloc/login/bloc.dart b/lib/user_system/bloc/login/bloc.dart index 9062ba5..5e4611d 100644 --- a/lib/user_system/bloc/login/bloc.dart +++ b/lib/user_system/bloc/login/bloc.dart @@ -16,7 +16,7 @@ import 'state.dart'; class LoginBloc extends Bloc { final AuthenticBloc authenticBloc; - LoginBloc({ @required this.authenticBloc}) : super(LoginNone()); + LoginBloc({ required this.authenticBloc}) : super(LoginNone()); @override Stream mapEventToState(LoginEvent event) async* { @@ -25,10 +25,10 @@ class LoginBloc extends Bloc { await Future.delayed(Duration(milliseconds: 500)); ResultBean result = await UserApi.login(username: event.username, password: event.password); - if (result.status) { + if (result.status&& result.data!=null) { // 注册成功 - authenticBloc.add(LoginOver(token: result.msg,user: result.data)); - yield LoginSuccess(result.data); + authenticBloc.add(LoginOver(token: result.msg,user: result.data!)); + yield LoginSuccess(result.data!); } else { yield LoginError('用户名和密码不匹配'); } diff --git a/lib/user_system/bloc/login/event.dart b/lib/user_system/bloc/login/event.dart index a213165..b0321dd 100644 --- a/lib/user_system/bloc/login/event.dart +++ b/lib/user_system/bloc/login/event.dart @@ -16,5 +16,5 @@ class DoLogin extends LoginEvent { final String username; final String password; - DoLogin({this.username, this.password}); + DoLogin({required this.username,required this.password}); } diff --git a/lib/user_system/bloc/register/bloc.dart b/lib/user_system/bloc/register/bloc.dart index 67dcf7d..c8350cf 100644 --- a/lib/user_system/bloc/register/bloc.dart +++ b/lib/user_system/bloc/register/bloc.dart @@ -22,7 +22,7 @@ class RegisterBloc extends Bloc { if(result.data == null){ yield RegisterError('注册失败'); }else{ - if (result.data) { + if (result.data!=null&&result.data!) { // 注册成功 yield RegisterSuccess(event.email); }else{ diff --git a/lib/user_system/component/authentic_widget.dart b/lib/user_system/component/authentic_widget.dart index 69b4137..055ca96 100644 --- a/lib/user_system/component/authentic_widget.dart +++ b/lib/user_system/component/authentic_widget.dart @@ -11,7 +11,7 @@ class AuthenticWidget extends StatelessWidget { final Widget authentic; final Widget noAuthentic; - const AuthenticWidget({this.authentic, this.noAuthentic}); + const AuthenticWidget({required this.authentic, required this.noAuthentic}); @override Widget build(BuildContext context) { diff --git a/lib/user_system/model/user.dart b/lib/user_system/model/user.dart index 2b670f1..6bcdfce 100644 --- a/lib/user_system/model/user.dart +++ b/lib/user_system/model/user.dart @@ -19,7 +19,7 @@ class User extends Equatable{ final String roles; final int userId; - const User({this.username, this.email, this.roles, this.userId,this.userAvatar}); + const User({required this.username,required this.email,required this.roles,required this.userId,required this.userAvatar}); factory User.fromJson(Map map) { return User( diff --git a/lib/user_system/pages/register/arc_clipper.dart b/lib/user_system/pages/register/arc_clipper.dart index 4fbf5a8..f444a38 100644 --- a/lib/user_system/pages/register/arc_clipper.dart +++ b/lib/user_system/pages/register/arc_clipper.dart @@ -27,10 +27,10 @@ class ArcClipper extends CustomClipper { } class ArcBackground extends StatelessWidget { - final Widget child; + final Widget? child; final ImageProvider image; - ArcBackground({this.child, this.image}); + ArcBackground({this.child,required this.image}); @override Widget build(BuildContext context) { @@ -52,7 +52,7 @@ class ArcBackground extends StatelessWidget { class UnitArcBackground extends StatelessWidget { final double height; - UnitArcBackground({Key key,this.height}) : super(key: key); + UnitArcBackground({Key? key,required this.height}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/lib/user_system/pages/register/register_page.dart b/lib/user_system/pages/register/register_page.dart index a36a36e..2423a86 100644 --- a/lib/user_system/pages/register/register_page.dart +++ b/lib/user_system/pages/register/register_page.dart @@ -172,7 +172,7 @@ class _RegisterPageState extends State { listener: _listenerLogin, child: ValueListenableBuilder( valueListenable: _enableRegister, - builder: (ctx,value,child){ + builder: (ctx,bool value,child){ return RaisedButton( elevation: 0, shape: RoundedRectangleBorder( diff --git a/lib/user_system/pages/register/send_code.dart b/lib/user_system/pages/register/send_code.dart index 76b60e9..3ae4c2c 100644 --- a/lib/user_system/pages/register/send_code.dart +++ b/lib/user_system/pages/register/send_code.dart @@ -7,16 +7,16 @@ import 'package:flutter/material.dart'; /// 说明: class CountDownWidget extends StatefulWidget { - final Function(BuildContext context) onPress; + final Function(BuildContext context)? onPress; - CountDownWidget({Key key, this.onPress}) : super(key: key); + CountDownWidget({Key? key, this.onPress}) : super(key: key); @override _CountDownWidgetState createState() => _CountDownWidgetState(); } class _CountDownWidgetState extends State { - Timer timer; + Timer? timer; int count = 60; bool startTimer = false; @@ -41,7 +41,7 @@ class _CountDownWidgetState extends State { setState(() { startTimer = true; }); - widget.onPress(context); + widget.onPress?.call(context); }, child: Text(startTimer ? '$count 秒后重试' : '获取验证码')); } diff --git a/lib/views/components/drop_selectable_widget.dart b/lib/views/components/drop_selectable_widget.dart index 799cf26..ca5d486 100644 --- a/lib/views/components/drop_selectable_widget.dart +++ b/lib/views/components/drop_selectable_widget.dart @@ -7,7 +7,7 @@ typedef OnDropSelected = void Function(int index); class DropSelectableWidget extends StatefulWidget { final List data; - final OnDropSelected onDropSelected; + final OnDropSelected? onDropSelected; final Color disableColor; final double iconSize; final double height; @@ -15,7 +15,7 @@ class DropSelectableWidget extends StatefulWidget { final double fontSize; const DropSelectableWidget( - {Key key, + {Key? key, this.data = const [], this.onDropSelected, this.disableColor = Colors.black, @@ -32,13 +32,13 @@ class DropSelectableWidget extends StatefulWidget { class _DropSelectableWidgetState extends State with SingleTickerProviderStateMixin { - FocusNode _node; + late FocusNode _node; bool _focused = false; - FocusAttachment _nodeAttachment; + late FocusAttachment _nodeAttachment; Color _color = Colors.white; - OverlayEntry _overlayEntry; - AnimationController _ctrl; - Animation animation; + OverlayEntry? _overlayEntry; + late AnimationController _ctrl; + late Animation animation; final LayerLink layerLink = LayerLink(); int _selectedIndex = 0; @@ -99,7 +99,7 @@ class _DropSelectableWidgetState extends State void _showOverlay() { _overlayEntry = _createOverlayEntry(); - Overlay.of(context).insert(_overlayEntry); + Overlay.of(context)?.insert(_overlayEntry!); } void _hideOverlay() { @@ -184,7 +184,7 @@ class _DropSelectableWidgetState extends State onTap: () { if (_selectedIndex != index) widget.onDropSelected?.call(index); _selectedIndex = index; - _overlayEntry.markNeedsBuild(); + _overlayEntry?.markNeedsBuild(); _node.unfocus(); }, child: Container( diff --git a/lib/views/components/flutter/no_div_expansion_tile.dart b/lib/views/components/flutter/no_div_expansion_tile.dart index 6dcbbe5..56998df 100644 --- a/lib/views/components/flutter/no_div_expansion_tile.dart +++ b/lib/views/components/flutter/no_div_expansion_tile.dart @@ -28,9 +28,9 @@ class NoBorderExpansionTile extends StatefulWidget { /// the tile to reveal or hide the [children]. The [initiallyExpanded] property must /// be non-null. const NoBorderExpansionTile({ - Key key, + Key? key, this.leading, - @required this.title, + required this.title, this.subtitle, this.backgroundColor, this.onExpansionChanged, @@ -43,7 +43,7 @@ class NoBorderExpansionTile extends StatefulWidget { /// A widget to display before the title. /// /// Typically a [CircleAvatar] widget. - final Widget leading; + final Widget? leading; /// The primary content of the list item. /// @@ -53,14 +53,14 @@ class NoBorderExpansionTile extends StatefulWidget { /// Additional content displayed below the title. /// /// Typically a [Text] widget. - final Widget subtitle; + final Widget? subtitle; /// Called when the tile expands or collapses. /// /// When the tile starts expanding, this function is called with the value /// true. When the tile starts collapsing, this function is called with /// the value false. - final ValueChanged onExpansionChanged; + final ValueChanged? onExpansionChanged; /// The widgets that are displayed when the tile expands. /// @@ -68,10 +68,10 @@ class NoBorderExpansionTile extends StatefulWidget { final List children; /// The color to display behind the sublist when expanded. - final Color backgroundColor; + final Color? backgroundColor; /// A widget to display instead of a rotating arrow icon. - final Widget trailing; + final Widget? trailing; /// Specifies if the list tile is initially expanded (true) or collapsed (false, the default). final bool initiallyExpanded; @@ -90,12 +90,12 @@ class _NoBorderExpansionTileState extends State with Sing final ColorTween _iconColorTween = ColorTween(); final ColorTween _backgroundColorTween = ColorTween(); - AnimationController _controller; - Animation _iconTurns; - Animation _heightFactor; - Animation _headerColor; - Animation _iconColor; - Animation _backgroundColor; + late AnimationController _controller; + late Animation _iconTurns; + late Animation _heightFactor; + late Animation _headerColor; + late Animation _iconColor; + late Animation _backgroundColor; bool _isExpanded = false; @@ -137,11 +137,10 @@ class _NoBorderExpansionTileState extends State with Sing } PageStorage.of(context)?.writeState(context, _isExpanded); }); - if (widget.onExpansionChanged != null) - widget.onExpansionChanged(_isExpanded); + widget.onExpansionChanged?.call(_isExpanded); } - Widget _buildChildren(BuildContext context, Widget child) { + Widget _buildChildren(BuildContext context, Widget? child) { return Container( color: _backgroundColor.value ?? Colors.transparent, @@ -180,7 +179,7 @@ class _NoBorderExpansionTileState extends State with Sing _borderColorTween ..end = theme.dividerColor; _headerColorTween - ..begin = theme.textTheme.subhead.color + ..begin = theme.textTheme.subhead?.color ..end = theme.accentColor; _iconColorTween ..begin = theme.unselectedWidgetColor diff --git a/lib/views/components/permanent/burst_menu.dart b/lib/views/components/permanent/burst_menu.dart index e4ae096..9a2fcdf 100644 --- a/lib/views/components/permanent/burst_menu.dart +++ b/lib/views/components/permanent/burst_menu.dart @@ -27,12 +27,12 @@ class BurstMenu extends StatefulWidget { final Duration duration; final BurstType burstType; final Curve curve; - final BurstMenuItemClick burstMenuItemClick; + final BurstMenuItemClick? burstMenuItemClick; const BurstMenu({ - Key key, - @required this.menus, - @required this.center, + Key? key, + required this.menus, + required this.center, this.radius = 100, this.swapAngle = 120, this.startAngle = -60, @@ -44,10 +44,10 @@ class BurstMenu extends StatefulWidget { }) : super(key: key); BurstMenu.topLeft({ - this.menus, + required this.menus, this.burstMenuItemClick, - this.radius, - this.center, + this.radius = 100, + required this.center, this.hideOpacity = 0, this.curve = Curves.ease, this.duration = const Duration(milliseconds: 300), @@ -57,10 +57,10 @@ class BurstMenu extends StatefulWidget { }); BurstMenu.bottomLeft({ - this.menus, + required this.menus, this.burstMenuItemClick, - this.radius, - this.center, + this.radius = 100, + required this.center, this.hideOpacity = 0, this.curve = Curves.ease, this.duration = const Duration(milliseconds: 300), @@ -70,10 +70,10 @@ class BurstMenu extends StatefulWidget { }); BurstMenu.topRight({ - this.menus, + required this.menus, this.burstMenuItemClick, - this.radius, - this.center, + this.radius = 100, + required this.center, this.hideOpacity = 0, this.curve = Curves.ease, this.duration = const Duration(milliseconds: 500), @@ -83,10 +83,10 @@ class BurstMenu extends StatefulWidget { }); BurstMenu.bottomRight({ - this.menus, + required this.menus, this.burstMenuItemClick, - this.radius, - this.center, + this.radius = 100, + required this.center, this.hideOpacity = 0, this.curve = Curves.ease, this.duration = const Duration(milliseconds: 300), @@ -101,11 +101,11 @@ class BurstMenu extends StatefulWidget { class BurstMenuState extends State with SingleTickerProviderStateMixin { - AnimationController _controller; + late AnimationController _controller; // 是否已关闭 bool _closed = true; - Animation curveAnim; // 1.定义曲线动画 + late Animation curveAnim; // 1.定义曲线动画 @override void initState() { @@ -114,8 +114,8 @@ class BurstMenuState extends State duration: widget.duration, vsync: this, ); - curveAnim = CurvedAnimation( - parent: _controller, curve: widget.curve); //<--2.创建曲线动画 + curveAnim = + CurvedAnimation(parent: _controller, curve: widget.curve); //<--2.创建曲线动画 } @override @@ -153,7 +153,7 @@ class BurstMenuState extends State toggle(); return; } - bool close = widget.burstMenuItemClick.call(index); + bool close = widget.burstMenuItemClick?.call(index) ?? false; if (close) toggle(); } @@ -207,7 +207,7 @@ class _CircleFlowDelegate extends FlowDelegate { void paintChildren(FlowPaintingContext context) { double radius = context.size.shortestSide / 2; final double halfCenterSize = - context.getChildSize(context.childCount - 1).width / 2; + context.getChildSize(context.childCount - 1)?.width ?? 0 / 2; switch (burstType) { case BurstType.circle: @@ -215,7 +215,7 @@ class _CircleFlowDelegate extends FlowDelegate { break; case BurstType.topLeft: Offset centerOffset = - Offset(-radius + halfCenterSize, -radius + halfCenterSize); + Offset(-radius + halfCenterSize, -radius + halfCenterSize); paintWithOffset(context, centerOffset); break; case BurstType.bottomLeft: @@ -249,8 +249,8 @@ class _CircleFlowDelegate extends FlowDelegate { if (animation.value > hideOpacity) { for (int i = 0; i < count; i++) { - final double cSizeX = context.getChildSize(i).width / 2; - final double cSizeY = context.getChildSize(i).height / 2; + final double cSizeX = context.getChildSize(i)?.width ?? 0 / 2; + final double cSizeY = context.getChildSize(i)?.height ?? 0 / 2; final double beforeRadius = (radius - cSizeX); final double now = beforeRadius + centerOffset.dy.abs(); @@ -277,15 +277,13 @@ class _CircleFlowDelegate extends FlowDelegate { } } + Size? size = context.getChildSize(context.childCount - 1); + if (size == null) return; context.paintChild( context.childCount - 1, transform: Matrix4.translationValues( - radius - - context.getChildSize(context.childCount - 1).width / 2 + - centerOffset.dx, - radius - - context.getChildSize(context.childCount - 1).height / 2 + - centerOffset.dy, + radius - size.width / 2 + centerOffset.dx, + radius - size.height / 2 + centerOffset.dy, 0.0, ), ); diff --git a/lib/views/components/permanent/circle.dart b/lib/views/components/permanent/circle.dart index e50a58f..7816653 100644 --- a/lib/views/components/permanent/circle.dart +++ b/lib/views/components/permanent/circle.dart @@ -4,7 +4,7 @@ class Circle extends StatelessWidget { final Color color; final double radius; final bool showShadow; - final Widget child; + final Widget? child; const Circle({this.color=Colors.blue, this.radius=6,this.showShadow=true,this.child}); diff --git a/lib/views/components/permanent/circle_image.dart b/lib/views/components/permanent/circle_image.dart index 08c628f..bcc81cd 100644 --- a/lib/views/components/permanent/circle_image.dart +++ b/lib/views/components/permanent/circle_image.dart @@ -2,17 +2,17 @@ import 'package:flutter/material.dart'; class CircleImage extends StatelessWidget { CircleImage( - {Key key, + {Key? key, this.borderSize =3, - @required this.image, + required this.image, this.size = 70, this.shadowColor, this.roundColor}) : super(key: key); final ImageProvider image; //图片 final double size; //大小 - final Color shadowColor; //阴影颜色 - final Color roundColor; //边框颜色 + final Color? shadowColor; //阴影颜色 + final Color? roundColor; //边框颜色 final double borderSize; @override Widget build(BuildContext context) { diff --git a/lib/views/components/permanent/circle_text.dart b/lib/views/components/permanent/circle_text.dart index f453082..de6c07e 100644 --- a/lib/views/components/permanent/circle_text.dart +++ b/lib/views/components/permanent/circle_text.dart @@ -2,8 +2,8 @@ import 'package:flutter/material.dart'; class CircleText extends StatelessWidget { CircleText( - {Key key, - @required this.text, + {Key? key, + required this.text, this.size = 70, this.fontSize = 24, this.color = Colors.white, @@ -14,10 +14,10 @@ class CircleText extends StatelessWidget { final String text; //图片 final double size; //大小 final double fontSize; //大小 - final Color shadowColor; //阴影颜色 + final Color? shadowColor; //阴影颜色 final Color color; //阴影颜色 - final Color roundColor; //边框颜色 - final Color backgroundColor; //边框颜色 + final Color? roundColor; //边框颜色 + final Color? backgroundColor; //边框颜色 @override Widget build(BuildContext context) { Widget headIcon = Container( diff --git a/lib/views/components/permanent/code/code_widget.dart b/lib/views/components/permanent/code/code_widget.dart index 2d787eb..c0f0c40 100644 --- a/lib/views/components/permanent/code/code_widget.dart +++ b/lib/views/components/permanent/code/code_widget.dart @@ -10,13 +10,13 @@ import 'high_light_code.dart'; import 'highlighter_style.dart'; class CodeWidget extends StatelessWidget { - CodeWidget({Key key, @required this.code, this.style, this.fontSize = 13,this.fontFamily}) + CodeWidget({Key? key, required this.code,required this.style, this.fontSize = 13,this.fontFamily}) : super(key: key); final String code; final HighlighterStyle style; final double fontSize; - final String fontFamily; + final String? fontFamily; @override Widget build(BuildContext context) { diff --git a/lib/views/components/permanent/code/high_light_code.dart b/lib/views/components/permanent/code/high_light_code.dart index d0dbabc..70f1470 100644 --- a/lib/views/components/permanent/code/high_light_code.dart +++ b/lib/views/components/permanent/code/high_light_code.dart @@ -20,24 +20,26 @@ abstract class Highlighter { // ignore: one_member_abstracts Language language; + + Highlighter({required this.language}); + TextSpan format(String src); } //暗黑模式下的高亮样式 class CodeHighlighter extends Highlighter { CodeHighlighter( - {Language language = const DartLanguage(), HighlighterStyle style}) { + {Language language = const DartLanguage(), HighlighterStyle? style}):super(language: language) { _spans = <_HighlightSpan>[]; - this.language = language; _style = style ?? HighlighterStyle.fromColors(HighlighterStyle.lightColor); } - HighlighterStyle _style; + late HighlighterStyle _style; - String _src; - StringScanner _scanner; + String _src=''; + late StringScanner _scanner; - List<_HighlightSpan> _spans; + List<_HighlightSpan> _spans=[]; @override TextSpan format(String src) { @@ -81,18 +83,18 @@ class CodeHighlighter extends Highlighter { // Block comments if (_scanner.scan(RegExp(r'/\*(.|\n)*\*/'))) { _spans.add(_HighlightSpan(_HighlightType.comment, - _scanner.lastMatch.start, _scanner.lastMatch.end)); + _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); continue; } // Line comments if (_scanner.scan('//')) { - final int startComment = _scanner.lastMatch.start; + final int startComment = _scanner.lastMatch?.start??0; bool eof = false; int endComment; if (_scanner.scan(RegExp(r'.*\n'))) { - endComment = _scanner.lastMatch.end - 1; + endComment = _scanner.lastMatch?.end??0 - 1; } else { eof = true; endComment = _src.length; @@ -108,77 +110,77 @@ class CodeHighlighter extends Highlighter { // Raw r"String" if (_scanner.scan(RegExp(r'r".*"'))) { _spans.add(_HighlightSpan(_HighlightType.string, - _scanner.lastMatch.start, _scanner.lastMatch.end)); + _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); continue; } // Raw r'String' if (_scanner.scan(RegExp(r"r'.*'"))) { _spans.add(_HighlightSpan(_HighlightType.string, - _scanner.lastMatch.start, _scanner.lastMatch.end)); + _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); continue; } // Multiline """String""" if (_scanner.scan(RegExp(r'"""(?:[^"\\]|\\(.|\n))*"""'))) { _spans.add(_HighlightSpan(_HighlightType.string, - _scanner.lastMatch.start, _scanner.lastMatch.end)); + _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); continue; } // Multiline '''String''' if (_scanner.scan(RegExp(r"'''(?:[^'\\]|\\(.|\n))*'''"))) { _spans.add(_HighlightSpan(_HighlightType.string, - _scanner.lastMatch.start, _scanner.lastMatch.end)); + _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); continue; } // "String" if (_scanner.scan(RegExp(r'"(?:[^"\\]|\\.)*"'))) { _spans.add(_HighlightSpan(_HighlightType.string, - _scanner.lastMatch.start, _scanner.lastMatch.end)); + _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); continue; } // 'String' if (_scanner.scan(RegExp(r"'(?:[^'\\]|\\.)*'"))) { _spans.add(_HighlightSpan(_HighlightType.string, - _scanner.lastMatch.start, _scanner.lastMatch.end)); + _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); continue; } // Double if (_scanner.scan(RegExp(r'\d+\.\d+'))) { _spans.add(_HighlightSpan(_HighlightType.number, - _scanner.lastMatch.start, _scanner.lastMatch.end)); + _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); continue; } // Integer if (_scanner.scan(RegExp(r'\d+'))) { _spans.add(_HighlightSpan(_HighlightType.number, - _scanner.lastMatch.start, _scanner.lastMatch.end)); + _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); continue; } // Punctuation if (_scanner.scan(RegExp(r'[\[\]{}().!=<>&\|\?\+\-\*/%\^~;:,]'))) { _spans.add(_HighlightSpan(_HighlightType.punctuation, - _scanner.lastMatch.start, _scanner.lastMatch.end)); + _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); continue; } // Meta data if (_scanner.scan(RegExp(r'@\w+'))) { _spans.add(_HighlightSpan(_HighlightType.keyword, - _scanner.lastMatch.start, _scanner.lastMatch.end)); + _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); continue; } // Words if (_scanner.scan(RegExp(r'\w+'))) { - _HighlightType type; - String word = _scanner.lastMatch[0]; + _HighlightType? type; + String word = _scanner.lastMatch?[0]??''; if (word.startsWith('_')) word = word.substring(1); @@ -195,7 +197,7 @@ class CodeHighlighter extends Highlighter { if (type != null) { _spans.add(_HighlightSpan( - type, _scanner.lastMatch.start, _scanner.lastMatch.end)); + type, _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); } } // Check if this loop did anything @@ -251,22 +253,22 @@ class _HighlightSpan { return src.substring(start, end); } - TextStyle textStyle(HighlighterStyle style) { + TextStyle? textStyle(HighlighterStyle? style) { if (type == _HighlightType.number) - return style.numberStyle; + return style?.numberStyle; else if (type == _HighlightType.comment) - return style.commentStyle; + return style?.commentStyle; else if (type == _HighlightType.keyword) - return style.keywordStyle; + return style?.keywordStyle; else if (type == _HighlightType.string) - return style.stringStyle; + return style?.stringStyle; else if (type == _HighlightType.punctuation) - return style.punctuationStyle; + return style?.punctuationStyle; else if (type == _HighlightType.klass) - return style.classStyle; + return style?.classStyle; else if (type == _HighlightType.constant) - return style.constantStyle; + return style?.constantStyle; else - return style.baseStyle; + return style?.baseStyle; } } diff --git a/lib/views/components/permanent/code/highlighter_style.dart b/lib/views/components/permanent/code/highlighter_style.dart index 3980bfc..ef08b3d 100644 --- a/lib/views/components/permanent/code/highlighter_style.dart +++ b/lib/views/components/permanent/code/highlighter_style.dart @@ -127,13 +127,13 @@ class HighlighterStyle { ), backgroundColor: Color(colors[8]), ); - final TextStyle baseStyle; - final TextStyle numberStyle; - final TextStyle commentStyle; - final TextStyle keywordStyle; - final TextStyle stringStyle; - final TextStyle punctuationStyle; - final TextStyle classStyle; - final TextStyle constantStyle; - final Color backgroundColor; + final TextStyle? baseStyle; + final TextStyle? numberStyle; + final TextStyle? commentStyle; + final TextStyle? keywordStyle; + final TextStyle? stringStyle; + final TextStyle? punctuationStyle; + final TextStyle? classStyle; + final TextStyle? constantStyle; + final Color? backgroundColor; } \ No newline at end of file diff --git a/lib/views/components/permanent/color_wrapper.dart b/lib/views/components/permanent/color_wrapper.dart index e14a0bd..231d951 100644 --- a/lib/views/components/permanent/color_wrapper.dart +++ b/lib/views/components/permanent/color_wrapper.dart @@ -5,14 +5,14 @@ import 'package:flutter/material.dart'; /// 说明: class WrapColor extends StatelessWidget { - final Widget child; - final Color color; + final Widget? child; + final Color? color; final double radius; final EdgeInsetsGeometry padding; WrapColor( {this.child, - this.color, + this.color, this.radius = 5, this.padding = const EdgeInsets.only(left: 4, right: 4, top: 0, bottom: 0)}); @@ -35,7 +35,7 @@ class Circled extends StatelessWidget { final Color color; final double radius; - Circled({this.child, this.color = Colors.blue, this.radius = 15}); + Circled({required this.child, this.color = Colors.blue, this.radius = 15}); @override Widget build(BuildContext context) { diff --git a/lib/views/components/permanent/edit_panel.dart b/lib/views/components/permanent/edit_panel.dart index 7143bf0..a562c6f 100644 --- a/lib/views/components/permanent/edit_panel.dart +++ b/lib/views/components/permanent/edit_panel.dart @@ -5,7 +5,7 @@ typedef ChangeCallback = void Function(String str); ///输入面板 class EditPanel extends StatefulWidget { EditPanel( - {Key key, + {Key? key, this.backgroundColor = Colors.white, this.color = Colors.lightBlue, this.minLines = 4, @@ -24,7 +24,7 @@ class EditPanel extends StatefulWidget { final double fontSize; //字号 final String hint; //提示字 final bool submitClear; //提交是否清空文字 - final ChangeCallback onChange; //提交监听 + final ChangeCallback? onChange; //提交监听 final String defaultText; //提交监听 @override @@ -32,14 +32,14 @@ class EditPanel extends StatefulWidget { } class _EditPanelState extends State { - Radius _radius; //边角半径 + Radius _radius=Radius.zero; //边角半径 - TextEditingController _controller; + late TextEditingController _controller; @override void initState() { _radius = Radius.circular(widget.fontSize * 0.618); - _controller = TextEditingController(text: widget.defaultText??''); + _controller = TextEditingController(text: widget.defaultText); super.initState(); } @@ -92,7 +92,7 @@ class _EditPanelState extends State { ), onChanged: (str) { //文字变化监听 - if (widget.onChange != null) widget.onChange(str); + widget.onChange?.call(str); }, onSubmitted: (str) { //提交监听 diff --git a/lib/views/components/permanent/feedback_widget.dart b/lib/views/components/permanent/feedback_widget.dart index 235e87c..d7090a4 100644 --- a/lib/views/components/permanent/feedback_widget.dart +++ b/lib/views/components/permanent/feedback_widget.dart @@ -16,13 +16,13 @@ class FeedbackWidget extends StatefulWidget { final Widget child; final FeedMode mode; final Duration duration; - final Function() onPressed; - final Function() onEnd; - final Function() onLongPressed; + final Function()? onPressed; + final Function()? onEnd; + final Function()? onLongPressed; final a; FeedbackWidget({ - @required this.child, + required this.child, this.mode = FeedMode.scale, this.a = 0.9, this.onLongPressed, @@ -36,7 +36,7 @@ class FeedbackWidget extends StatefulWidget { } class _FeedBackState extends State with SingleTickerProviderStateMixin { - AnimationController _controller; + late AnimationController _controller; @override void initState() { @@ -47,7 +47,7 @@ class _FeedBackState extends State with SingleTickerProviderStat )..addStatusListener((s) { if (s == AnimationStatus.completed) { _controller.reverse().then((value) { - if (widget.onEnd != null) widget.onEnd(); + widget.onEnd?.call(); }); } }); @@ -77,9 +77,7 @@ class _FeedBackState extends State with SingleTickerProviderStat onLongPress: widget.onLongPressed, onTap: () { _controller.forward(); - if (widget.onPressed != null) { - widget.onPressed(); - } + widget.onPressed?.call(); }, child: AnimatedBuilder( animation: _controller, @@ -88,7 +86,7 @@ class _FeedBackState extends State with SingleTickerProviderStat )); } - Widget _buildByMode(Widget child, FeedMode mode) { + Widget _buildByMode(Widget? child, FeedMode mode) { double rate = (widget.a - 1) * _controller.value + 1; switch (mode) { case FeedMode.scale: diff --git a/lib/views/components/permanent/icon_input.dart b/lib/views/components/permanent/icon_input.dart index bbd7cc9..71bef62 100644 --- a/lib/views/components/permanent/icon_input.dart +++ b/lib/views/components/permanent/icon_input.dart @@ -9,7 +9,7 @@ class IconInput extends StatelessWidget { final Widget textFiled; final IconData icon; - IconInput({Key key,this.textFiled,this.icon}) : super(key: key); + IconInput({Key? key,required this.textFiled,required this.icon}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/lib/views/components/permanent/input_button.dart b/lib/views/components/permanent/input_button.dart index d82b261..ba64a54 100644 --- a/lib/views/components/permanent/input_button.dart +++ b/lib/views/components/permanent/input_button.dart @@ -7,13 +7,11 @@ class InputButtonConfig { final IconData iconData; //图标 final String hint; //提示文字 final double fontSize; //文字大小 - final Widget front; //前面图标 + final Widget? front; //前面图标 final bool submitClear; //是否提交清空 - const InputButtonConfig( {this.height = 36, - this.iconData = Icons.add, this.fontSize = 14, this.submitClear = true, @@ -22,17 +20,17 @@ class InputButtonConfig { } class InputButton extends StatefulWidget { - final SubmitCallback onSubmit; - final ValueChanged onChanged; - final VoidCallback onTap; + final SubmitCallback? onSubmit; + final ValueChanged? onChanged; + final VoidCallback? onTap; final InputButtonConfig config; final String defaultText; InputButton( - {Key key, + {Key? key, this.onSubmit, this.onChanged, - this.defaultText, + this.defaultText = '请输入', this.onTap, this.config = const InputButtonConfig()}) : super(key: key); @@ -42,11 +40,11 @@ class InputButton extends StatefulWidget { } class _InputButtonState extends State { - double _height; - double _fontSize; - Radius _radius; + double _height = 0; + double _fontSize = 0; + Radius _radius = Radius.zero; - TextEditingController _controller; + late TextEditingController _controller; @override void initState() { @@ -54,7 +52,7 @@ class _InputButtonState extends State { _height = widget.config.height; _fontSize = widget.config.fontSize; _radius = Radius.circular(_height / 3.6); - _controller = TextEditingController(text: widget.defaultText??''); + _controller = TextEditingController(text: widget.defaultText); } @override @@ -90,7 +88,7 @@ class _InputButtonState extends State { ), ), onChanged: (str) { - if (widget.onChanged != null) widget.onChanged(str); + widget.onChanged?.call(str); }, onTap: widget.onTap, ); @@ -102,7 +100,7 @@ class _InputButtonState extends State { padding: EdgeInsets.zero, onPressed: () { FocusScope.of(context).requestFocus(FocusNode()); //收起键盘 - if (widget.onSubmit != null) widget.onSubmit(_controller.text); + widget.onSubmit?.call(_controller.text); if (widget.config.submitClear) { setState(() { _controller.clear(); diff --git a/lib/views/components/permanent/markdown/markdown_widget.dart b/lib/views/components/permanent/markdown/markdown_widget.dart index 188038c..b3984c1 100644 --- a/lib/views/components/permanent/markdown/markdown_widget.dart +++ b/lib/views/components/permanent/markdown/markdown_widget.dart @@ -113,7 +113,7 @@ class MarkdownWidget extends StatelessWidget { Iterable tags = exp.allMatches(markdownData); if (tags != null && tags.length > 0) { for (Match m in tags) { - String imageMatch = m.group(0); + String imageMatch = m.group(0)??''; if (imageMatch != null && !imageMatch.contains(".svg")) { String match = imageMatch.replaceAll("\)", "?raw=true)"); if (!match.contains(".svg") && match.contains("http")) { @@ -126,7 +126,7 @@ class MarkdownWidget extends StatelessWidget { } else { match = ""; } - mdDataCode = mdDataCode.replaceAll(m.group(0), match); + mdDataCode = mdDataCode.replaceAll(m.group(0)??'', match); } } } @@ -135,12 +135,12 @@ class MarkdownWidget extends StatelessWidget { tags = expImg.allMatches(markdownData); if (tags != null && tags.length > 0) { for (Match m in tags) { - String imageTag = m.group(0); + String imageTag = m.group(0)??''; String match = imageTag; if (imageTag != null) { Iterable srcTags = expSrc.allMatches(imageTag); for (Match srcMatch in srcTags) { - String srcString = srcMatch.group(0); + String srcString = srcMatch.group(0)??''; if (srcString != null && srcString.contains("http")) { String newSrc = srcString.substring( srcString.indexOf("http"), srcString.length - 1) + @@ -168,7 +168,7 @@ class MarkdownWidget extends StatelessWidget { styleSheet: _getStyle(context), syntaxHighlighter: Highlighter(), data: _getMarkDownData(markdownData), - onTapLink: (String text, String href, String title) { + onTapLink: (String text, String? href, String title) { // CommonUtils.launchUrl(context, source); }, ), diff --git a/lib/views/components/permanent/markdown/syntax_high_lighter.dart b/lib/views/components/permanent/markdown/syntax_high_lighter.dart index 305bb11..350aed7 100644 --- a/lib/views/components/permanent/markdown/syntax_high_lighter.dart +++ b/lib/views/components/permanent/markdown/syntax_high_lighter.dart @@ -26,14 +26,14 @@ class SyntaxHighlighterStyle { constantStyle: TextStyle(color: Colors.brown[500])); } - final TextStyle baseStyle; - final TextStyle numberStyle; - final TextStyle commentStyle; - final TextStyle keywordStyle; - final TextStyle stringStyle; - final TextStyle punctuationStyle; - final TextStyle classStyle; - final TextStyle constantStyle; + final TextStyle? baseStyle; + final TextStyle? numberStyle; + final TextStyle? commentStyle; + final TextStyle? keywordStyle; + final TextStyle? stringStyle; + final TextStyle? punctuationStyle; + final TextStyle? classStyle; + final TextStyle? constantStyle; } abstract class SyntaxCostomHighlighter { @@ -47,9 +47,9 @@ class DartSyntaxHighlighter extends SyntaxCostomHighlighter { if (_style == null) _style = SyntaxHighlighterStyle.defaultStyle(); } - SyntaxHighlighterStyle _style; + SyntaxHighlighterStyle? _style; - static const List _kKeywords = const [ + static const List _kKeywords = [ 'abstract', 'as', 'assert', @@ -124,17 +124,17 @@ class DartSyntaxHighlighter extends SyntaxCostomHighlighter { 'instanceof' ]; - static const List _kBuiltInTypes = const [ + static const List _kBuiltInTypes = [ 'int', 'double', 'num', 'bool' ]; - String _src; - StringScanner _scanner; + String _src=''; + late StringScanner _scanner; - List<_HighlightSpan> _spans; + List<_HighlightSpan> _spans =[]; TextSpan format(String src) { _src = src; @@ -160,10 +160,10 @@ class DartSyntaxHighlighter extends SyntaxCostomHighlighter { formattedText.add( TextSpan(text: _src.substring(currentPosition, _src.length))); - return TextSpan(style: _style.baseStyle, children: formattedText); + return TextSpan(style: _style?.baseStyle, children: formattedText); } else { // Parsing failed, return with only basic formatting - return TextSpan(style: _style.baseStyle, text: src); + return TextSpan(style: _style?.baseStyle, text: src); } } @@ -178,18 +178,18 @@ class DartSyntaxHighlighter extends SyntaxCostomHighlighter { // Block comments if (_scanner.scan( RegExp(r"/\*(.|\n)*\*/"))) { _spans.add( _HighlightSpan(_HighlightType.comment, - _scanner.lastMatch.start, _scanner.lastMatch.end)); + _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); continue; } // Line comments if (_scanner.scan("//")) { - int startComment = _scanner.lastMatch.start; + int startComment = _scanner.lastMatch?.start??0; bool eof = false; int endComment; if (_scanner.scan( RegExp(r".*\n"))) { - endComment = _scanner.lastMatch.end - 1; + endComment = _scanner.lastMatch?.end??0 - 1; } else { eof = true; endComment = _src.length; @@ -204,13 +204,13 @@ class DartSyntaxHighlighter extends SyntaxCostomHighlighter { } if (_scanner.scan("#")) { - int startComment = _scanner.lastMatch.start; + int startComment = _scanner.lastMatch?.start??0; bool eof = false; int endComment; if (_scanner.scan( RegExp(r".*\n"))) { - endComment = _scanner.lastMatch.end - 1; + endComment = _scanner.lastMatch?.end??0 - 1; } else { eof = true; endComment = _src.length; @@ -226,85 +226,85 @@ class DartSyntaxHighlighter extends SyntaxCostomHighlighter { // Raw r"String" if (_scanner.scan( RegExp(r'r".*"'))) { _spans.add( _HighlightSpan(_HighlightType.string, - _scanner.lastMatch.start, _scanner.lastMatch.end)); + _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); continue; } // Raw r'String' if (_scanner.scan( RegExp(r"r'.*'"))) { _spans.add( _HighlightSpan(_HighlightType.string, - _scanner.lastMatch.start, _scanner.lastMatch.end)); + _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); continue; } // Multiline """String""" if (_scanner.scan( RegExp(r'"""(?:[^"\\]|\\(.|\n))*"""'))) { _spans.add( _HighlightSpan(_HighlightType.string, - _scanner.lastMatch.start, _scanner.lastMatch.end)); + _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); continue; } // Multiline '''String''' if (_scanner.scan( RegExp(r"'''(?:[^'\\]|\\(.|\n))*'''"))) { _spans.add( _HighlightSpan(_HighlightType.string, - _scanner.lastMatch.start, _scanner.lastMatch.end)); + _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); continue; } // "String" if (_scanner.scan( RegExp(r'"(?:[^"\\]|\\.)*"'))) { _spans.add( _HighlightSpan(_HighlightType.string, - _scanner.lastMatch.start, _scanner.lastMatch.end)); + _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); continue; } // 'String' if (_scanner.scan( RegExp(r"'(?:[^'\\]|\\.)*'"))) { _spans.add( _HighlightSpan(_HighlightType.string, - _scanner.lastMatch.start, _scanner.lastMatch.end)); + _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); continue; } // Double if (_scanner.scan( RegExp(r"\d+\.\d+"))) { _spans.add( _HighlightSpan(_HighlightType.number, - _scanner.lastMatch.start, _scanner.lastMatch.end)); + _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); continue; } // Integer if (_scanner.scan( RegExp(r"\d+"))) { _spans.add( _HighlightSpan(_HighlightType.number, - _scanner.lastMatch.start, _scanner.lastMatch.end)); + _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); continue; } // Punctuation if (_scanner.scan( RegExp(r"[\[\]{}().!=<>&\|\?\+\-\*/%\^~;:,]"))) { _spans.add( _HighlightSpan(_HighlightType.punctuation, - _scanner.lastMatch.start, _scanner.lastMatch.end)); + _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); continue; } //中文 if (_scanner.scan( RegExp(r"[\u4e00-\u9fa5]"))) { _spans.add( _HighlightSpan(_HighlightType.punctuation, - _scanner.lastMatch.start, _scanner.lastMatch.end)); + _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); continue; } // Metadata if (_scanner.scan( RegExp(r"@\w+"))) { _spans.add( _HighlightSpan(_HighlightType.keyword, - _scanner.lastMatch.start, _scanner.lastMatch.end)); + _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); continue; } // Words if (_scanner.scan( RegExp(r"\w+"))) { - _HighlightType type; + _HighlightType? type; - String word = _scanner.lastMatch[0]; + String word = _scanner.lastMatch![0]!; if (word.startsWith("_")) word = word.substring(1); if (_kKeywords.contains(word)) @@ -320,7 +320,7 @@ class DartSyntaxHighlighter extends SyntaxCostomHighlighter { if (type != null) { _spans.add( _HighlightSpan( - type, _scanner.lastMatch.start, _scanner.lastMatch.end)); + type, _scanner.lastMatch?.start??0, _scanner.lastMatch?.end??0)); } } @@ -387,22 +387,22 @@ class _HighlightSpan { return src.substring(start, end); } - TextStyle textStyle(SyntaxHighlighterStyle style) { + TextStyle? textStyle(SyntaxHighlighterStyle? style) { if (type == _HighlightType.number) - return style.numberStyle; + return style?.numberStyle; else if (type == _HighlightType.comment) - return style.commentStyle; + return style?.commentStyle; else if (type == _HighlightType.keyword) - return style.keywordStyle; + return style?.keywordStyle; else if (type == _HighlightType.string) - return style.stringStyle; + return style?.stringStyle; else if (type == _HighlightType.punctuation) - return style.punctuationStyle; + return style?.punctuationStyle; else if (type == _HighlightType.klass) - return style.classStyle; + return style?.classStyle; else if (type == _HighlightType.constant) - return style.constantStyle; + return style?.constantStyle; else - return style.baseStyle; + return style?.baseStyle; } } diff --git a/lib/views/components/permanent/math_runner.dart b/lib/views/components/permanent/math_runner.dart index dcf611b..7858eed 100644 --- a/lib/views/components/permanent/math_runner.dart +++ b/lib/views/components/permanent/math_runner.dart @@ -7,9 +7,10 @@ import 'package:flutter/material.dart'; typedef FunNum1 = Function(double t); class MathRunner extends StatefulWidget { - MathRunner({Key key, this.child, this.f, this.g, this.reverse = true}) + MathRunner({Key? key, this.child,required this.f,required this.g, this.reverse = true}) : super(key: key); - final Widget child; + + final Widget? child; final FunNum1 f; final FunNum1 g; final bool reverse; @@ -20,8 +21,8 @@ class MathRunner extends StatefulWidget { class _MathRunnerState extends State with SingleTickerProviderStateMixin { - AnimationController _controller; - Animation animationX; + late AnimationController _controller; + late Animation animationX; double _x = -1.0; double _y = 0; diff --git a/lib/views/components/permanent/multi_chip_filter.dart b/lib/views/components/permanent/multi_chip_filter.dart index a9fa792..a20399f 100644 --- a/lib/views/components/permanent/multi_chip_filter.dart +++ b/lib/views/components/permanent/multi_chip_filter.dart @@ -9,10 +9,10 @@ typedef BoolWidgetBuilder = Widget Function(BuildContext context, bool selected) class MultiChipFilter extends StatefulWidget { final List data; final BoolWidgetBuilder labelBuilder; - final IndexedWidgetBuilder avatarBuilder; + final IndexedWidgetBuilder? avatarBuilder; final Function(List) onChange; - MultiChipFilter({@required this.data,@required this.labelBuilder,this.avatarBuilder,@required this.onChange}); + MultiChipFilter({required this.data,required this.labelBuilder,this.avatarBuilder,required this.onChange}); @override _MultiChipFilterState createState() => _MultiChipFilterState(); @@ -39,7 +39,7 @@ class _MultiChipFilterState extends State> { shadowColor: Colors.orangeAccent, pressElevation: 5, elevation: 3, - avatar: widget.avatarBuilder==null?null:widget.avatarBuilder(context,index), + avatar: widget.avatarBuilder==null?null:widget.avatarBuilder!(context,index), label: widget.labelBuilder(context,selected), selected: selected, onSelected: (bool value) { diff --git a/lib/views/components/permanent/panel.dart b/lib/views/components/permanent/panel.dart index 86f1a90..b2ea134 100644 --- a/lib/views/components/permanent/panel.dart +++ b/lib/views/components/permanent/panel.dart @@ -4,10 +4,10 @@ import 'package:flutter/material.dart'; class Panel extends StatelessWidget { final double radius; - final Color color; - final Widget child; + final Color? color; + final Widget? child; - Panel({this.radius = 5.0, this.color, this.child}); + Panel({this.radius = 5.0, this.color, this.child}); @override Widget build(BuildContext context) { diff --git a/lib/views/components/permanent/tag.dart b/lib/views/components/permanent/tag.dart index 957d3c7..fb54cb5 100644 --- a/lib/views/components/permanent/tag.dart +++ b/lib/views/components/permanent/tag.dart @@ -34,7 +34,7 @@ class _TagPaint extends CustomPainter { final rate = 0.5; - _TagPaint({this.tranRate, this.color ,this.shadowHeight}) + _TagPaint({this.tranRate,required this.color ,required this.shadowHeight}) : _paint = Paint()..color = color; @override diff --git a/lib/views/components/permanent/text_typer.dart b/lib/views/components/permanent/text_typer.dart index 52ca628..fd36b9b 100644 --- a/lib/views/components/permanent/text_typer.dart +++ b/lib/views/components/permanent/text_typer.dart @@ -8,8 +8,8 @@ class TextTyper extends StatefulWidget { final TextStyle textStyle; TextTyper( - {this.text, - Key key, + {required this.text, + Key? key, this.textStyle = const TextStyle(fontWeight: FontWeight.w600, fontSize: 20.0), this.duration = const Duration(milliseconds: 150)}) @@ -21,7 +21,7 @@ class TextTyper extends StatefulWidget { class _TextTyperState extends State { final ValueNotifier data = ValueNotifier(""); - Timer _timer; + Timer? _timer; @override void initState() { @@ -58,7 +58,7 @@ class _TextTyperState extends State { ); } - Widget _buildByAnim(BuildContext context, Widget child) => Text( + Widget _buildByAnim(BuildContext context, Widget? child) => Text( data.value, style: widget.textStyle, ); diff --git a/lib/views/components/project/color_chooser.dart b/lib/views/components/project/color_chooser.dart index f012ee2..a3eddc4 100644 --- a/lib/views/components/project/color_chooser.dart +++ b/lib/views/components/project/color_chooser.dart @@ -6,15 +6,15 @@ typedef CheckCallback = void Function(T color); class ColorChooser extends StatefulWidget { ColorChooser( - {Key key, + {Key? key, this.defaultIndex=0, this.radius = 10, - @required this.colors, - @required this.onChecked}) + required this.colors, + required this.onChecked}) : super(key: key); final double radius; final List colors; - final Function(Color) onChecked; + final Function(Color)? onChecked; final int defaultIndex; @override @@ -22,7 +22,7 @@ class ColorChooser extends StatefulWidget { } class _ColorChooserState extends State { - List _checkLi; + List _checkLi=[]; int _perPosition = 0; @override @@ -43,7 +43,7 @@ class _ColorChooserState extends State { _checkLi[_perPosition] = false; _perPosition = i; _checkLi[i] = true; - if (widget.onChecked != null) widget.onChecked(widget.colors[i]); + widget.onChecked?.call(widget.colors[i]); setState(() {}); }, child: Circle( @@ -55,7 +55,7 @@ class _ColorChooserState extends State { size: 15, color: Colors.white, ) - : null, + : const SizedBox.shrink(), // checked: _checkLi[i] ))); } @@ -65,10 +65,10 @@ class _ColorChooserState extends State { class IconChooser extends StatefulWidget { IconChooser( - {Key key, + {Key? key, this.radius = 20, - @required this.icons, - @required this.onChecked, + required this.icons, + required this.onChecked, this.initialIndex = 0}) : super(key: key); final double radius; @@ -81,7 +81,7 @@ class IconChooser extends StatefulWidget { } class _IconChooserState extends State { - List _checkLi; + List _checkLi=[]; int _perPosition = 0; @override @@ -112,7 +112,7 @@ class _IconChooserState extends State { children: li); } - buildIcon({bool checked, IconData icon}) { + Widget buildIcon({bool checked = false, IconData? icon}) { Color defaultColor = Colors.black26; Color activeColor = Colors.blue; return Icon( diff --git a/lib/views/components/project/default/empty_shower.dart b/lib/views/components/project/default/empty_shower.dart index 8dcc0b0..bfaed4f 100644 --- a/lib/views/components/project/default/empty_shower.dart +++ b/lib/views/components/project/default/empty_shower.dart @@ -8,7 +8,7 @@ import 'package:flutter_unit/app/res/style_unit.dart'; class EmptyShower extends StatelessWidget { final String message; - const EmptyShower({Key key, this.message = "数据为空"}) : super(key: key); + const EmptyShower({Key? key, this.message = "数据为空"}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/lib/views/components/project/default/error_shower.dart b/lib/views/components/project/default/error_shower.dart index baae700..58ef75c 100644 --- a/lib/views/components/project/default/error_shower.dart +++ b/lib/views/components/project/default/error_shower.dart @@ -9,7 +9,7 @@ import 'package:flutter_unit/app/res/style_unit.dart'; class ErrorShower extends StatelessWidget { final String error; - ErrorShower({Key key, this.error = "出现异常"}) : super(key: key); + ErrorShower({Key? key, this.error = "出现异常"}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/lib/views/components/project/default/loading_shower.dart b/lib/views/components/project/default/loading_shower.dart index bba59bd..5d73c75 100644 --- a/lib/views/components/project/default/loading_shower.dart +++ b/lib/views/components/project/default/loading_shower.dart @@ -7,7 +7,7 @@ import 'package:flutter_unit/app/res/style_unit.dart'; /// 说明: 默认 加载视图 class LoadingShower extends StatelessWidget { - const LoadingShower({Key key}) : super(key: key); + const LoadingShower({Key? key}) : super(key: key); @override diff --git a/lib/views/components/project/dialogs/delete_category_dialog.dart b/lib/views/components/project/dialogs/delete_category_dialog.dart index 1296f23..2f0ba8e 100644 --- a/lib/views/components/project/dialogs/delete_category_dialog.dart +++ b/lib/views/components/project/dialogs/delete_category_dialog.dart @@ -8,7 +8,7 @@ import 'package:flutter_unit/views/components/permanent/feedback_widget.dart'; class DeleteCategoryDialog extends StatelessWidget { final String title; final String content; - final Function() onSubmit; + final VoidCallback? onSubmit; DeleteCategoryDialog({ diff --git a/lib/views/components/project/items/category_list_item.dart b/lib/views/components/project/items/category_list_item.dart index 81681c7..ab4b1db 100644 --- a/lib/views/components/project/items/category_list_item.dart +++ b/lib/views/components/project/items/category_list_item.dart @@ -10,10 +10,10 @@ import 'package:flutter_unit/model/category_model.dart'; class CategoryListItem extends StatelessWidget { final CategoryModel data; - final Function(CategoryModel) onDeleteItemClick; - final Function(CategoryModel) onEditItemClick; + final Function(CategoryModel)? onDeleteItemClick; + final Function(CategoryModel)? onEditItemClick; - CategoryListItem({this.data, this.onDeleteItemClick,this.onEditItemClick}); + CategoryListItem({required this.data, this.onDeleteItemClick,this.onEditItemClick}); @override Widget build(BuildContext context) { @@ -59,9 +59,7 @@ class CategoryListItem extends StatelessWidget { child: FeedbackWidget( onPressed: () { - if (onEditItemClick != null) { - onEditItemClick(data); - } + onEditItemClick?.call(data); }, child: Icon( Icons.edit, @@ -103,9 +101,7 @@ class CategoryListItem extends StatelessWidget { )), FeedbackWidget( onPressed: () { - if (onDeleteItemClick != null) { - onDeleteItemClick(data); - } + onDeleteItemClick?.call(data); }, child: const Icon( CupertinoIcons.delete_solid, diff --git a/lib/views/components/project/items/collect_widget_list_item.dart b/lib/views/components/project/items/collect_widget_list_item.dart index 48ea5a5..de81395 100644 --- a/lib/views/components/project/items/collect_widget_list_item.dart +++ b/lib/views/components/project/items/collect_widget_list_item.dart @@ -10,9 +10,9 @@ import 'package:flutter_unit/model/widget_model.dart'; class CollectWidgetListItem extends StatelessWidget { final WidgetModel data; - final Function(WidgetModel) onDeleteItemClick; + final Function(WidgetModel model)? onDeleteItemClick; - CollectWidgetListItem({this.data, this.onDeleteItemClick}); + CollectWidgetListItem({required this.data, this.onDeleteItemClick}); @override Widget build(BuildContext context) { @@ -49,9 +49,7 @@ class CollectWidgetListItem extends StatelessWidget { right: 5, child: FeedbackWidget( onPressed: () { - if (onDeleteItemClick != null) { - onDeleteItemClick(data); - } + onDeleteItemClick?.call(data); }, child: const Icon( CupertinoIcons.delete_solid, @@ -74,7 +72,7 @@ class CollectWidgetListItem extends StatelessWidget { ), ) : CircleImage( - image: data.image, + image: data.image!, size: 50, ), ); diff --git a/lib/views/components/project/items/gallery/gallery_card_item.dart b/lib/views/components/project/items/gallery/gallery_card_item.dart index 5ea88a0..07fe690 100644 --- a/lib/views/components/project/items/gallery/gallery_card_item.dart +++ b/lib/views/components/project/items/gallery/gallery_card_item.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_unit/app/utils/convert.dart'; -import 'package:flutter_unit/views/components/permanent/color_wrapper.dart'; import 'package:flutter_unit/painter_system/gallery_factory.dart'; +import 'package:flutter_unit/views/components/permanent/color_wrapper.dart'; /// create by 张风捷特烈 on 2020/11/28 /// contact me by email 1981462002@qq.com @@ -10,7 +10,12 @@ import 'package:flutter_unit/painter_system/gallery_factory.dart'; class GalleryCardItem extends StatelessWidget { final GalleryInfo galleryInfo; final int count; - GalleryCardItem({Key key, this.galleryInfo,this.count=0}) : super(key: key); + + GalleryCardItem({ + Key? key, + required this.galleryInfo, + this.count = 0, + }) : super(key: key); @override Widget build(BuildContext context) { @@ -112,7 +117,7 @@ class GalleryInfo { } const GalleryInfo( - {this.count = 0, this.name, this.info, this.image, this.router}); + {this.count = 0,required this.name,required this.info,required this.image,required this.router}); factory GalleryInfo.fromJson(Map map) { return GalleryInfo( diff --git a/lib/views/components/project/items/widget/coupon_widget_list_item.dart b/lib/views/components/project/items/widget/coupon_widget_list_item.dart index edf2a04..e19b63e 100644 --- a/lib/views/components/project/items/widget/coupon_widget_list_item.dart +++ b/lib/views/components/project/items/widget/coupon_widget_list_item.dart @@ -16,7 +16,7 @@ class CouponWidgetListItem extends StatelessWidget { final bool isClip; CouponWidgetListItem( - {this.data, + {required this.data, this.hasTopHole = true, this.hasBottomHole = false, this.isClip = true}); @@ -80,7 +80,7 @@ class CouponWidgetListItem extends StatelessWidget { ), ) : CircleImage( - image: data.image, + image: data.image!, size: 60, ), ), @@ -122,7 +122,7 @@ class CouponWidgetListItem extends StatelessWidget { style: TextStyle( fontSize: 17, fontWeight: FontWeight.bold, - decoration: (data.deprecated??false)?TextDecoration.lineThrough:TextDecoration.none, + decoration: data.deprecated?TextDecoration.lineThrough:TextDecoration.none, decorationThickness: 2, shadows: [ Shadow(color: Colors.white, offset: Offset(.3, .3)) diff --git a/lib/views/components/project/items/widget/home_item_support.dart b/lib/views/components/project/items/widget/home_item_support.dart index 7f91e9a..3e3313b 100644 --- a/lib/views/components/project/items/widget/home_item_support.dart +++ b/lib/views/components/project/items/widget/home_item_support.dart @@ -52,6 +52,7 @@ class HomeItemSupport { id: Random().nextInt(10000), name: 'Container', nameCN: "", + links: [], lever: 5, family: WidgetFamily.statelessWidget, info: '用于容纳单个子组件的容器组件。集成了若干个单子组件的功能,如内外边距、形变、装饰、约束等...'); diff --git a/lib/views/components/project/items/widget/simple_widget_list_item.dart b/lib/views/components/project/items/widget/simple_widget_list_item.dart index 5afc499..ec5473d 100644 --- a/lib/views/components/project/items/widget/simple_widget_list_item.dart +++ b/lib/views/components/project/items/widget/simple_widget_list_item.dart @@ -17,7 +17,7 @@ class SimpleWidgetListItem extends StatelessWidget { final WidgetModel data; SimpleWidgetListItem({ - this.data, + required this.data, }); @override @@ -104,7 +104,7 @@ class SimpleWidgetListItem extends StatelessWidget { ), ) : CircleImage( - image: data.image, + image: data.image!, size: 55, ), ); @@ -121,7 +121,7 @@ class SimpleWidgetListItem extends StatelessWidget { style: TextStyle( fontSize: 17, fontWeight: FontWeight.bold, - decoration: (data.deprecated??false)?TextDecoration.lineThrough:TextDecoration.none, + decoration: data.deprecated?TextDecoration.lineThrough:TextDecoration.none, decorationThickness: 2, shadows: [ Shadow(color: Colors.white, offset: Offset(.3, .3)) diff --git a/lib/views/components/project/items/widget/techno_widget_list_item.dart b/lib/views/components/project/items/widget/techno_widget_list_item.dart index 1c13290..69f211d 100644 --- a/lib/views/components/project/items/widget/techno_widget_list_item.dart +++ b/lib/views/components/project/items/widget/techno_widget_list_item.dart @@ -13,7 +13,7 @@ import 'package:flutter_unit/model/widget_model.dart'; class TechnoWidgetListItem extends StatelessWidget { final WidgetModel data; - TechnoWidgetListItem({this.data}); + TechnoWidgetListItem({required this.data}); @override Widget build(BuildContext context) { @@ -98,7 +98,7 @@ class TechnoWidgetListItem extends StatelessWidget { ), ) : CircleImage( - image: data.image, + image: data.image!, size: 55, ), ); @@ -115,7 +115,7 @@ class TechnoWidgetListItem extends StatelessWidget { style: TextStyle( fontSize: 17, fontWeight: FontWeight.bold, - decoration: (data.deprecated??false)?TextDecoration.lineThrough:TextDecoration.none, + decoration: data.deprecated?TextDecoration.lineThrough:TextDecoration.none, decorationThickness: 2, shadows: [ Shadow(color: Colors.white, offset: Offset(.3, .3)) diff --git a/lib/views/components/project/nav/unit_bottom_bar.dart b/lib/views/components/project/nav/unit_bottom_bar.dart index 6c5d615..cbe7b31 100644 --- a/lib/views/components/project/nav/unit_bottom_bar.dart +++ b/lib/views/components/project/nav/unit_bottom_bar.dart @@ -14,14 +14,14 @@ class UnitBottomBar extends StatefulWidget { final Color color; // item 点击事件 - final IndexTapCallback onItemTap; + final IndexTapCallback? onItemTap; // item 长按事件 - final IndexLongTapCallback onItemLongTap; + final IndexLongTapCallback? onItemLongTap; UnitBottomBar({ this.color = Colors.blue, - @required this.onItemTap, + required this.onItemTap, this.onItemLongTap, }); @@ -163,15 +163,12 @@ class _UnitBottomBarState extends State { void _updateIndex(int index) { setState(() { _position = index; - if (widget.onItemTap != null) { - widget.onItemTap(_position); - } + widget.onItemTap?.call(_position); }); } void _onLongPress(BuildContext context, int index) { - if (widget.onItemLongTap != null) { - widget.onItemLongTap(context, index); - } + widget.onItemLongTap?.call(context, index); + } } diff --git a/lib/views/components/project/overlay_tool_wrapper.dart b/lib/views/components/project/overlay_tool_wrapper.dart index 3f65171..e505f00 100644 --- a/lib/views/components/project/overlay_tool_wrapper.dart +++ b/lib/views/components/project/overlay_tool_wrapper.dart @@ -14,18 +14,17 @@ import '../permanent/color_wrapper.dart'; class OverlayToolWrapper extends StatefulWidget { final Widget child; - OverlayToolWrapper({Key key, this.child}) : super(key: key); + OverlayToolWrapper({Key? key,required this.child}) : super(key: key); @override OverlayToolWrapperState createState() => OverlayToolWrapperState(); static OverlayToolWrapperState of(BuildContext context, {bool nullOk = false}) { - assert(nullOk != null); - assert(context != null); - final OverlayToolWrapperState result = + + final OverlayToolWrapperState? result = context.findAncestorStateOfType(); - if (nullOk || result != null) return result; + if (result != null) return result; throw FlutterError.fromParts([ ErrorSummary( 'OverlayToolWrapper.of() called with a context that does not contain a OverlayToolWrapper.'), @@ -38,7 +37,7 @@ class OverlayToolWrapperState extends State bool show = false; Offset offset = Offset(200, 200); - AnimationController _ctrl; + late AnimationController _ctrl; final double width = 200; final double height = 30; @@ -46,7 +45,7 @@ class OverlayToolWrapperState extends State final double boxHeight = 110; final double radius = 60; - OverlayEntry entry; + OverlayEntry? entry; double showWidth = 0; bool out = false; @@ -60,7 +59,7 @@ class OverlayToolWrapperState extends State vsync: this, )..addListener(_listenAnimate); - WidgetsBinding.instance.addPostFrameCallback((callback) { + WidgetsBinding.instance?.addPostFrameCallback((callback) { var px = MediaQuery.of(context).size.width - 100; var py = 250.0; offset = Offset(px, py); @@ -180,7 +179,7 @@ class OverlayToolWrapperState extends State } } - double endX; + double endX=0; void _onPanEnd(details) { endX = offset.dx; @@ -210,7 +209,7 @@ class OverlayToolWrapperState extends State } offset = Offset(px, offset.dy); - entry.markNeedsBuild(); + entry?.markNeedsBuild(); } void _updatePosition(DragUpdateDetails details) { @@ -232,19 +231,19 @@ class OverlayToolWrapperState extends State y = MediaQuery.of(context).size.height - menuSize / 2 - circleRadius; } offset = Offset(x, y); - entry.markNeedsBuild(); + entry?.markNeedsBuild(); } void showFloating() { - if (!show) { - Overlay.of(context).insert(entry); + if (!show&&entry!=null) { + Overlay.of(context)?.insert(entry!); show = true; } } void hideFloating() { if (show) { - entry.remove(); + entry?.remove(); show = false; } } diff --git a/lib/views/components/project/unit_drawer_header.dart b/lib/views/components/project/unit_drawer_header.dart index 9ac1294..d197901 100644 --- a/lib/views/components/project/unit_drawer_header.dart +++ b/lib/views/components/project/unit_drawer_header.dart @@ -8,7 +8,7 @@ class UnitDrawerHeader extends StatelessWidget { final Color color; - UnitDrawerHeader({this.color}); + const UnitDrawerHeader({required this.color}); @override Widget build(BuildContext context) { diff --git a/lib/views/components/project/widget_node_panel.dart b/lib/views/components/project/widget_node_panel.dart index 6ca4964..ce99faf 100644 --- a/lib/views/components/project/widget_node_panel.dart +++ b/lib/views/components/project/widget_node_panel.dart @@ -19,16 +19,16 @@ class WidgetNodePanel extends StatefulWidget { final String text; final String subText; final String code; - final Widget show; - final HighlighterStyle codeStyle; - final String codeFamily; + final Widget? show; + final HighlighterStyle? codeStyle; + final String? codeFamily; WidgetNodePanel( - {this.text, - this.subText, - this.code, + {this.text='', + this.subText='', + this.code='', this.show, - this.codeStyle, + required this.codeStyle, this.codeFamily}); @override diff --git a/lib/views/components/project/wrapper/honour_wrapper.dart b/lib/views/components/project/wrapper/honour_wrapper.dart index 40cc072..9d0a0cc 100644 --- a/lib/views/components/project/wrapper/honour_wrapper.dart +++ b/lib/views/components/project/wrapper/honour_wrapper.dart @@ -17,7 +17,7 @@ class HonourWrapper extends StatefulWidget { class _HonourWrapperState extends State with SingleTickerProviderStateMixin { - AnimationController _ctrl; + late AnimationController _ctrl; @override void initState() { @@ -60,7 +60,7 @@ class HonourPainter extends CustomPainter { textAlign: TextAlign.center, textDirection: TextDirection.ltr); - HonourPainter({this.factor}) : super(repaint: factor); + HonourPainter({required this.factor}) : super(repaint: factor); static const List colors = [ Color(0xffFFAB40), diff --git a/lib/views/pages/about/about_app_page.dart b/lib/views/pages/about/about_app_page.dart index 6918ee5..7050f3a 100644 --- a/lib/views/pages/about/about_app_page.dart +++ b/lib/views/pages/about/about_app_page.dart @@ -192,7 +192,7 @@ class InfoPanel extends StatelessWidget { final String info; - InfoPanel({this.title, this.info}); + InfoPanel({required this.title,required this.info}); @override Widget build(BuildContext context) { diff --git a/lib/views/pages/about/version/app_version_checker.dart b/lib/views/pages/about/version/app_version_checker.dart index fb62260..beebe08 100644 --- a/lib/views/pages/about/version/app_version_checker.dart +++ b/lib/views/pages/about/version/app_version_checker.dart @@ -14,7 +14,7 @@ import 'package:path/path.dart' as path; import 'package:path_provider/path_provider.dart'; class AppVersionChecker extends StatefulWidget { - const AppVersionChecker({Key key}) : super(key: key); + const AppVersionChecker({Key? key}) : super(key: key); @override _AppVersionCheckerState createState() => _AppVersionCheckerState(); @@ -34,7 +34,9 @@ class _AppVersionCheckerState extends State { ValueNotifier progress = ValueNotifier(0); _doDownload() async { - Directory dir = await getExternalStorageDirectory(); + Directory? dir = await getExternalStorageDirectory(); + if(dir ==null) return; + String dstPath = path.join(dir.path, 'FlutterUnit.apk'); if(File(dstPath).existsSync()){ @@ -79,15 +81,15 @@ class _AppVersionCheckerState extends State { ResultBean result = await AppInfoApi.getAppVersion(); PackageInfo packageInfo = await PackageInfo.fromPlatform(); - if (result.status) { - print('${result.data.appName}:${result.data.appVersion}'); - if (packageInfo.version == result.data.appVersion) { + if (result.status&&result.data!=null) { + print('${result.data!.appName}:${result.data!.appVersion}'); + if (packageInfo.version == result.data!.appVersion) { Toast.success(context, '当前应用已是最新版本!'); versionState.value = VersionState.none; } else { oldVersion = packageInfo.version; - newVersion = result.data.appVersion; - Toast.green(context, '检测到新版本【${result.data.appVersion}】,可点击更新!'); + newVersion = result.data!.appVersion; + Toast.green(context, '检测到新版本【${result.data!.appVersion}】,可点击更新!'); versionState.value = VersionState.shouldUpdate; } } else { @@ -99,7 +101,7 @@ class _AppVersionCheckerState extends State { } Widget _buildTrailByState( - BuildContext context, VersionState value, Widget child) { + BuildContext context, VersionState value, Widget? child) { switch (value) { case VersionState.none: return const SizedBox(); @@ -129,7 +131,7 @@ class _AppVersionCheckerState extends State { return const SizedBox(); } - Widget _buildProgress(BuildContext context, double value, Widget child) { + Widget _buildProgress(BuildContext context, double value, Widget? child) { return Wrap( alignment: WrapAlignment.center, crossAxisAlignment: WrapCrossAlignment.center, diff --git a/lib/views/pages/about/version/version_shower.dart b/lib/views/pages/about/version/version_shower.dart index 2a81a6d..f29e75a 100644 --- a/lib/views/pages/about/version/version_shower.dart +++ b/lib/views/pages/about/version/version_shower.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:package_info/package_info.dart'; class VersionShower extends StatefulWidget { - const VersionShower({Key key}) : super(key: key); + const VersionShower({Key? key}) : super(key: key); @override _VersionShowerState createState() => _VersionShowerState(); diff --git a/lib/views/pages/app/bloc_wrapper.dart b/lib/views/pages/app/bloc_wrapper.dart index 0db8e8d..6d1cdfd 100644 --- a/lib/views/pages/app/bloc_wrapper.dart +++ b/lib/views/pages/app/bloc_wrapper.dart @@ -22,7 +22,7 @@ final AppStart storage = AppStart(); class BlocWrapper extends StatefulWidget { final Widget child; - BlocWrapper({this.child}); + BlocWrapper({required this.child}); @override _BlocWrapperState createState() => _BlocWrapperState(); diff --git a/lib/views/pages/app/unit_navigation.dart b/lib/views/pages/app/unit_navigation.dart index 2bbcaf8..2eaa99f 100644 --- a/lib/views/pages/app/unit_navigation.dart +++ b/lib/views/pages/app/unit_navigation.dart @@ -60,7 +60,7 @@ class _UnitNavigationState extends State { } // 构建悬浮按钮工具 - Widget wrapOverlayTool({Widget child}) => Builder( + Widget wrapOverlayTool({required Widget child}) => Builder( builder: (ctx) => OverlayToolWrapper( child: child, )); diff --git a/lib/views/pages/category/category_detail.dart b/lib/views/pages/category/category_detail.dart index 45281d1..b1f3d8b 100644 --- a/lib/views/pages/category/category_detail.dart +++ b/lib/views/pages/category/category_detail.dart @@ -17,7 +17,7 @@ import 'package:flutter_unit/model/widget_model.dart'; class CategoryShow extends StatelessWidget { final CategoryModel model; - CategoryShow({this.model}); + CategoryShow({required this.model}); @override Widget build(BuildContext context) { @@ -51,7 +51,7 @@ class CategoryShow extends StatelessWidget { ), onDismissed: (v) { BlocProvider.of(context).add( - EventToggleCategoryWidget(model.id, widgets[index].id)); + EventToggleCategoryWidget(model.id!, widgets[index].id)); }, child: Container( margin: EdgeInsets.symmetric(horizontal: 15, vertical: 8), @@ -77,7 +77,7 @@ class CategoryShow extends StatelessWidget { class SimpleWidgetItem extends StatelessWidget { final WidgetModel data; - SimpleWidgetItem({this.data}); + SimpleWidgetItem({required this.data}); @override Widget build(BuildContext context) { @@ -134,7 +134,7 @@ class SimpleWidgetItem extends StatelessWidget { ), ) : CircleImage( - image: data.image, + image: data.image!, size: 60, ), ); diff --git a/lib/views/pages/category/category_page.dart b/lib/views/pages/category/category_page.dart index 3f6596e..7113660 100644 --- a/lib/views/pages/category/category_page.dart +++ b/lib/views/pages/category/category_page.dart @@ -79,7 +79,7 @@ class CategoryPage extends StatelessWidget { content: ' 删除【${model.name}】收藏集,你将会失去其中的所有收藏组件,是否确定继续执行?', onSubmit: () { BlocProvider.of(context) - .add(EventDeleteCategory(id: model.id)); + .add(EventDeleteCategory(id: model.id!)); Navigator.of(context).pop(); }, ), @@ -127,7 +127,7 @@ class CategoryPage extends StatelessWidget { } _toDetailPage(BuildContext context, CategoryModel model) { - BlocProvider.of(context).add(EventLoadCategoryWidget(model.id)); + BlocProvider.of(context).add(EventLoadCategoryWidget(model.id!)); Navigator.pushNamed(context, UnitRouter.category_show, arguments: model); } diff --git a/lib/views/pages/category/collect_page.dart b/lib/views/pages/category/collect_page.dart index 5414c3d..124495b 100644 --- a/lib/views/pages/category/collect_page.dart +++ b/lib/views/pages/category/collect_page.dart @@ -21,7 +21,7 @@ class CollectPage extends StatefulWidget { class _CollectPageState extends State with AutomaticKeepAliveClientMixin { - final _tabs = [ + final List _tabs = [ '收藏集录', '珍藏组件', ]; @@ -36,7 +36,7 @@ class _CollectPageState extends State color: BlocProvider.of(context).state.color.withAlpha(11), child: DefaultTabController( - length: _tabs.length, // This is the number of tabs. + length: _tabs.length, child: NestedScrollView( headerSliverBuilder: (context, innerBoxIsScrolled) => [ SliverOverlapAbsorber( diff --git a/lib/views/pages/category/edit_category_panel.dart b/lib/views/pages/category/edit_category_panel.dart index b5d6596..0644b09 100644 --- a/lib/views/pages/category/edit_category_panel.dart +++ b/lib/views/pages/category/edit_category_panel.dart @@ -15,34 +15,32 @@ import 'package:flutter_unit/model/category_model.dart'; enum EditType { add, update } class EditCategoryPanel extends StatefulWidget { - final CategoryModel model; + final CategoryModel? model; final EditType type; - EditCategoryPanel({this.model, this.type = EditType.add}); + const EditCategoryPanel({this.model, this.type = EditType.add}); @override _EditCategoryPanelState createState() => _EditCategoryPanelState(); } class _EditCategoryPanelState extends State { - String name; - String color; - String info; + String name=''; + String color=''; + String info=''; int get colorIndex => widget.model == null ? 0 : UnitColor.collectColorSupport .map((e) => e.value) .toList() - .indexOf(widget.model.color.value); + .indexOf(widget.model!.color.value); @override void initState() { super.initState(); - info = widget.model?.info; - color = widget.model == null - ? null - : ColorUtils.colorString(widget.model.color); + info = widget.model?.info??''; + color = (widget.model == null ? null : ColorUtils.colorString(widget.model!.color))??''; } @override @@ -53,7 +51,7 @@ class _EditCategoryPanelState extends State { Padding( padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 8), child: InputButton( - defaultText: widget.model?.name, + defaultText: '${widget.model?.name}', config: InputButtonConfig(hint: '收藏集名称', iconData: Icons.check), onSubmit: (str) { name = str; @@ -65,7 +63,7 @@ class _EditCategoryPanelState extends State { if (widget.type == EditType.update) { BlocProvider.of(context).add( EventUpdateCategory( - id: widget.model.id, + id: widget.model!.id!, name: name, info: info, color: color)); @@ -78,7 +76,7 @@ class _EditCategoryPanelState extends State { Padding( padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 8), child: EditPanel( - defaultText: widget.model?.info, + defaultText: '${widget.model?.info}', submitClear: false, hint: '收藏集简介...', onChange: (v) => info = v, diff --git a/lib/views/pages/category/home_right_drawer.dart b/lib/views/pages/category/home_right_drawer.dart index bc5f5a9..f3d6cb7 100644 --- a/lib/views/pages/category/home_right_drawer.dart +++ b/lib/views/pages/category/home_right_drawer.dart @@ -13,9 +13,9 @@ class HomeRightDrawer extends StatefulWidget { } class _HomeRightDrawerState extends State { - String name; - String color; - String info; + String name=''; + String color=''; + String info=''; @override Widget build(BuildContext context) { @@ -33,7 +33,9 @@ class _HomeRightDrawerState extends State { child: ListView(padding: EdgeInsets.zero, children: [ UnitDrawerHeader(color:color), _buildTitle(context), - EditCategoryPanel() + const EditCategoryPanel( + + ) ]), ); } diff --git a/lib/views/pages/category/sync/async_button.dart b/lib/views/pages/category/sync/async_button.dart index da21f96..477aff1 100644 --- a/lib/views/pages/category/sync/async_button.dart +++ b/lib/views/pages/category/sync/async_button.dart @@ -77,7 +77,7 @@ class _SyncCategoryButtonState extends State { if (result.data != null) { //说明有后台备份数据,进行同步操作 CategoryRepository repository = BlocProvider.of(context).repository; - await repository.syncCategoryByData(result.data.data,result.data.likeData); + await repository.syncCategoryByData(result.data!.data,result.data!.likeData); BlocProvider.of(context).add(EventLoadCategory()); BlocProvider.of(context).add(EventLoadLikeData()); } else { diff --git a/lib/views/pages/data_manage/data_manage_page.dart b/lib/views/pages/data_manage/data_manage_page.dart index 6c063ec..566a1fd 100644 --- a/lib/views/pages/data_manage/data_manage_page.dart +++ b/lib/views/pages/data_manage/data_manage_page.dart @@ -109,7 +109,7 @@ class DataManagePage extends StatelessWidget { CategoryRepository repository = BlocProvider.of(context).repository; await repository.syncCategoryByData( - result.data.data, result.data.likeData); + result.data!.data, result.data!.likeData); BlocProvider.of(context).add(EventLoadCategory()); BlocProvider.of(context).add(EventLoadLikeData()); } else { diff --git a/lib/views/pages/gallery/gallery_page.dart b/lib/views/pages/gallery/gallery_page.dart index be39d5b..afeb7d2 100644 --- a/lib/views/pages/gallery/gallery_page.dart +++ b/lib/views/pages/gallery/gallery_page.dart @@ -130,12 +130,12 @@ class FrameShower extends StatelessWidget { final Widget content; FrameShower( - {Key key, + {Key? key, this.title = "", this.author = "", this.srcUrl = "", this.info = "", - @required this.content}) + required this.content}) : super(key: key); @override diff --git a/lib/views/pages/issues_point/issue_item.dart b/lib/views/pages/issues_point/issue_item.dart index dd00487..0f3484d 100644 --- a/lib/views/pages/issues_point/issue_item.dart +++ b/lib/views/pages/issues_point/issue_item.dart @@ -14,7 +14,7 @@ import 'package:flutter_unit/model/github/issue.dart'; class IssueItem extends StatelessWidget { final Issue issue; - IssueItem({this.issue}); + IssueItem({required this.issue}); @override Widget build(BuildContext context) { @@ -32,7 +32,7 @@ class IssueItem extends StatelessWidget { Padding( padding: const EdgeInsets.only(top: 5.0, bottom: 5.0, left: 10), child: Text( - issue.title, + '${issue.title}', style: TextStyle(fontSize: 15, color: Colors.grey, shadows: [ Shadow(color: Colors.white, offset: Offset(1, .5)) ]), @@ -65,7 +65,7 @@ class IssueItem extends StatelessWidget { return Row( children: [ CircleImage( - image: NetworkImage(issue.user.avatarUrl), + image: NetworkImage(issue.user?.avatarUrl??''), size: 40, borderSize: 2, ), @@ -81,11 +81,11 @@ class IssueItem extends StatelessWidget { width: 10, ), Text( - issue.user.login, + '${issue.user?.login}', style: TextStyle(fontWeight: FontWeight.bold), ), Spacer(), - Text(ConvertMan.time2string(issue.createdAt)), + Text(ConvertMan.time2string(issue.createdAt!)), ], ); } diff --git a/lib/views/pages/issues_point/issues_detail.dart b/lib/views/pages/issues_point/issues_detail.dart index b197cd2..53f7862 100644 --- a/lib/views/pages/issues_point/issues_detail.dart +++ b/lib/views/pages/issues_point/issues_detail.dart @@ -47,11 +47,11 @@ class IssuesDetailPage extends StatelessWidget { class IssueTitle extends StatelessWidget { final Issue issue; - IssueTitle({Key key, this.issue}) : super(key: key); + IssueTitle({Key? key,required this.issue}) : super(key: key); String get issueDesHtml => issue.bodyHtml != null - ? issue.bodyHtml - : (issue.body != null) ? issue.body : ""; + ? issue.bodyHtml! + : (issue.body != null) ? issue.body! : ""; @override Widget build(BuildContext context) { @@ -80,15 +80,15 @@ class IssueTitle extends StatelessWidget { color: Colors.blue.withAlpha(22), child: ListTile( dense: true, - leading: CircleImage(size:40,borderSize:1,image: NetworkImage(issue.user.avatarUrl),), - title: Text(issue.user.login), + leading: CircleImage(size:40,borderSize:1,image: NetworkImage(issue.user!.avatarUrl!),), + title: Text(issue.user!.login!), subtitle:Row( children: [ - Text('创建于:${ConvertMan.time2string(issue.createdAt)}'), + Text('创建于:${ConvertMan.time2string(issue.createdAt!)}'), Spacer(), WrapColor( color: Colors.green, - child: Text('更新于:${ConvertMan.time2string(issue.updatedAt)}',style: TextStyle(color: Colors.white),)), + child: Text('更新于:${ConvertMan.time2string(issue.updatedAt!)}',style: TextStyle(color: Colors.white),)), ], ) , @@ -111,11 +111,11 @@ class IssueTitle extends StatelessWidget { class IssueCommentWidget extends StatelessWidget { final IssueComment comment; - IssueCommentWidget({Key key, this.comment}) : super(key: key); + IssueCommentWidget({Key? key,required this.comment}) : super(key: key); String get issueDesHtml => comment.bodyHtml != null - ? comment.bodyHtml - : (comment.body != null) ? comment.body : ""; + ? comment.bodyHtml! + : (comment.body != null) ? comment.body! : ""; @override Widget build(BuildContext context) { @@ -127,15 +127,15 @@ class IssueCommentWidget extends StatelessWidget { color: Colors.blue.withAlpha(22), child: ListTile( dense: true, - leading: CircleImage(size:40,borderSize:1,image: NetworkImage(comment.user.avatarUrl),), - title: Text(comment.user.login), + leading: CircleImage(size:40,borderSize:1,image: NetworkImage(comment.user!.avatarUrl!),), + title: Text(comment.user!.login!), subtitle:Row( children: [ - Text('创建于:${ConvertMan.time2string(comment.createdAt)}'), + Text('创建于:${ConvertMan.time2string(comment.createdAt!)}'), Spacer(), WrapColor( color: Colors.green, - child: Text('更新于:${ConvertMan.time2string(comment.updatedAt)}',style: TextStyle(color: Colors.white),)), + child: Text('更新于:${ConvertMan.time2string(comment.updatedAt!)}',style: TextStyle(color: Colors.white),)), ], ) , diff --git a/lib/views/pages/issues_point/issues_point_page.dart b/lib/views/pages/issues_point/issues_point_page.dart index 5135fe8..d07f450 100644 --- a/lib/views/pages/issues_point/issues_point_page.dart +++ b/lib/views/pages/issues_point/issues_point_page.dart @@ -29,7 +29,7 @@ class IssuesPointContent extends StatefulWidget { } class _IssuesPointContentState extends State { - Repository _repository; + Repository? _repository; @override void initState() { @@ -122,7 +122,7 @@ class _IssuesPointContentState extends State { ), ) : RepoWidget( - repository: _repository, + repository: _repository!, ), ), ); @@ -134,7 +134,7 @@ class _IssuesPointContentState extends State { } void _loadRepo() async { - final Repository result = await IssuesApi.getRepoFlutterUnit(); + final Repository? result = await IssuesApi.getRepoFlutterUnit(); setState(() { if (result != null) { _repository = result; diff --git a/lib/views/pages/issues_point/repo_widget.dart b/lib/views/pages/issues_point/repo_widget.dart index 01865d5..92c422b 100644 --- a/lib/views/pages/issues_point/repo_widget.dart +++ b/lib/views/pages/issues_point/repo_widget.dart @@ -12,7 +12,7 @@ import 'package:flutter_unit/model/github/repository.dart'; class RepoWidget extends StatelessWidget { final Repository repository; - RepoWidget({this.repository}); + RepoWidget({required this.repository}); @override Widget build(BuildContext context) { @@ -36,13 +36,13 @@ class RepoWidget extends StatelessWidget { Row( children: [ Text( - repository.fullName, + repository.fullName!, style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16), ), SizedBox(width: 10,), WrapColor( child: Text( - repository.license.spdxId, + '${repository.license?.type}', style: TextStyle( fontWeight: FontWeight.bold, color: Colors.white, @@ -52,7 +52,7 @@ class RepoWidget extends StatelessWidget { Spacer(), Text( "创建:" + - ConvertMan.time2string(repository.createdAt, just: true), + ConvertMan.time2string(repository.createdAt!, just: true), style: TextStyle(color: Colors.grey), ), ], @@ -60,7 +60,7 @@ class RepoWidget extends StatelessWidget { Padding( padding: const EdgeInsets.symmetric(vertical: 8.0), child: Text( - repository.description, + repository.description!, style: TextStyle(color: Colors.grey), ), ), diff --git a/lib/views/pages/setting/code_style_setting.dart b/lib/views/pages/setting/code_style_setting.dart index 64823fa..addc905 100644 --- a/lib/views/pages/setting/code_style_setting.dart +++ b/lib/views/pages/setting/code_style_setting.dart @@ -65,7 +65,7 @@ class Hello { bottom: 20, child: Text(Cons.codeThemeSupport.values.toList()[i],style: TextStyle( fontSize: 14, - color: styles[i].stringStyle.color, + color: styles[i].stringStyle!.color, shadows: [Shadow( color: Colors.white, offset: Offset(.5,.5), diff --git a/lib/views/pages/setting/theme_color_setting.dart b/lib/views/pages/setting/theme_color_setting.dart index d89fefd..af39661 100644 --- a/lib/views/pages/setting/theme_color_setting.dart +++ b/lib/views/pages/setting/theme_color_setting.dart @@ -33,15 +33,15 @@ class ThemeColorSettingPage extends StatelessWidget { crossAxisSpacing: 10, childAspectRatio: 1.5, children: themeColorSupport - .map((e) => FeedbackWidget( + .map((MaterialColor c) => FeedbackWidget( a: 0.95, duration: Duration(milliseconds: 200), - onPressed: () => BlocProvider.of(context).add(EventSwitchThemeColor(e)), + onPressed: () => BlocProvider.of(context).add(EventSwitchThemeColor(c)), child: GridTile( header: Container( decoration: BoxDecoration( borderRadius: BorderRadius.only(topLeft: Radius.circular(10),topRight: Radius.circular(10)), - color: color == e + color: color == c ? Colors.blue.withAlpha(88): Colors.grey.withAlpha(55), ), @@ -51,12 +51,12 @@ class ThemeColorSettingPage extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.center, children: [ Spacer(), - Text(colorString(e), + Text(colorString(c), style: TextStyle( color: Colors.white, )), Spacer(), - if (color == e) Padding( + if (color == c) Padding( padding: const EdgeInsets.only(right:8.0), child: Circle(color: Colors.white,radius: 7,), ) @@ -67,20 +67,20 @@ class ThemeColorSettingPage extends StatelessWidget { decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(10)), gradient: LinearGradient(colors: [ - e[50], - e[100], - e[200], - e[300], - e[400], - e[500], - e[600], - e[700], - e[800], - e[900], + c.shade50, + c.shade100, + c.shade200, + c.shade300, + c.shade400, + c.shade500, + c.shade600, + c.shade700, + c.shade800, + c.shade900, ])), alignment: Alignment(0,0.35), child: Text( - Cons.themeColorSupport [e], + '${Cons.themeColorSupport[c]}', style: TextStyle(fontSize: 18,color: Colors.white,fontWeight: FontWeight.bold), )), ))) diff --git a/lib/views/pages/splash/flutter_unit_text.dart b/lib/views/pages/splash/flutter_unit_text.dart index 0095d98..a6ae37d 100644 --- a/lib/views/pages/splash/flutter_unit_text.dart +++ b/lib/views/pages/splash/flutter_unit_text.dart @@ -7,8 +7,11 @@ class FlutterUnitText extends StatefulWidget { final String text; final Color color; - FlutterUnitText({this.text = "Toly", this.color = Colors.blue, Key key}) - : super(key: key); + FlutterUnitText({ + this.text = "Toly", + this.color = Colors.blue, + Key? key, + }) : super(key: key); @override _FlutterUnitTextState createState() => _FlutterUnitTextState(); @@ -17,12 +20,12 @@ class FlutterUnitText extends StatefulWidget { class _FlutterUnitTextState extends State with SingleTickerProviderStateMixin { - AnimationController _ctrl; + late AnimationController _ctrl; final TextPainter _textPainter = TextPainter(textDirection: TextDirection.ltr); - Animation animation; + late Animation animation; @override void initState() { @@ -57,7 +60,10 @@ class _FlutterUnitTextState extends State return CustomPaint( size: _textPainter.size, painter: SpringPainter( - textPainter: _textPainter, color: widget.color, skew: animation)); + textPainter: _textPainter, + color: widget.color, + skew: animation, + )); } } @@ -73,16 +79,15 @@ class Interpolator extends Curve { class SpringPainter extends CustomPainter { final ValueListenable skew; - - String _text = ''; - Color color = Colors.blue; - - SpringPainter({this.skew, this.textPainter, this.color}) - : super(repaint: skew) { - _text = textPainter.text.toPlainText(); - } - final TextPainter textPainter; + String _text = ''; + Color color; + + SpringPainter( + {required this.skew, required this.textPainter, this.color = Colors.blue}) + : super(repaint: skew) { + _text = textPainter.text?.toPlainText() ?? ''; + } @override void paint(Canvas canvas, Size size) { diff --git a/lib/views/pages/splash/unit_paint.dart b/lib/views/pages/splash/unit_paint.dart index 103e57d..6bf790a 100644 --- a/lib/views/pages/splash/unit_paint.dart +++ b/lib/views/pages/splash/unit_paint.dart @@ -5,9 +5,9 @@ import 'package:flutter/material.dart'; /// 说明: app 闪屏页画板 class UnitPainter extends CustomPainter { - Paint _paint; + late Paint _paint; final double width; - Animation _curveAnim; + late Animation _curveAnim; final Color color; final Path _path1 = Path(); @@ -15,9 +15,13 @@ class UnitPainter extends CustomPainter { final Path _path3 = Path(); final Path _path4 = Path(); - UnitPainter({this.width = 200.0, this.color = Colors.blue,Animation repaint}):super(repaint: repaint) { + UnitPainter( + {this.width = 200.0, + this.color = Colors.blue, + required Animation repaint}) + : super(repaint: repaint) { _paint = Paint(); - _curveAnim= CurvedAnimation(parent: repaint, curve: Curves.fastOutSlowIn); + _curveAnim = CurvedAnimation(parent: repaint, curve: Curves.fastOutSlowIn); } @override diff --git a/lib/views/pages/splash/unit_splash.dart b/lib/views/pages/splash/unit_splash.dart index 50d6cbc..42d35ac 100644 --- a/lib/views/pages/splash/unit_splash.dart +++ b/lib/views/pages/splash/unit_splash.dart @@ -21,7 +21,7 @@ class UnitSplash extends StatefulWidget { } class _UnitSplashState extends State with TickerProviderStateMixin { - AnimationController _controller; + late AnimationController _controller; ValueNotifier _animEnd = ValueNotifier(false); @@ -94,7 +94,7 @@ class _UnitSplashState extends State with TickerProviderStateMixin { top: winH / 1.4, child: ValueListenableBuilder( valueListenable: _animEnd, - builder: (_, value, __) => value + builder: (_,bool value, __) => value ? FlutterUnitText( text: StrUnit.appName, color: Theme.of(context).primaryColor, diff --git a/lib/views/pages/user/page_item.dart b/lib/views/pages/user/page_item.dart index 57d5749..fde1f51 100644 --- a/lib/views/pages/user/page_item.dart +++ b/lib/views/pages/user/page_item.dart @@ -45,7 +45,7 @@ class MePageItem extends StatelessWidget { Widget _buildItem( BuildContext context, IconData icon, String title, String linkTo, - {VoidCallback onTap}) => + {VoidCallback? onTap}) => ListTile( leading: Icon( icon, @@ -55,7 +55,7 @@ class MePageItem extends StatelessWidget { trailing: Icon(Icons.chevron_right, color: Theme.of(context).primaryColor), onTap: () { - if (linkTo != null && linkTo.isNotEmpty) { + if (linkTo.isNotEmpty) { Navigator.of(context).pushNamed(linkTo); if (onTap != null) onTap(); } diff --git a/lib/views/pages/user/unit_drawer_header.dart b/lib/views/pages/user/unit_drawer_header.dart index b945383..d4733b0 100644 --- a/lib/views/pages/user/unit_drawer_header.dart +++ b/lib/views/pages/user/unit_drawer_header.dart @@ -8,7 +8,7 @@ class UnitDrawerHeader extends StatelessWidget { final Color color; - UnitDrawerHeader({this.color}); + UnitDrawerHeader({required this.color}); @override Widget build(BuildContext context) { diff --git a/lib/views/pages/widget_detail/category_end_drawer.dart b/lib/views/pages/widget_detail/category_end_drawer.dart index 3fa0d9c..547b835 100644 --- a/lib/views/pages/widget_detail/category_end_drawer.dart +++ b/lib/views/pages/widget_detail/category_end_drawer.dart @@ -16,7 +16,7 @@ import 'package:flutter_unit/views/components/project/unit_drawer_header.dart'; class CategoryEndDrawer extends StatelessWidget { final WidgetModel widget; - CategoryEndDrawer({this.widget}); + CategoryEndDrawer({required this.widget}); @override Widget build(BuildContext context) { @@ -128,10 +128,10 @@ class _CategoryInfoState extends State { selected: inHere, label: Text(category.name), onSelected: (v) async { - await repository.toggleCategory(category.id, widget.id); + await repository.toggleCategory(category.id!, widget.id); _loadCategoryIds(); BlocProvider.of(context) - .add(EventLoadCategoryWidget(category.id)); + .add(EventLoadCategoryWidget(category.id!)); }); } diff --git a/lib/views/pages/widget_detail/widget_detail_page.dart b/lib/views/pages/widget_detail/widget_detail_page.dart index f84712c..4496333 100644 --- a/lib/views/pages/widget_detail/widget_detail_page.dart +++ b/lib/views/pages/widget_detail/widget_detail_page.dart @@ -16,7 +16,7 @@ import 'package:flutter_unit/views/widgets/widgets_map.dart'; class WidgetDetailPage extends StatefulWidget { final WidgetModel model; - WidgetDetailPage({this.model}); + WidgetDetailPage({required this.model}); @override _WidgetDetailPageState createState() => _WidgetDetailPageState(); @@ -218,7 +218,7 @@ class _WidgetDetailPageState extends State { class WidgetDetailTitle extends StatelessWidget { final WidgetModel model; - WidgetDetailTitle({this.model}); + WidgetDetailTitle({required this.model}); @override Widget build(BuildContext context) { @@ -274,7 +274,7 @@ class WidgetDetailTitle extends StatelessWidget { borderRadius: BorderRadius.all(Radius.circular(8)), child: model.image == null ? Image.asset('assets/images/caver.webp') - : Image(image: model.image))), + : Image(image: model.image!))), ), ), StarScore( diff --git a/lib/views/pages/widget_home/home_drawer.dart b/lib/views/pages/widget_home/home_drawer.dart index 34b53ad..76ef53e 100644 --- a/lib/views/pages/widget_home/home_drawer.dart +++ b/lib/views/pages/widget_home/home_drawer.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:flutter_unit/app/router/unit_router.dart'; import 'package:flutter_unit/app/res/toly_icon.dart'; +import 'package:flutter_unit/app/router/unit_router.dart'; import 'package:flutter_unit/blocs/bloc_exp.dart'; import 'package:flutter_unit/blocs/point/point_bloc.dart'; import 'package:flutter_unit/blocs/point/point_event.dart'; @@ -31,16 +31,17 @@ class HomeDrawer extends StatelessWidget { child: ListView( padding: EdgeInsets.zero, children: [ - UnitDrawerHeader(color: color), - _buildItem(context, TolyIcon.icon_them, '应用设置', UnitRouter.setting), - _buildItem(context, TolyIcon.icon_layout, '数据管理', UnitRouter.data_manage), - Divider(height: 1), - _buildFlutterUnit(context), - _buildItem(context, TolyIcon.icon_code, 'Dart 手册', null), - Divider(height: 1), - _buildItem(context, Icons.info, '关于应用', UnitRouter.about_app), - _buildItem(context, TolyIcon.icon_kafei, '联系本王', UnitRouter.about_me), - ], + UnitDrawerHeader(color: color), + _buildItem(context, TolyIcon.icon_them, '应用设置', UnitRouter.setting), + _buildItem( + context, TolyIcon.icon_layout, '数据管理', UnitRouter.data_manage), + Divider(height: 1), + _buildFlutterUnit(context), + _buildItem(context, TolyIcon.icon_code, 'Dart 手册', ''), + Divider(height: 1), + _buildItem(context, Icons.info, '关于应用', UnitRouter.about_app), + _buildItem(context, TolyIcon.icon_kafei, '联系本王', UnitRouter.about_me), + ], ), ); } @@ -63,7 +64,8 @@ class HomeDrawer extends StatelessWidget { ); Widget _buildItem( - BuildContext context, IconData icon, String title, String linkTo,{VoidCallback onTap}) => + BuildContext context, IconData icon, String title, String linkTo, + {VoidCallback? onTap}) => ListTile( leading: Icon( icon, @@ -73,9 +75,9 @@ class HomeDrawer extends StatelessWidget { trailing: Icon(Icons.chevron_right, color: Theme.of(context).primaryColor), onTap: () { - if (linkTo != null && linkTo.isNotEmpty) { + if (linkTo.isNotEmpty) { Navigator.of(context).pushNamed(linkTo); - if(onTap!=null) onTap(); + if (onTap != null) onTap(); } }, ); diff --git a/lib/views/pages/widget_home/home_page.dart b/lib/views/pages/widget_home/home_page.dart index 13b7e6a..4f86205 100644 --- a/lib/views/pages/widget_home/home_page.dart +++ b/lib/views/pages/widget_home/home_page.dart @@ -28,7 +28,7 @@ class _HomePageState extends State @override void initState() { super.initState(); - WidgetsBinding.instance.addPostFrameCallback(_onFrameCallBack); + WidgetsBinding.instance?.addPostFrameCallback(_onFrameCallBack); } void _onFrameCallBack(Duration timeStamp) { @@ -139,9 +139,9 @@ class _HomePageState extends State class FlexHeaderDelegate extends SliverPersistentHeaderDelegate { FlexHeaderDelegate({ - @required this.minHeight, - @required this.maxHeight, - @required this.childBuilder, + required this.minHeight, + required this.maxHeight, + required this.childBuilder, }); final double minHeight; //最小高度 diff --git a/lib/views/pages/widget_home/toly_app_bar.dart b/lib/views/pages/widget_home/toly_app_bar.dart index 0c5f8ed..9e7300a 100644 --- a/lib/views/pages/widget_home/toly_app_bar.dart +++ b/lib/views/pages/widget_home/toly_app_bar.dart @@ -4,14 +4,14 @@ import 'package:flutter_unit/views/components/permanent/circle.dart'; class TolyAppBar extends StatefulWidget { final double maxHeight; - final Function(int) onItemClick; + final Function(int)? onItemClick; @override _TolyAppBarState createState() => _TolyAppBarState(); final int defaultIndex; - TolyAppBar({this.maxHeight, this.onItemClick, this.defaultIndex = 0}); + TolyAppBar({required this.maxHeight, this.onItemClick, this.defaultIndex = 0}); } const BorderRadius _kBorderRadius = BorderRadius.only( @@ -25,7 +25,7 @@ const TextStyle _kTabTextStyle = TextStyle(color: Colors.white, shadows: [ class _TolyAppBarState extends State with SingleTickerProviderStateMixin { - double _width; + double? _width; int _selectIndex = 0; int _prevSelectIndex = 0; @@ -49,10 +49,10 @@ class _TolyAppBarState extends State 'Other' ]; - AnimationController _controller; - Animation circleAnim; - Animation heightAnim; - Animation backCircleAnim; + late AnimationController _controller; + late Animation circleAnim; + late Animation heightAnim; + late Animation backCircleAnim; @override void initState() { @@ -133,7 +133,7 @@ class _TolyAppBarState extends State _controller.forward(); _prevSelectIndex = _selectIndex; _selectIndex = colors.indexOf(color); - if (widget.onItemClick != null) widget.onItemClick(_selectIndex); + widget.onItemClick?.call(_selectIndex); }); } @@ -151,7 +151,7 @@ class TolyAppBarDelegate extends FlowDelegate { final Animation repaint; TolyAppBarDelegate(this.selectIndex, this.prevSelectIndex, this.height, - {this.repaint}) + {required this.repaint}) : super(repaint: repaint); double get factor => repaint.value; @@ -162,7 +162,7 @@ class TolyAppBarDelegate extends FlowDelegate { double obx = 0; for (int i = 0; i < context.childCount / 2; i++) { - Size cSize = context.getChildSize(i); + Size cSize = context.getChildSize(i)??Size.zero; if (i == selectIndex) { context.paintChild(i, transform: Matrix4.translationValues(ox, 20.0 * factor - 20, 0.0)); @@ -181,10 +181,11 @@ class TolyAppBarDelegate extends FlowDelegate { // 绘制小点 for (int i = (context.childCount / 2).floor(); i < context.childCount; i++) { + Size size = context.getChildSize(0)??Size.zero; context.paintChild(i, transform: Matrix4.translationValues( - obx + context.getChildSize(0).width / 2 - 5, height + 5, 0)); - obx += context.getChildSize(0).width; + obx + size.width / 2 - 5, height + 5, 0)); + obx += size.width; } } diff --git a/lib/views/widgets/MultiChildRenderObjectWidget/Flex/zz_node_play.dart b/lib/views/widgets/MultiChildRenderObjectWidget/Flex/zz_node_play.dart index 3f6e49a..d056da0 100644 --- a/lib/views/widgets/MultiChildRenderObjectWidget/Flex/zz_node_play.dart +++ b/lib/views/widgets/MultiChildRenderObjectWidget/Flex/zz_node_play.dart @@ -83,7 +83,7 @@ class _PlayFlexState extends State { .toList(), onChanged: (e) { setState(() { - _direction = e; + _direction = e??_direction; }); }), ], @@ -114,7 +114,7 @@ class _PlayFlexState extends State { .toList(), onChanged: (e) { setState(() { - _mainAxisAlignment = e; + _mainAxisAlignment = e??_mainAxisAlignment; }); }), ], @@ -145,7 +145,7 @@ class _PlayFlexState extends State { .toList(), onChanged: (e) { setState(() { - _crossAxisAlignment = e; + _crossAxisAlignment = e??_crossAxisAlignment; }); }), ], @@ -176,7 +176,7 @@ class _PlayFlexState extends State { .toList(), onChanged: (e) { setState(() { - _verticalDirection = e; + _verticalDirection = e??_verticalDirection; }); }), ], diff --git a/lib/views/widgets/MultiChildRenderObjectWidget/Flow/node1_base.dart b/lib/views/widgets/MultiChildRenderObjectWidget/Flow/node1_base.dart index 3b41103..29b47bf 100644 --- a/lib/views/widgets/MultiChildRenderObjectWidget/Flow/node1_base.dart +++ b/lib/views/widgets/MultiChildRenderObjectWidget/Flow/node1_base.dart @@ -1,6 +1,7 @@ import 'dart:math'; import 'package:flutter/material.dart'; + /// create by 张风捷特烈 on 2020-03-30 /// contact me by email 1981462002@qq.com /// 说明: @@ -13,7 +14,7 @@ import 'package:flutter/material.dart'; // "【delegate】 : 代理 【FlowDelegate】", // } class CircleFlow extends StatelessWidget { - final data = List.generate( + final List data = List.generate( 16, (index) => index.isEven ? "assets/images/icon_head.webp" @@ -38,19 +39,18 @@ class CircleFlow extends StatelessWidget { class _CircleFlowDelegate extends FlowDelegate { @override //绘制孩子的方法 void paintChildren(FlowPaintingContext context) { - double radius = context.size.shortestSide / 2; - print(context.getChildSize(0)); - var count = context.childCount; - var perRad = 2 * pi / count; + final double radius = context.size.shortestSide / 2; + final int count = context.childCount; + final double perRad = 2 * pi / count; for (int i = 0; i < count; i++) { - var cSizeX = context.getChildSize(i).width / 2; - var cSizeY = context.getChildSize(i).height / 2; - - var offsetX = (radius - cSizeX) * cos(i * perRad) + radius; - var offsetY = (radius - cSizeY) * sin(i * perRad) + radius; + final Size size = context.getChildSize(i) ?? Size.zero; + final double offsetX = + (radius - size.width / 2) * cos(i * perRad) + radius; + final double offsetY = + (radius - size.height / 2) * sin(i * perRad) + radius; context.paintChild(i, transform: Matrix4.translationValues( - offsetX - cSizeX, offsetY - cSizeY, 0.0)); + offsetX - size.width / 2, offsetY - size.height / 2, 0.0)); } } diff --git a/lib/views/widgets/MultiChildRenderObjectWidget/Flow/node2_anim.dart b/lib/views/widgets/MultiChildRenderObjectWidget/Flow/node2_anim.dart index 46bd526..df7e164 100644 --- a/lib/views/widgets/MultiChildRenderObjectWidget/Flow/node2_anim.dart +++ b/lib/views/widgets/MultiChildRenderObjectWidget/Flow/node2_anim.dart @@ -1,3 +1,4 @@ +import 'dart:developer'; import 'dart:math'; import 'package:flutter/material.dart'; @@ -33,7 +34,7 @@ class BurstFlow extends StatefulWidget { final List children; final Widget menu; - BurstFlow({@required this.children, @required this.menu}); + BurstFlow({required this.children, required this.menu}); @override _BurstFlowState createState() => _BurstFlowState(); @@ -41,7 +42,7 @@ class BurstFlow extends StatefulWidget { class _BurstFlowState extends State with SingleTickerProviderStateMixin { - AnimationController _controller; + late AnimationController _controller; double _rad = 0.0; bool _closed = true; @@ -90,27 +91,26 @@ class _BurstFlowDelegate extends FlowDelegate { @override //绘制孩子的方法 void paintChildren(FlowPaintingContext context) { double radius = context.size.shortestSide / 2; - var count = context.childCount - 1; - var perRad = 2 * pi / count; + final int count = context.childCount - 1; + final double perRad = 2 * pi / count; for (int i = 0; i < count; i++) { - print(i); - var cSizeX = context.getChildSize(i).width / 2; - var cSizeY = context.getChildSize(i).height / 2; - var offsetX = rad * (radius - cSizeX) * cos(i * perRad) + radius; - var offsetY = rad * (radius - cSizeY) * sin(i * perRad) + radius; + Size size = context.getChildSize(i) ?? Size.zero; + final double offsetX = rad * (radius - size.width/2) * cos(i * perRad) + radius; + final double offsetY = rad * (radius - size.height/2) * sin(i * perRad) + radius; context.paintChild(i, transform: Matrix4.translationValues( - offsetX - cSizeX, offsetY - cSizeY, 0.0)); + offsetX - size.width/2, offsetY - size.height/2, 0.0)); } + + Size size = context.getChildSize(context.childCount - 1) ?? Size.zero; + context.paintChild(context.childCount - 1, transform: Matrix4.translationValues( - radius - context.getChildSize(context.childCount - 1).width / 2, - radius - context.getChildSize(context.childCount - 1).height / 2, - 0.0)); + radius - size.width / 2, radius - size.height / 2, 0.0)); } @override - bool shouldRepaint(FlowDelegate oldDelegate) { - return true; + bool shouldRepaint(_BurstFlowDelegate oldDelegate) { + return oldDelegate.rad != rad; } } diff --git a/lib/views/widgets/MultiChildRenderObjectWidget/Viewport/node1_base.dart b/lib/views/widgets/MultiChildRenderObjectWidget/Viewport/node1_base.dart index 3da7d8d..b778f13 100644 --- a/lib/views/widgets/MultiChildRenderObjectWidget/Viewport/node1_base.dart +++ b/lib/views/widgets/MultiChildRenderObjectWidget/Viewport/node1_base.dart @@ -55,7 +55,7 @@ class ViewportDemo extends StatelessWidget { class ColorItem extends StatefulWidget { final Color color; - ColorItem({Key key,this.color}) : super(key: key); + ColorItem({Key? key,required this.color}) : super(key: key); @override _ColorItemState createState() => _ColorItemState(); } diff --git a/lib/views/widgets/Other/ListWheelViewport/node1_base.dart b/lib/views/widgets/Other/ListWheelViewport/node1_base.dart index a5a7390..e4ea3f6 100644 --- a/lib/views/widgets/Other/ListWheelViewport/node1_base.dart +++ b/lib/views/widgets/Other/ListWheelViewport/node1_base.dart @@ -18,12 +18,24 @@ import 'package:flutter/material.dart'; class ListWheelViewportDemo extends StatelessWidget { final List data = [ - Colors.blue[50], Colors.blue[100], Colors.blue[200], - Colors.blue[300], Colors.blue[400], Colors.blue[500], - Colors.blue[600], Colors.blue[700], Colors.blue[800], - Colors.blue[900], Colors.blue[800], Colors.blue[700], - Colors.blue[600], Colors.blue[500], Colors.blue[400], - Colors.blue[300], Colors.blue[200], Colors.blue[100], + Colors.blue[50]!, + Colors.blue[100]!, + Colors.blue[200]!, + Colors.blue[300]!, + Colors.blue[400]!, + Colors.blue[500]!, + Colors.blue[600]!, + Colors.blue[700]!, + Colors.blue[800]!, + Colors.blue[900]!, + Colors.blue[800]!, + Colors.blue[700]!, + Colors.blue[600]!, + Colors.blue[500]!, + Colors.blue[400]!, + Colors.blue[300]!, + Colors.blue[200]!, + Colors.blue[100]!, ]; @override diff --git a/lib/views/widgets/Other/ListWheelViewport/node2_perspective.dart b/lib/views/widgets/Other/ListWheelViewport/node2_perspective.dart index fc9f260..5c9e476 100644 --- a/lib/views/widgets/Other/ListWheelViewport/node2_perspective.dart +++ b/lib/views/widgets/Other/ListWheelViewport/node2_perspective.dart @@ -16,12 +16,24 @@ import 'package:flutter/material.dart'; class ListWheelViewportDemo2 extends StatelessWidget { final List data = [ - Colors.blue[50], Colors.blue[100], Colors.blue[200], - Colors.blue[300], Colors.blue[400], Colors.blue[500], - Colors.blue[600], Colors.blue[700], Colors.blue[800], - Colors.blue[900], Colors.blue[800], Colors.blue[700], - Colors.blue[600], Colors.blue[500], Colors.blue[400], - Colors.blue[300], Colors.blue[200], Colors.blue[100], + Colors.blue[50]!, + Colors.blue[100]!, + Colors.blue[200]!, + Colors.blue[300]!, + Colors.blue[400]!, + Colors.blue[500]!, + Colors.blue[600]!, + Colors.blue[700]!, + Colors.blue[800]!, + Colors.blue[900]!, + Colors.blue[800]!, + Colors.blue[700]!, + Colors.blue[600]!, + Colors.blue[500]!, + Colors.blue[400]!, + Colors.blue[300]!, + Colors.blue[200]!, + Colors.blue[100]!, ]; @override @@ -34,25 +46,25 @@ class ListWheelViewportDemo2 extends StatelessWidget { physics: BouncingScrollPhysics(), dragStartBehavior: DragStartBehavior.start, viewportBuilder: (ctx, position) => ListWheelViewport( - perspective: 0.008, - squeeze: 1, - diameterRatio: 2, - itemExtent: 50, - offset: position, - childDelegate: ListWheelChildLoopingListDelegate( - children: data.map((e) => _buildItem(e)).toList()), - )), + perspective: 0.008, + squeeze: 1, + diameterRatio: 2, + itemExtent: 50, + offset: position, + childDelegate: ListWheelChildLoopingListDelegate( + children: data.map((e) => _buildItem(e)).toList()), + )), ); } Widget _buildItem(Color color) => Container( - alignment: Alignment.center, - color: color, - child: Text(colorString(color), - style: TextStyle(color: Colors.white, shadows: [ - Shadow(color: Colors.black, offset: Offset(.5, .5), blurRadius: 2) - ])), - ); + alignment: Alignment.center, + color: color, + child: Text(colorString(color), + style: TextStyle(color: Colors.white, shadows: [ + Shadow(color: Colors.black, offset: Offset(.5, .5), blurRadius: 2) + ])), + ); String colorString(Color color) => "#${color.value.toRadixString(16).padLeft(8, '0').toUpperCase()}"; diff --git a/lib/views/widgets/Other/ListWheelViewport/node3_magnifier.dart b/lib/views/widgets/Other/ListWheelViewport/node3_magnifier.dart index 1248f0f..5a6bc3c 100644 --- a/lib/views/widgets/Other/ListWheelViewport/node3_magnifier.dart +++ b/lib/views/widgets/Other/ListWheelViewport/node3_magnifier.dart @@ -17,13 +17,26 @@ import 'package:flutter/material.dart'; // } class ListWheelViewportDemo3 extends StatelessWidget { + final List data = [ - Colors.blue[50], Colors.blue[100], Colors.blue[200], - Colors.blue[300], Colors.blue[400], Colors.blue[500], - Colors.blue[600], Colors.blue[700], Colors.blue[800], - Colors.blue[900], Colors.blue[800], Colors.blue[700], - Colors.blue[600], Colors.blue[500], Colors.blue[400], - Colors.blue[300], Colors.blue[200], Colors.blue[100], + Colors.blue[50]!, + Colors.blue[100]!, + Colors.blue[200]!, + Colors.blue[300]!, + Colors.blue[400]!, + Colors.blue[500]!, + Colors.blue[600]!, + Colors.blue[700]!, + Colors.blue[800]!, + Colors.blue[900]!, + Colors.blue[800]!, + Colors.blue[700]!, + Colors.blue[600]!, + Colors.blue[500]!, + Colors.blue[400]!, + Colors.blue[300]!, + Colors.blue[200]!, + Colors.blue[100]!, ]; @override diff --git a/lib/views/widgets/Other/ListWheelViewport/node4_opacity.dart b/lib/views/widgets/Other/ListWheelViewport/node4_opacity.dart index a467b1d..47ac3d5 100644 --- a/lib/views/widgets/Other/ListWheelViewport/node4_opacity.dart +++ b/lib/views/widgets/Other/ListWheelViewport/node4_opacity.dart @@ -15,13 +15,26 @@ import 'package:flutter/material.dart'; // } class ListWheelViewportDemo4 extends StatelessWidget { + final List data = [ - Colors.blue[50], Colors.blue[100], Colors.blue[200], - Colors.blue[300], Colors.blue[400], Colors.blue[500], - Colors.blue[600], Colors.blue[700], Colors.blue[800], - Colors.blue[900], Colors.blue[800], Colors.blue[700], - Colors.blue[600], Colors.blue[500], Colors.blue[400], - Colors.blue[300], Colors.blue[200], Colors.blue[100], + Colors.blue[50]!, + Colors.blue[100]!, + Colors.blue[200]!, + Colors.blue[300]!, + Colors.blue[400]!, + Colors.blue[500]!, + Colors.blue[600]!, + Colors.blue[700]!, + Colors.blue[800]!, + Colors.blue[900]!, + Colors.blue[800]!, + Colors.blue[700]!, + Colors.blue[600]!, + Colors.blue[500]!, + Colors.blue[400]!, + Colors.blue[300]!, + Colors.blue[200]!, + Colors.blue[100]!, ]; @override diff --git a/lib/views/widgets/Other/RawImage/node1_base.dart b/lib/views/widgets/Other/RawImage/node1_base.dart index dd31189..30df924 100644 --- a/lib/views/widgets/Other/RawImage/node1_base.dart +++ b/lib/views/widgets/Other/RawImage/node1_base.dart @@ -24,7 +24,7 @@ class RawImageDemo extends StatefulWidget { } class _RawImageDemoState extends State { - ui.Image _image; + ui.Image? _image; @override void initState() { @@ -76,17 +76,17 @@ class _RawImageDemoState extends State { void _loadImageFromAssets(String name) async { _image = await loadImageByProvider(AssetImage(name)); - setState(() {}); } + late ImageStreamListener listener; + //通过ImageProvider读取Image Future loadImageByProvider( ImageProvider provider, { ImageConfiguration config = ImageConfiguration.empty, }) async { Completer completer = Completer(); //完成的回调 - ImageStreamListener listener; ImageStream stream = provider.resolve(config); //获取图片流 listener = ImageStreamListener((ImageInfo frame, bool sync) { //监听 diff --git a/lib/views/widgets/ProxyWidget/ChipTheme/node1_base.dart b/lib/views/widgets/ProxyWidget/ChipTheme/node1_base.dart index 013cd2b..33e5081 100644 --- a/lib/views/widgets/ProxyWidget/ChipTheme/node1_base.dart +++ b/lib/views/widgets/ProxyWidget/ChipTheme/node1_base.dart @@ -59,12 +59,12 @@ class _CustomFilterChipState extends State { padding: const EdgeInsets.all(4.0), child: FilterChip( avatar: CircleAvatar(child: Text(key)), - label: Text(map[key]), + label: Text(map[key]!), selected: _selected.contains(map[key]), onSelected: (bool value) { setState(() { if (value) { - _selected.add(map[key]); + _selected.add(map[key]!); } else { _selected.removeWhere((name) => name == map[key]); } diff --git a/lib/views/widgets/ProxyWidget/DefaultAssetBundle/node1_base.dart b/lib/views/widgets/ProxyWidget/DefaultAssetBundle/node1_base.dart index 942dcbc..0874404 100644 --- a/lib/views/widgets/ProxyWidget/DefaultAssetBundle/node1_base.dart +++ b/lib/views/widgets/ProxyWidget/DefaultAssetBundle/node1_base.dart @@ -20,7 +20,7 @@ class DefaultAssetBundleDemo extends StatefulWidget { } class _DefaultAssetBundleDemoState extends State { - ui.Image _image; + ui.Image? _image; @override void initState() { super.initState(); diff --git a/lib/views/widgets/ProxyWidget/DropdownButtonHideUnderline/node1_base.dart b/lib/views/widgets/ProxyWidget/DropdownButtonHideUnderline/node1_base.dart index cc97cf3..ecd30fb 100644 --- a/lib/views/widgets/ProxyWidget/DropdownButtonHideUnderline/node1_base.dart +++ b/lib/views/widgets/ProxyWidget/DropdownButtonHideUnderline/node1_base.dart @@ -19,8 +19,13 @@ class CustomDropDownButtonHideUnderline extends StatefulWidget { class _CustomDropDownButtonHideUnderlineState extends State { Color _color = Colors.red; - final _colors = [Colors.red, Colors.yellow, Colors.blue, Colors.green]; - final _info = ["红色", "黄色", "蓝色", "绿色"]; + final List _colors = [ + Colors.red, + Colors.yellow, + Colors.blue, + Colors.green + ]; + final List _info = ["红色", "黄色", "蓝色", "绿色"]; @override Widget build(BuildContext context) { @@ -42,7 +47,8 @@ class _CustomDropDownButtonHideUnderlineState color: _color, ), items: _buildItems(), - onChanged: (v) => setState(() => _color = v)), + onChanged: (Color? color) => + setState(() => _color = color ?? _color)), ), ], ); diff --git a/lib/views/widgets/ProxyWidget/InheritedWidget/node1_base.dart b/lib/views/widgets/ProxyWidget/InheritedWidget/node1_base.dart index 2845693..76f98d9 100644 --- a/lib/views/widgets/ProxyWidget/InheritedWidget/node1_base.dart +++ b/lib/views/widgets/ProxyWidget/InheritedWidget/node1_base.dart @@ -32,7 +32,7 @@ class InheritedWidgetDemo extends StatelessWidget { class InfoWidget extends StatelessWidget { @override Widget build(BuildContext context) { - String info = InfoInheritedWidget.of(context).info; + String info = InfoInheritedWidget.of(context)?.info??''; return Container( color: Colors.blue.withOpacity(0.1), @@ -46,13 +46,13 @@ class InfoWidget extends StatelessWidget { class InfoInheritedWidget extends InheritedWidget { final String info; - InfoInheritedWidget({Key key, this.info, @required Widget child}) + InfoInheritedWidget({Key? key,required this.info, required Widget child}) : super(key: key, child: child); @override bool updateShouldNotify(covariant InfoInheritedWidget oldWidget) => info != oldWidget.info; - static InfoInheritedWidget of(BuildContext context) => + static InfoInheritedWidget? of(BuildContext context) => context.dependOnInheritedWidgetOfExactType(); } diff --git a/lib/views/widgets/ProxyWidget/KeepAlive/node1_base.dart b/lib/views/widgets/ProxyWidget/KeepAlive/node1_base.dart index 135d896..af26994 100644 --- a/lib/views/widgets/ProxyWidget/KeepAlive/node1_base.dart +++ b/lib/views/widgets/ProxyWidget/KeepAlive/node1_base.dart @@ -18,26 +18,26 @@ import 'package:flutter/material.dart'; class KeepAliveDemo extends StatelessWidget { final List data = [ - Colors.purple[50], - Colors.purple[100], - Colors.purple[200], - Colors.purple[300], - Colors.purple[400], - Colors.purple[500], - Colors.purple[600], - Colors.purple[700], - Colors.purple[800], - Colors.purple[900], - Colors.red[50], - Colors.red[100], - Colors.red[200], - Colors.red[300], - Colors.red[400], - Colors.red[500], - Colors.red[600], - Colors.red[700], - Colors.red[800], - Colors.red[900], + Colors.purple[50]!, + Colors.purple[100]!, + Colors.purple[200]!, + Colors.purple[300]!, + Colors.purple[400]!, + Colors.purple[500]!, + Colors.purple[600]!, + Colors.purple[700]!, + Colors.purple[800]!, + Colors.purple[900]!, + Colors.red[50]!, + Colors.red[100]!, + Colors.red[200]!, + Colors.red[300]!, + Colors.red[400]!, + Colors.red[500]!, + Colors.red[600]!, + Colors.red[700]!, + Colors.red[800]!, + Colors.red[900]!, ]; @override @@ -59,7 +59,7 @@ class ColorBox extends StatefulWidget { final Color color; final int index; - ColorBox({Key key, this.color, this.index}) : super(key: key); + ColorBox({Key? key,required this.color,required this.index}) : super(key: key); @override _ColorBoxState createState() => _ColorBoxState(); @@ -94,9 +94,9 @@ class _ColorBoxState extends State with AutomaticKeepAliveClientMixin SizedBox(width: 60,), Checkbox( value: _checked, - onChanged: (v) { + onChanged: (bool? v) { setState(() { - _checked = v; + _checked = v??false; }); }, ), diff --git a/lib/views/widgets/ProxyWidget/PrimaryScrollController/node1_base.dart b/lib/views/widgets/ProxyWidget/PrimaryScrollController/node1_base.dart index c59121f..45664c0 100644 --- a/lib/views/widgets/ProxyWidget/PrimaryScrollController/node1_base.dart +++ b/lib/views/widgets/ProxyWidget/PrimaryScrollController/node1_base.dart @@ -24,7 +24,7 @@ class PrimaryScrollControllerDemo extends StatelessWidget { @override Widget build(BuildContext context) { - ScrollController label = PrimaryScrollController.of(context); + ScrollController? label = PrimaryScrollController.of(context); return Container( color: Colors.blue.withOpacity(0.1), diff --git a/lib/views/widgets/ProxyWidget/ScrollConfiguration/node1_base.dart b/lib/views/widgets/ProxyWidget/ScrollConfiguration/node1_base.dart index a8bb6e5..b753b16 100644 --- a/lib/views/widgets/ProxyWidget/ScrollConfiguration/node1_base.dart +++ b/lib/views/widgets/ProxyWidget/ScrollConfiguration/node1_base.dart @@ -14,16 +14,16 @@ import 'package:flutter/material.dart'; // } class CustomScrollConfiguration extends StatelessWidget { final data = [ - Colors.cyan[50], - Colors.cyan[100], - Colors.cyan[200], - Colors.cyan[300], - Colors.cyan[400], - Colors.cyan[500], - Colors.cyan[600], - Colors.cyan[700], - Colors.cyan[800], - Colors.cyan[900], + Colors.cyan[50]!, + Colors.cyan[100]!, + Colors.cyan[200]!, + Colors.cyan[300]!, + Colors.cyan[400]!, + Colors.cyan[500]!, + Colors.cyan[600]!, + Colors.cyan[700]!, + Colors.cyan[800]!, + Colors.cyan[900]!, ]; @override diff --git a/lib/views/widgets/ProxyWidget/SliderTheme/node2_diy.dart b/lib/views/widgets/ProxyWidget/SliderTheme/node2_diy.dart index 885db01..e1e0c8b 100644 --- a/lib/views/widgets/ProxyWidget/SliderTheme/node2_diy.dart +++ b/lib/views/widgets/ProxyWidget/SliderTheme/node2_diy.dart @@ -38,7 +38,7 @@ class _DIYSliderThemeState extends State { valueIndicatorColor: Colors.deepPurpleAccent, thumbShape: _CustomThumbShape(), valueIndicatorShape: _CustomValueIndicatorShape(), - valueIndicatorTextStyle: theme.accentTextTheme.body2 + valueIndicatorTextStyle: theme.accentTextTheme.body2! .copyWith(color: theme.colorScheme.onSurface), ), child: Slider( @@ -75,16 +75,16 @@ class _CustomThumbShape extends SliderComponentShape { @override void paint(PaintingContext context, Offset center, - {Animation activationAnimation, - Animation enableAnimation, - bool isDiscrete, - TextPainter labelPainter, - RenderBox parentBox, - SliderThemeData sliderTheme, - TextDirection textDirection, - double value, - double textScaleFactor, - Size sizeWithOverflow}) { + {required Animation activationAnimation, + required Animation enableAnimation, + required bool isDiscrete, + required TextPainter labelPainter, + required RenderBox parentBox, + required SliderThemeData sliderTheme, + required TextDirection textDirection, + required double value, + required double textScaleFactor, + required Size sizeWithOverflow}) { final Canvas canvas = context.canvas; final ColorTween colorTween = ColorTween( begin: sliderTheme.disabledThumbColor, @@ -92,8 +92,8 @@ class _CustomThumbShape extends SliderComponentShape { ); final double size = _thumbSize * sizeTween.evaluate(enableAnimation); final Path thumbPath = _downTriangle(size, center); - canvas.drawPath( - thumbPath, Paint()..color = colorTween.evaluate(enableAnimation)); + canvas.drawPath(thumbPath, + Paint()..color = colorTween.evaluate(enableAnimation) ?? Colors.blue); } } @@ -132,16 +132,16 @@ class _CustomValueIndicatorShape extends SliderComponentShape { @override void paint(PaintingContext context, Offset center, - {Animation activationAnimation, - Animation enableAnimation, - bool isDiscrete, - TextPainter labelPainter, - RenderBox parentBox, - SliderThemeData sliderTheme, - TextDirection textDirection, - double value, - double textScaleFactor, - Size sizeWithOverflow}) { + {required Animation activationAnimation, + required Animation enableAnimation, + required bool isDiscrete, + required TextPainter labelPainter, + required RenderBox parentBox, + required SliderThemeData sliderTheme, + required TextDirection textDirection, + required double value, + required double textScaleFactor, + required Size sizeWithOverflow}) { final Canvas canvas = context.canvas; final ColorTween enableColor = ColorTween( begin: sliderTheme.disabledThumbColor, @@ -156,8 +156,9 @@ class _CustomValueIndicatorShape extends SliderComponentShape { Offset(0.0, -slideUpTween.evaluate(activationAnimation)); final Path thumbPath = _upTriangle(size, center + slideUpOffset); final Color paintColor = enableColor - .evaluate(enableAnimation) - .withAlpha((255.0 * activationAnimation.value).round()); + .evaluate(enableAnimation) + ?.withAlpha((255.0 * activationAnimation.value).round()) ?? + Colors.black; canvas.drawPath( thumbPath, Paint()..color = paintColor, diff --git a/lib/views/widgets/SingleChildRenderObjectWidget/Align/node2_other.dart b/lib/views/widgets/SingleChildRenderObjectWidget/Align/node2_other.dart index d16e6e2..331aaa1 100644 --- a/lib/views/widgets/SingleChildRenderObjectWidget/Align/node2_other.dart +++ b/lib/views/widgets/SingleChildRenderObjectWidget/Align/node2_other.dart @@ -14,7 +14,7 @@ import 'package:flutter/material.dart'; // } class Ball extends StatelessWidget { Ball({ - Key key, + Key? key, this.radius = 15, this.color = Colors.blue, }) : super(key: key); @@ -36,7 +36,7 @@ class Ball extends StatelessWidget { class SinLayout extends StatefulWidget { SinLayout({ - Key key, + Key? key, }) : super(key: key); @override diff --git a/lib/views/widgets/SingleChildRenderObjectWidget/AnimatedSize/node1_base.dart b/lib/views/widgets/SingleChildRenderObjectWidget/AnimatedSize/node1_base.dart index df49a4b..b01f430 100644 --- a/lib/views/widgets/SingleChildRenderObjectWidget/AnimatedSize/node1_base.dart +++ b/lib/views/widgets/SingleChildRenderObjectWidget/AnimatedSize/node1_base.dart @@ -26,7 +26,7 @@ class _CustomAnimatedSizeState extends State final double start = 100; final double end = 200; - double _width; + late double _width; @override void initState() { diff --git a/lib/views/widgets/SingleChildRenderObjectWidget/ClipPath/node1_base.dart b/lib/views/widgets/SingleChildRenderObjectWidget/ClipPath/node1_base.dart index 1fdb022..e000625 100644 --- a/lib/views/widgets/SingleChildRenderObjectWidget/ClipPath/node1_base.dart +++ b/lib/views/widgets/SingleChildRenderObjectWidget/ClipPath/node1_base.dart @@ -33,20 +33,20 @@ class _StarShapeBorder extends ShapeBorder { final Path _path = Path(); @override - EdgeInsetsGeometry get dimensions => null; + EdgeInsetsGeometry get dimensions => EdgeInsets.zero; @override - Path getInnerPath(Rect rect, {TextDirection textDirection}) { - return null; + Path getInnerPath(Rect rect, {TextDirection? textDirection}) { + return Path(); } @override - Path getOuterPath(Rect rect, {TextDirection textDirection}) => + Path getOuterPath(Rect rect, {TextDirection? textDirection}) => nStarPath(20, rect.height / 2, rect.height / 2 * 0.85, dx: rect.width / 2, dy: rect.height / 2); @override - void paint(Canvas canvas, Rect rect, {TextDirection textDirection}) {} + void paint(Canvas canvas, Rect rect, {TextDirection? textDirection}) {} Path nStarPath(int num, double R, double r, {dx = 0, dy = 0}) { double perRad = 2 * pi / num; @@ -65,6 +65,6 @@ class _StarShapeBorder extends ShapeBorder { @override ShapeBorder scale(double t) { - return null; + return this; } } diff --git a/lib/views/widgets/SingleChildRenderObjectWidget/CompositedTransformFollower/node1_base.dart b/lib/views/widgets/SingleChildRenderObjectWidget/CompositedTransformFollower/node1_base.dart index c54530e..0138d03 100644 --- a/lib/views/widgets/SingleChildRenderObjectWidget/CompositedTransformFollower/node1_base.dart +++ b/lib/views/widgets/SingleChildRenderObjectWidget/CompositedTransformFollower/node1_base.dart @@ -54,14 +54,13 @@ class _LogoTips extends StatefulWidget { } class _LogoTipsState extends State<_LogoTips> { - OverlayEntry _overlayEntry; + OverlayEntry? _overlayEntry; final LayerLink _layerLink = LayerLink(); bool show = false; OverlayEntry _createOverlayEntry() { - return OverlayEntry( builder: (context) => Positioned( width: 150, @@ -104,7 +103,7 @@ class _LogoTipsState extends State<_LogoTips> { void _showOverlay() { _overlayEntry = _createOverlayEntry(); - Overlay.of(context).insert(_overlayEntry); + Overlay.of(context)?.insert(_overlayEntry!); } void _hideOverlay() { diff --git a/lib/views/widgets/SingleChildRenderObjectWidget/CompositedTransformTarget/node1_base.dart b/lib/views/widgets/SingleChildRenderObjectWidget/CompositedTransformTarget/node1_base.dart index 7ae48ca..ff3061e 100644 --- a/lib/views/widgets/SingleChildRenderObjectWidget/CompositedTransformTarget/node1_base.dart +++ b/lib/views/widgets/SingleChildRenderObjectWidget/CompositedTransformTarget/node1_base.dart @@ -49,7 +49,7 @@ class _LogoTips extends StatefulWidget { } class _LogoTipsState extends State<_LogoTips> { - OverlayEntry _overlayEntry; + OverlayEntry? _overlayEntry; final LayerLink _layerLink = LayerLink(); @@ -97,7 +97,7 @@ class _LogoTipsState extends State<_LogoTips> { void _showOverlay() { _overlayEntry = _createOverlayEntry(); - Overlay.of(context).insert(_overlayEntry); + Overlay.of(context)?.insert(_overlayEntry!); } void _hideOverlay() { diff --git a/lib/views/widgets/SingleChildRenderObjectWidget/CustomPaint/node1_clock.dart b/lib/views/widgets/SingleChildRenderObjectWidget/CustomPaint/node1_clock.dart index c86f46c..50a498b 100644 --- a/lib/views/widgets/SingleChildRenderObjectWidget/CustomPaint/node1_clock.dart +++ b/lib/views/widgets/SingleChildRenderObjectWidget/CustomPaint/node1_clock.dart @@ -26,8 +26,8 @@ class ClockPage extends StatelessWidget { } class ClockPainter extends CustomPainter { - Paint _paint; - var _radius = 3.0; //小球半径 + late Paint _paint; + double _radius = 3.0; //小球半径 Path _path = Path(); //画笔对象 ClockPainter () { _paint = Paint()..color= Color(0xff45d0fd)..isAntiAlias=true; diff --git a/lib/views/widgets/SingleChildRenderObjectWidget/CustomPaint/node2_bezier.dart b/lib/views/widgets/SingleChildRenderObjectWidget/CustomPaint/node2_bezier.dart index fdc124b..b024b86 100644 --- a/lib/views/widgets/SingleChildRenderObjectWidget/CustomPaint/node2_bezier.dart +++ b/lib/views/widgets/SingleChildRenderObjectWidget/CustomPaint/node2_bezier.dart @@ -20,7 +20,7 @@ class PlayBezier3Page extends StatefulWidget { class _PlayBezier3PageState extends State { List _pos = []; - int selectPos; + int selectPos=0; @override void initState() { @@ -53,17 +53,17 @@ class _PlayBezier3PageState extends State { } class BezierPainter extends CustomPainter { - Paint _gridPaint; - Path _gridPath; + late Paint _gridPaint; + late Path _gridPath; - Paint _mainPaint; - Path _mainPath; - int selectPos; - Paint _helpPaint; + late Paint _mainPaint; + late Path _mainPath; + int? selectPos; + late Paint _helpPaint; List pos; - BezierPainter({this.pos, this.selectPos}) { + BezierPainter({this.pos=const [], this.selectPos}) { _gridPaint = Paint()..style = PaintingStyle.stroke; _gridPath = Path(); @@ -166,7 +166,7 @@ class BezierPainter extends CustomPainter { void _drawSelectPos(Canvas canvas) { if (selectPos == null) return; canvas.drawCircle( - pos[selectPos], + pos[selectPos!], 10, _helpPaint ..color = Colors.green diff --git a/lib/views/widgets/SingleChildRenderObjectWidget/CustomSingleChildLayout/node2_offset.dart b/lib/views/widgets/SingleChildRenderObjectWidget/CustomSingleChildLayout/node2_offset.dart index 4b5444c..b4fe6af 100644 --- a/lib/views/widgets/SingleChildRenderObjectWidget/CustomSingleChildLayout/node2_offset.dart +++ b/lib/views/widgets/SingleChildRenderObjectWidget/CustomSingleChildLayout/node2_offset.dart @@ -13,7 +13,7 @@ import 'package:flutter/material.dart'; // } class OffSetWidgetDemo extends StatelessWidget { - final data = [ + final List> data = [ { 'offset': Offset(20, 20), 'direction': Direction.topLeft, @@ -71,7 +71,7 @@ class OffSetWidget extends StatelessWidget { OffSetWidget( {this.offset = Offset.zero, - this.child, + required this.child, this.direction = Direction.topLeft}); @override diff --git a/lib/views/widgets/SingleChildRenderObjectWidget/FadeTransition/node1_base.dart b/lib/views/widgets/SingleChildRenderObjectWidget/FadeTransition/node1_base.dart index 9e69d82..b96452a 100644 --- a/lib/views/widgets/SingleChildRenderObjectWidget/FadeTransition/node1_base.dart +++ b/lib/views/widgets/SingleChildRenderObjectWidget/FadeTransition/node1_base.dart @@ -18,7 +18,7 @@ class CustomFadeTransition extends StatefulWidget { class _CustomFadeTransitionState extends State with SingleTickerProviderStateMixin { - AnimationController _ctrl; + late AnimationController _ctrl; @override void initState() { @@ -37,7 +37,6 @@ class _CustomFadeTransitionState extends State Widget build(BuildContext context) { return GestureDetector( onTap: () => _ctrl.forward(from: 0), - child: Container( color: Colors.grey.withAlpha(22), width: 100, diff --git a/lib/views/widgets/SingleChildRenderObjectWidget/RepaintBoundary/node1_base.dart b/lib/views/widgets/SingleChildRenderObjectWidget/RepaintBoundary/node1_base.dart index abd4c46..89e2b3c 100644 --- a/lib/views/widgets/SingleChildRenderObjectWidget/RepaintBoundary/node1_base.dart +++ b/lib/views/widgets/SingleChildRenderObjectWidget/RepaintBoundary/node1_base.dart @@ -30,7 +30,7 @@ class TempPlayBezier3Page extends StatefulWidget { class _TempPlayBezier3PageState extends State { List _pos = []; - int selectPos; + int? selectPos; @override void initState() { @@ -59,17 +59,17 @@ class _TempPlayBezier3PageState extends State { } class TempBezierPainter extends CustomPainter { - Paint _gridPaint; - Path _gridPath; + late Paint _gridPaint; + late Path _gridPath; - Paint _mainPaint; - Path _mainPath; - int selectPos; - Paint _helpPaint; + late Paint _mainPaint; + late Path _mainPath; + int? selectPos; + late Paint _helpPaint; List pos; - TempBezierPainter({this.pos, this.selectPos}) { + TempBezierPainter({this.pos=const [], this.selectPos}) { _gridPaint = Paint()..style = PaintingStyle.stroke; _gridPath = Path(); @@ -173,7 +173,7 @@ class TempBezierPainter extends CustomPainter { void _drawSelectPos(Canvas canvas) { if (selectPos == null) return; canvas.drawCircle( - pos[selectPos], + pos[selectPos!], 10, _helpPaint ..color = Colors.green diff --git a/lib/views/widgets/SingleChildRenderObjectWidget/RepaintBoundary/node2_save.dart b/lib/views/widgets/SingleChildRenderObjectWidget/RepaintBoundary/node2_save.dart index 7d700f2..bf876ad 100644 --- a/lib/views/widgets/SingleChildRenderObjectWidget/RepaintBoundary/node2_save.dart +++ b/lib/views/widgets/SingleChildRenderObjectWidget/RepaintBoundary/node2_save.dart @@ -49,6 +49,7 @@ class RepaintBoundarySave extends StatelessWidget { var bits = await _widget2Image(_globalKey); var dir = await getApplicationSupportDirectory(); var file = File(dir.path + "/save_img.png"); + if(bits==null) return; var f = await file.writeAsBytes(bits); Scaffold.of(context).showSnackBar(SnackBar( backgroundColor: Theme.of(context).primaryColor, @@ -56,13 +57,15 @@ class RepaintBoundarySave extends StatelessWidget { )); }); - Future _widget2Image(GlobalKey key) async { - RenderRepaintBoundary boundary = key.currentContext.findRenderObject(); + Future _widget2Image(GlobalKey key) async { + RenderObject? boundary = key.currentContext?.findRenderObject(); + if(boundary==null || boundary is! RenderRepaintBoundary) return null; + //获得 ui.image ui.Image img = await boundary.toImage(); //获取图片字节 var byteData = await img.toByteData(format: ui.ImageByteFormat.png); - Uint8List bits = byteData.buffer.asUint8List(); + Uint8List? bits = byteData?.buffer.asUint8List(); return bits; } } diff --git a/lib/views/widgets/SingleChildRenderObjectWidget/Transform/node1_skew.dart b/lib/views/widgets/SingleChildRenderObjectWidget/Transform/node1_skew.dart index 067c9c0..4d64e62 100644 --- a/lib/views/widgets/SingleChildRenderObjectWidget/Transform/node1_skew.dart +++ b/lib/views/widgets/SingleChildRenderObjectWidget/Transform/node1_skew.dart @@ -23,7 +23,7 @@ class SkewTransform extends StatefulWidget { } class _SkewTransformState extends State { - Matrix4 _m4; + late Matrix4 _m4; double _alpha = 0; double _beta = 0; diff --git a/lib/views/widgets/SingleChildRenderObjectWidget/Transform/node2_translation.dart b/lib/views/widgets/SingleChildRenderObjectWidget/Transform/node2_translation.dart index 4d3980e..02835c2 100644 --- a/lib/views/widgets/SingleChildRenderObjectWidget/Transform/node2_translation.dart +++ b/lib/views/widgets/SingleChildRenderObjectWidget/Transform/node2_translation.dart @@ -21,7 +21,7 @@ class TranslationTransform extends StatefulWidget { } class _TranslationTransformState extends State { - Matrix4 _m4; + late Matrix4 _m4; double _x = 0; double _y = 0; double _z = 0; diff --git a/lib/views/widgets/SingleChildRenderObjectWidget/Transform/node3_scale.dart b/lib/views/widgets/SingleChildRenderObjectWidget/Transform/node3_scale.dart index ef27825..97a5e63 100644 --- a/lib/views/widgets/SingleChildRenderObjectWidget/Transform/node3_scale.dart +++ b/lib/views/widgets/SingleChildRenderObjectWidget/Transform/node3_scale.dart @@ -20,7 +20,7 @@ class ScaleTransform extends StatefulWidget { } class _ScaleTransformState extends State { - Matrix4 _m4; + late Matrix4 _m4; double _x = 1.0; double _y = 1.0; double _z = 1.0; diff --git a/lib/views/widgets/SingleChildRenderObjectWidget/Transform/node4_rotate.dart b/lib/views/widgets/SingleChildRenderObjectWidget/Transform/node4_rotate.dart index 2becac1..5444d67 100644 --- a/lib/views/widgets/SingleChildRenderObjectWidget/Transform/node4_rotate.dart +++ b/lib/views/widgets/SingleChildRenderObjectWidget/Transform/node4_rotate.dart @@ -23,7 +23,7 @@ class RotateTransform extends StatefulWidget { } class _RotateTransformState extends State { - Matrix4 _m4; + late Matrix4 _m4; double _x = 0; int _rotateFlag = 1; @@ -103,7 +103,7 @@ class _RotateTransformState extends State { pressElevation: 5, elevation: 3, avatar: CircleAvatar(child: Text(key.toString())), - label: Text(map[key]), + label: Text(map[key]!), selected: _rotateFlag == key, onSelected: (bool value) { print(map[key]); diff --git a/lib/views/widgets/SingleChildRenderObjectWidget/Transform/node5_perspective.dart b/lib/views/widgets/SingleChildRenderObjectWidget/Transform/node5_perspective.dart index 97b37a4..5a90e75 100644 --- a/lib/views/widgets/SingleChildRenderObjectWidget/Transform/node5_perspective.dart +++ b/lib/views/widgets/SingleChildRenderObjectWidget/Transform/node5_perspective.dart @@ -19,7 +19,7 @@ class R3C2 extends StatefulWidget { } class _R3C2State extends State { - Matrix4 _m4; + late Matrix4 _m4; double _value = 0; double _rad = 0; diff --git a/lib/views/widgets/Sliver/CupertinoSliverNavigationBar/node1_base.dart b/lib/views/widgets/Sliver/CupertinoSliverNavigationBar/node1_base.dart index 6f78cef..25a453f 100644 --- a/lib/views/widgets/Sliver/CupertinoSliverNavigationBar/node1_base.dart +++ b/lib/views/widgets/Sliver/CupertinoSliverNavigationBar/node1_base.dart @@ -18,17 +18,17 @@ import 'package:flutter/material.dart'; // "【padding】 : 内边距 【EdgeInsetsDirectional】", // } class CupertinoSliverNavigationBarDemo extends StatelessWidget { - final data = [ - Colors.orange[50], - Colors.orange[100], - Colors.orange[200], - Colors.orange[300], - Colors.orange[400], - Colors.orange[500], - Colors.orange[600], - Colors.orange[700], - Colors.orange[800], - Colors.orange[900], + final List data = [ + Colors.orange[50]!, + Colors.orange[100]!, + Colors.orange[200]!, + Colors.orange[300]!, + Colors.orange[400]!, + Colors.orange[500]!, + Colors.orange[600]!, + Colors.orange[700]!, + Colors.orange[800]!, + Colors.orange[900]!, ]; @override diff --git a/lib/views/widgets/Sliver/CupertinoSliverRefreshControl/node1_base.dart b/lib/views/widgets/Sliver/CupertinoSliverRefreshControl/node1_base.dart index 7e2e4dd..5938b6c 100644 --- a/lib/views/widgets/Sliver/CupertinoSliverRefreshControl/node1_base.dart +++ b/lib/views/widgets/Sliver/CupertinoSliverRefreshControl/node1_base.dart @@ -24,20 +24,20 @@ class CupertinoSliverRefreshControlDemo extends StatefulWidget { class _CupertinoSliverRefreshControlDemoState extends State { - final data = [ - Colors.orange[50], - Colors.orange[100], - Colors.orange[200], - Colors.orange[300], - Colors.orange[400], - Colors.orange[500], - Colors.orange[600], - Colors.orange[700], - Colors.orange[800], - Colors.orange[900], + final List data = [ + Colors.orange[50]!, + Colors.orange[100]!, + Colors.orange[200]!, + Colors.orange[300]!, + Colors.orange[400]!, + Colors.orange[500]!, + Colors.orange[600]!, + Colors.orange[700]!, + Colors.orange[800]!, + Colors.orange[900]!, ]; - final r = Random(); + final Random r = Random(); @override Widget build(BuildContext context) { diff --git a/lib/views/widgets/Sliver/CustomScrollView/node1_base.dart b/lib/views/widgets/Sliver/CustomScrollView/node1_base.dart index 2ff09ea..c177d69 100644 --- a/lib/views/widgets/Sliver/CustomScrollView/node1_base.dart +++ b/lib/views/widgets/Sliver/CustomScrollView/node1_base.dart @@ -15,16 +15,16 @@ import 'package:flutter/material.dart'; // } class CustomScrollViewDemo extends StatelessWidget { final List data = [ - Colors.purple[50], - Colors.purple[100], - Colors.purple[200], - Colors.purple[300], - Colors.purple[400], - Colors.purple[500], - Colors.purple[600], - Colors.purple[700], - Colors.purple[800], - Colors.purple[900], + Colors.purple[50]!, + Colors.purple[100]!, + Colors.purple[200]!, + Colors.purple[300]!, + Colors.purple[400]!, + Colors.purple[500]!, + Colors.purple[600]!, + Colors.purple[700]!, + Colors.purple[800]!, + Colors.purple[900]!, ]; @override diff --git a/lib/views/widgets/Sliver/FlexibleSpaceBar/node1_base.dart b/lib/views/widgets/Sliver/FlexibleSpaceBar/node1_base.dart index 39c745b..afa4b72 100644 --- a/lib/views/widgets/Sliver/FlexibleSpaceBar/node1_base.dart +++ b/lib/views/widgets/Sliver/FlexibleSpaceBar/node1_base.dart @@ -19,17 +19,17 @@ import 'package:flutter/material.dart'; // } class FlexibleSpaceBarDemo extends StatelessWidget { - final data = [ - Colors.blue[50], - Colors.blue[100], - Colors.blue[200], - Colors.blue[300], - Colors.blue[400], - Colors.blue[500], - Colors.blue[600], - Colors.blue[700], - Colors.blue[800], - Colors.blue[900], + final List data =[ + Colors.blue[50]!, + Colors.blue[100]!, + Colors.blue[200]!, + Colors.blue[300]!, + Colors.blue[400]!, + Colors.blue[500]!, + Colors.blue[600]!, + Colors.blue[700]!, + Colors.blue[800]!, + Colors.blue[900]!, ]; @override diff --git a/lib/views/widgets/Sliver/SliverAnimatedList/node1_base.dart b/lib/views/widgets/Sliver/SliverAnimatedList/node1_base.dart index be69ccc..9ac4cf4 100644 --- a/lib/views/widgets/Sliver/SliverAnimatedList/node1_base.dart +++ b/lib/views/widgets/Sliver/SliverAnimatedList/node1_base.dart @@ -21,9 +21,9 @@ class SliverAnimatedListDemo extends StatefulWidget { class _SliverAnimatedListDemoState extends State { final GlobalKey _listKey = GlobalKey(); - ListModel _list; - int _selectedItem; - int _nextItem; + late ListModel _list; + int? _selectedItem; + int _nextItem=0; @override void initState() { @@ -58,13 +58,13 @@ class _SliverAnimatedListDemoState extends State { } void _insert() { - final int index = _selectedItem == null ? _list.length : _list.indexOf(_selectedItem); + final int index = _selectedItem == null ? _list.length : _list.indexOf(_selectedItem!); _list.insert(index, _nextItem++); } void _remove() { if (_selectedItem != null) { - _list.removeAt(_list.indexOf(_selectedItem)); + _list.removeAt(_list.indexOf(_selectedItem!)); setState(() { _selectedItem = null; }); @@ -121,24 +121,23 @@ class _SliverAnimatedListDemoState extends State { class ListModel { ListModel({ - @required this.listKey, - @required this.removedItemBuilder, - Iterable initialItems, - }) : assert(listKey != null), - assert(removedItemBuilder != null), + required this.listKey, + required this.removedItemBuilder, + required Iterable? initialItems, + }) : assert(removedItemBuilder != null), _items = List.from(initialItems ?? []); final GlobalKey listKey; final dynamic removedItemBuilder; final List _items; - SliverAnimatedListState get _animatedList => listKey.currentState; + SliverAnimatedListState? get _animatedList => listKey.currentState; void insert(int index, E item) { _items.insert(index, item); - _animatedList.insertItem(index); + _animatedList?.insertItem(index); } E removeAt(int index) { final E removedItem = _items.removeAt(index); if (removedItem != null) { - _animatedList.removeItem( + _animatedList?.removeItem( index, (BuildContext context, Animation animation) => removedItemBuilder(removedItem, context, animation), ); @@ -153,17 +152,14 @@ class ListModel { class CardItem extends StatelessWidget { const CardItem({ - Key key, - @required this.animation, - @required this.item, + Key? key, + required this.animation, + required this.item, this.onTap, this.selected = false, - }) : assert(animation != null), - assert(item != null && item >= 0), - assert(selected != null), - super(key: key); + }) :super(key: key); final Animation animation; - final VoidCallback onTap; + final VoidCallback? onTap; final int item; final bool selected; @override diff --git a/lib/views/widgets/Sliver/SliverAppBar/node1_base.dart b/lib/views/widgets/Sliver/SliverAppBar/node1_base.dart index d48f587..06a9017 100644 --- a/lib/views/widgets/Sliver/SliverAppBar/node1_base.dart +++ b/lib/views/widgets/Sliver/SliverAppBar/node1_base.dart @@ -32,17 +32,17 @@ class _SliverAppBarDemoState extends State { bool _pinned = false; bool _snap = false; - final data = [ - Colors.purple[50], - Colors.purple[100], - Colors.purple[200], - Colors.purple[300], - Colors.purple[400], - Colors.purple[500], - Colors.purple[600], - Colors.purple[700], - Colors.purple[800], - Colors.purple[900], + final List data = [ + Colors.purple[50]!, + Colors.purple[100]!, + Colors.purple[200]!, + Colors.purple[300]!, + Colors.purple[400]!, + Colors.purple[500]!, + Colors.purple[600]!, + Colors.purple[700]!, + Colors.purple[800]!, + Colors.purple[900]!, ]; @override @@ -163,7 +163,6 @@ class _SliverAppBarDemoState extends State { if(_floating){ setState(() => _snap = v); } - }), ], ) diff --git a/lib/views/widgets/Sliver/SliverFillRemaining/node1_base.dart b/lib/views/widgets/Sliver/SliverFillRemaining/node1_base.dart index 31d4357..65114c1 100644 --- a/lib/views/widgets/Sliver/SliverFillRemaining/node1_base.dart +++ b/lib/views/widgets/Sliver/SliverFillRemaining/node1_base.dart @@ -22,20 +22,20 @@ class SliverFillRemainingDemo extends StatefulWidget { } class _SliverFillRemainingDemoState extends State { - final data = [ - Colors.orange[50], - Colors.orange[100], - Colors.orange[200], - Colors.orange[300], - Colors.orange[400], - Colors.orange[500], - Colors.orange[600], - Colors.orange[700], - Colors.orange[800], - Colors.orange[900], + final List data = [ + Colors.orange[50]!, + Colors.orange[100]!, + Colors.orange[200]!, + Colors.orange[300]!, + Colors.orange[400]!, + Colors.orange[500]!, + Colors.orange[600]!, + Colors.orange[700]!, + Colors.orange[800]!, + Colors.orange[900]!, ]; - final r = Random(); + final Random r = Random(); bool hasScrollBody = false; bool fillOverscroll = true; diff --git a/lib/views/widgets/Sliver/SliverFillViewport/node1_base.dart b/lib/views/widgets/Sliver/SliverFillViewport/node1_base.dart index 01d5237..85a62f2 100644 --- a/lib/views/widgets/Sliver/SliverFillViewport/node1_base.dart +++ b/lib/views/widgets/Sliver/SliverFillViewport/node1_base.dart @@ -17,19 +17,20 @@ class SliverFillViewportDemo extends StatefulWidget { } class _SliverFillViewportDemoState extends State { - final data = [ - Colors.orange[50], - Colors.orange[100], - Colors.orange[200], - Colors.orange[300], - Colors.orange[400], - Colors.orange[500], - Colors.orange[600], - Colors.orange[700], - Colors.orange[800], - Colors.orange[900], + final List data = [ + Colors.orange[50]!, + Colors.orange[100]!, + Colors.orange[200]!, + Colors.orange[300]!, + Colors.orange[400]!, + Colors.orange[500]!, + Colors.orange[600]!, + Colors.orange[700]!, + Colors.orange[800]!, + Colors.orange[900]!, ]; - var _viewportFraction = 0.5; + + double _viewportFraction = 0.5; @override Widget build(BuildContext context) { diff --git a/lib/views/widgets/Sliver/SliverFixedExtentList/node1_base.dart b/lib/views/widgets/Sliver/SliverFixedExtentList/node1_base.dart index c43fae0..6393749 100644 --- a/lib/views/widgets/Sliver/SliverFixedExtentList/node1_base.dart +++ b/lib/views/widgets/Sliver/SliverFixedExtentList/node1_base.dart @@ -17,19 +17,20 @@ class SliverFixedExtentListDemo extends StatefulWidget { } class _SliverFixedExtentListDemoState extends State { - final data = [ - Colors.orange[50], - Colors.orange[100], - Colors.orange[200], - Colors.orange[300], - Colors.orange[400], - Colors.orange[500], - Colors.orange[600], - Colors.orange[700], - Colors.orange[800], - Colors.orange[900], + final List data = [ + Colors.orange[50]!, + Colors.orange[100]!, + Colors.orange[200]!, + Colors.orange[300]!, + Colors.orange[400]!, + Colors.orange[500]!, + Colors.orange[600]!, + Colors.orange[700]!, + Colors.orange[800]!, + Colors.orange[900]!, ]; + @override Widget build(BuildContext context) { return Container( diff --git a/lib/views/widgets/Sliver/SliverIgnorePointer/node1_base.dart b/lib/views/widgets/Sliver/SliverIgnorePointer/node1_base.dart index 1046683..0433e35 100644 --- a/lib/views/widgets/Sliver/SliverIgnorePointer/node1_base.dart +++ b/lib/views/widgets/Sliver/SliverIgnorePointer/node1_base.dart @@ -21,20 +21,21 @@ class SliverIgnorePointerDemo extends StatefulWidget { } class _SliverIgnorePointerDemoState extends State { - final data = [ - Colors.orange[50], - Colors.orange[100], - Colors.orange[200], - Colors.orange[300], - Colors.orange[400], - Colors.orange[500], - Colors.orange[600], - Colors.orange[700], - Colors.orange[800], - Colors.orange[900], + final List data = [ + Colors.orange[50]!, + Colors.orange[100]!, + Colors.orange[200]!, + Colors.orange[300]!, + Colors.orange[400]!, + Colors.orange[500]!, + Colors.orange[600]!, + Colors.orange[700]!, + Colors.orange[800]!, + Colors.orange[900]!, ]; - final r = Random(); + + final Random r = Random(); bool hasScrollBody = false; bool fillOverscroll = true; diff --git a/lib/views/widgets/Sliver/SliverLayoutBuilder/node1_base.dart b/lib/views/widgets/Sliver/SliverLayoutBuilder/node1_base.dart index 274de28..e63dfb2 100644 --- a/lib/views/widgets/Sliver/SliverLayoutBuilder/node1_base.dart +++ b/lib/views/widgets/Sliver/SliverLayoutBuilder/node1_base.dart @@ -21,19 +21,20 @@ class SliverLayoutBuilderDemo extends StatefulWidget { } class _SliverLayoutBuilderDemoState extends State { - final data = [ - Colors.orange[50], - Colors.orange[100], - Colors.orange[200], - Colors.orange[300], - Colors.orange[400], - Colors.orange[500], - Colors.orange[600], - Colors.orange[700], - Colors.orange[800], - Colors.orange[900], + final List data = [ + Colors.orange[50]!, + Colors.orange[100]!, + Colors.orange[200]!, + Colors.orange[300]!, + Colors.orange[400]!, + Colors.orange[500]!, + Colors.orange[600]!, + Colors.orange[700]!, + Colors.orange[800]!, + Colors.orange[900]!, ]; + @override Widget build(BuildContext context) { return Container( diff --git a/lib/views/widgets/Sliver/SliverList/node1_base.dart b/lib/views/widgets/Sliver/SliverList/node1_base.dart index 06c62af..6c4744a 100644 --- a/lib/views/widgets/Sliver/SliverList/node1_base.dart +++ b/lib/views/widgets/Sliver/SliverList/node1_base.dart @@ -11,17 +11,17 @@ import 'package:flutter/material.dart'; // "【delegate】 : 孩子代理 【SliverChildDelegate】", // } class SliverListDemo extends StatelessWidget { - final data = [ - Colors.purple[50], - Colors.purple[100], - Colors.purple[200], - Colors.purple[300], - Colors.purple[400], - Colors.purple[500], - Colors.purple[600], - Colors.purple[700], - Colors.purple[800], - Colors.purple[900], + final List data =[ + Colors.purple[50]!, + Colors.purple[100]!, + Colors.purple[200]!, + Colors.purple[300]!, + Colors.purple[400]!, + Colors.purple[500]!, + Colors.purple[600]!, + Colors.purple[700]!, + Colors.purple[800]!, + Colors.purple[900]!, ]; @override diff --git a/lib/views/widgets/Sliver/SliverPersistentHeader/node1_base.dart b/lib/views/widgets/Sliver/SliverPersistentHeader/node1_base.dart index 1e1a607..1d6d515 100644 --- a/lib/views/widgets/Sliver/SliverPersistentHeader/node1_base.dart +++ b/lib/views/widgets/Sliver/SliverPersistentHeader/node1_base.dart @@ -15,17 +15,17 @@ import 'package:flutter/material.dart'; // "【pinned】 : 是否顶部停留 【bool】", // } class SliverPersistentHeaderDemo extends StatelessWidget { - final data = [ - Colors.purple[50], - Colors.purple[100], - Colors.purple[200], - Colors.purple[300], - Colors.purple[400], - Colors.purple[500], - Colors.purple[600], - Colors.purple[700], - Colors.purple[800], - Colors.purple[900], + final List data = [ + Colors.purple[50]!, + Colors.purple[100]!, + Colors.purple[200]!, + Colors.purple[300]!, + Colors.purple[400]!, + Colors.purple[500]!, + Colors.purple[600]!, + Colors.purple[700]!, + Colors.purple[800]!, + Colors.purple[900]!, ]; @override @@ -135,9 +135,9 @@ class SliverPersistentHeaderDemo extends StatelessWidget { class _SliverDelegate extends SliverPersistentHeaderDelegate { _SliverDelegate({ - @required this.minHeight, - @required this.maxHeight, - @required this.child, + required this.minHeight, + required this.maxHeight, + required this.child, }); final double minHeight; //最小高度 diff --git a/lib/views/widgets/Sliver/SliverPrototypeExtentList/SliverPrototypeExtentList.dart b/lib/views/widgets/Sliver/SliverPrototypeExtentList/SliverPrototypeExtentList.dart deleted file mode 100644 index e68f845..0000000 --- a/lib/views/widgets/Sliver/SliverPrototypeExtentList/SliverPrototypeExtentList.dart +++ /dev/null @@ -1,105 +0,0 @@ -import 'package:flutter/material.dart'; - -/// create by 张风捷特烈 on 2020/9/21 -/// contact me by email 1981462002@qq.com -/// 说明: 314 SliverPrototypeExtentList Sliver原型延伸列表 prototypeItem属性是一个Widget,该Widget负责在主轴方向上约束item尺寸,但会不显示出来。delegate接受一个SliverChildDelegate完成item的创建。 -// { -// "widgetId": 314, -// "name": 'SliverPrototypeExtentList基本使用', -// "priority": 1, -// "subtitle": -// "【prototypeItem】 : 主轴方向尺寸组件 【Widget】\n" -// "【delegate】 : 孩子代理 【SliverChildDelegate】", -// } -class SliverPrototypeExtentListDemo extends StatefulWidget { - @override - _SliverPrototypeExtentListDemoState createState() => - _SliverPrototypeExtentListDemoState(); -} - -class _SliverPrototypeExtentListDemoState - extends State { - final data = [ - Colors.orange[50], - Colors.orange[100], - Colors.orange[200], - Colors.orange[300], - Colors.orange[400], - Colors.orange[500], - Colors.orange[600], - Colors.orange[700], - Colors.orange[800], - Colors.orange[900], - ]; - - @override - Widget build(BuildContext context) { - return Container( - height: 300, - child: CustomScrollView( - slivers: [_buildSliverAppBar(), _buildSliverList()], - ), - ); - } - - Widget _buildSliverList() => SliverPrototypeExtentList( - prototypeItem: Container( - height: 80, - ), - delegate: SliverChildBuilderDelegate( - (_, int index) => Container( - alignment: Alignment.center, - width: 100, - height: 60, - color: data[index], - child: Text( - colorString(data[index]), - style: TextStyle(color: Colors.white, shadows: [ - Shadow( - color: Colors.black, - offset: Offset(.5, .5), - blurRadius: 2) - ]), - ), - ), - childCount: data.length), - ); - - Widget _buildSliverAppBar() { - return SliverAppBar( - expandedHeight: 150.0, - leading: _buildLeading(), - title: Text('张风捷特烈'), - actions: _buildActions(), - elevation: 5, - pinned: true, - backgroundColor: Colors.orange, - flexibleSpace: FlexibleSpaceBar( - //伸展处布局 - titlePadding: EdgeInsets.only(left: 55, bottom: 15), //标题边距 - collapseMode: CollapseMode.parallax, //视差效果 - background: Image.asset( - "assets/images/caver.webp", - fit: BoxFit.cover, - ), - ), - ); - } - - Widget _buildLeading() => Container( - margin: EdgeInsets.all(10), - child: Image.asset('assets/images/icon_head.webp')); - - List _buildActions() => [ - IconButton( - onPressed: () {}, - icon: Icon( - Icons.star_border, - color: Colors.white, - ), - ) - ]; - - String colorString(Color color) => - "#${color.value.toRadixString(16).padLeft(8, '0').toUpperCase()}"; -} diff --git a/lib/views/widgets/Sliver/SliverPrototypeExtentList/node1_base.dart b/lib/views/widgets/Sliver/SliverPrototypeExtentList/node1_base.dart index a8f3b12..0ee769c 100644 --- a/lib/views/widgets/Sliver/SliverPrototypeExtentList/node1_base.dart +++ b/lib/views/widgets/Sliver/SliverPrototypeExtentList/node1_base.dart @@ -19,17 +19,17 @@ class SliverPrototypeExtentListDemo extends StatefulWidget { class _SliverPrototypeExtentListDemoState extends State { - final data = [ - Colors.orange[50], - Colors.orange[100], - Colors.orange[200], - Colors.orange[300], - Colors.orange[400], - Colors.orange[500], - Colors.orange[600], - Colors.orange[700], - Colors.orange[800], - Colors.orange[900], + final List data = [ + Colors.orange[50]!, + Colors.orange[100]!, + Colors.orange[200]!, + Colors.orange[300]!, + Colors.orange[400]!, + Colors.orange[500]!, + Colors.orange[600]!, + Colors.orange[700]!, + Colors.orange[800]!, + Colors.orange[900]!, ]; @override diff --git a/lib/views/widgets/Sliver/SliverToBoxAdapter/node1_base.dart b/lib/views/widgets/Sliver/SliverToBoxAdapter/node1_base.dart index 167baa3..c00ff9d 100644 --- a/lib/views/widgets/Sliver/SliverToBoxAdapter/node1_base.dart +++ b/lib/views/widgets/Sliver/SliverToBoxAdapter/node1_base.dart @@ -11,17 +11,17 @@ import 'package:flutter/material.dart'; // "【child】 : 子组件 【Widget】", // } class SliverToBoxAdapterDemo extends StatelessWidget { - final data = [ - Colors.purple[50], - Colors.purple[100], - Colors.purple[200], - Colors.purple[300], - Colors.purple[400], - Colors.purple[500], - Colors.purple[600], - Colors.purple[700], - Colors.purple[800], - Colors.purple[900], + final List data = [ + Colors.purple[50]!, + Colors.purple[100]!, + Colors.purple[200]!, + Colors.purple[300]!, + Colors.purple[400]!, + Colors.purple[500]!, + Colors.purple[600]!, + Colors.purple[700]!, + Colors.purple[800]!, + Colors.purple[900]!, ]; @override diff --git a/lib/views/widgets/StatefulWidget/AlignTransition/node1_base.dart b/lib/views/widgets/StatefulWidget/AlignTransition/node1_base.dart index 2c0cac9..0ed3413 100644 --- a/lib/views/widgets/StatefulWidget/AlignTransition/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/AlignTransition/node1_base.dart @@ -18,7 +18,7 @@ class CustomAlignTransition extends StatefulWidget { class _CustomAlignTransitionState extends State with SingleTickerProviderStateMixin { - AnimationController _ctrl; + late AnimationController _ctrl; @override void initState() { diff --git a/lib/views/widgets/StatefulWidget/AnimatedAlign/node1_base.dart b/lib/views/widgets/StatefulWidget/AnimatedAlign/node1_base.dart index e448143..8f41a38 100644 --- a/lib/views/widgets/StatefulWidget/AnimatedAlign/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/AnimatedAlign/node1_base.dart @@ -24,7 +24,7 @@ class _CustomAnimatedAlignState extends State { final Alignment start = Alignment(0, 0); final Alignment end = Alignment.bottomRight; - Alignment _alignment; + late Alignment _alignment; @override void initState() { diff --git a/lib/views/widgets/StatefulWidget/AnimatedBuilder/node1_base.dart b/lib/views/widgets/StatefulWidget/AnimatedBuilder/node1_base.dart index 01ca1c7..91c387f 100644 --- a/lib/views/widgets/StatefulWidget/AnimatedBuilder/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/AnimatedBuilder/node1_base.dart @@ -24,7 +24,7 @@ class AnimatedBuilderDemo extends StatefulWidget { class _AnimatedBuilderDemoState extends State with SingleTickerProviderStateMixin { - AnimationController controller; + late AnimationController controller; @override void initState() { diff --git a/lib/views/widgets/StatefulWidget/AnimatedContainer/node1_base.dart b/lib/views/widgets/StatefulWidget/AnimatedContainer/node1_base.dart index fcc3f7b..db0ab5f 100644 --- a/lib/views/widgets/StatefulWidget/AnimatedContainer/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/AnimatedContainer/node1_base.dart @@ -56,9 +56,9 @@ class _CustomAnimatedContainerState extends State { final double startHeight = 150.0; final double endHeight = 100.0; - Decoration _decoration; - double _height; - Alignment _alignment; + late Decoration _decoration; + late double _height; + late Alignment _alignment; @override void initState() { diff --git a/lib/views/widgets/StatefulWidget/AnimatedDefaultTextStyle/node1_base.dart b/lib/views/widgets/StatefulWidget/AnimatedDefaultTextStyle/node1_base.dart index 0b6f30a..e65ad07 100644 --- a/lib/views/widgets/StatefulWidget/AnimatedDefaultTextStyle/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/AnimatedDefaultTextStyle/node1_base.dart @@ -33,7 +33,7 @@ class _CustomAnimatedDefaultTextStyleState Shadow(offset: Offset(1, 1), color: Colors.purple, blurRadius: 3) ]); - TextStyle _style; + late TextStyle _style; @override void initState() { diff --git a/lib/views/widgets/StatefulWidget/AnimatedList/node1_base.dart b/lib/views/widgets/StatefulWidget/AnimatedList/node1_base.dart index d148ddf..928d771 100644 --- a/lib/views/widgets/StatefulWidget/AnimatedList/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/AnimatedList/node1_base.dart @@ -23,9 +23,9 @@ class CustomAnimatedList extends StatefulWidget { class _CustomAnimatedListState extends State { final GlobalKey _listKey = GlobalKey(); - ListModel _list; - int _selectedItem; - int _nextItem; + late ListModel _list; + int? _selectedItem; + int _nextItem = 0; @override void initState() { @@ -63,13 +63,13 @@ class _CustomAnimatedListState extends State { void _insert() { final int index = - _selectedItem == null ? _list.length : _list.indexOf(_selectedItem); + _selectedItem == null ? _list.length : _list.indexOf(_selectedItem!); _list.insert(index, _nextItem++); } void _remove() { if (_selectedItem != null) { - _list.removeAt(_list.indexOf(_selectedItem)); + _list.removeAt(_list.indexOf(_selectedItem!)); setState(() { _selectedItem = null; }); @@ -117,27 +117,27 @@ class _CustomAnimatedListState extends State { class ListModel { ListModel({ - @required this.listKey, - @required this.removedItemBuilder, - Iterable initialItems, - }) : assert(listKey != null), - assert(removedItemBuilder != null), - _items = List.from(initialItems ?? []); + required this.listKey, + required this.removedItemBuilder, + required Iterable initialItems, + }) : assert(removedItemBuilder != null), + _items = List.from(initialItems); final GlobalKey listKey; final dynamic removedItemBuilder; final List _items; - AnimatedListState get _animatedList => listKey.currentState; + AnimatedListState? get _animatedList => listKey.currentState; void insert(int index, E item) { _items.insert(index, item); - _animatedList.insertItem(index); + _animatedList?.insertItem(index); } E removeAt(int index) { final E removedItem = _items.removeAt(index); if (removedItem != null) { - _animatedList.removeItem(index, + _animatedList?.removeItem( + index, (BuildContext context, Animation animation) => removedItemBuilder(removedItem, context, animation), ); @@ -154,17 +154,17 @@ class ListModel { class CardItem extends StatelessWidget { const CardItem( - {Key key, - @required this.animation, + {Key? key, + required this.animation, this.onTap, - @required this.item, + required this.item, this.selected: false}) : assert(animation != null), assert(item != null && item >= 0), assert(selected != null), super(key: key); final Animation animation; - final VoidCallback onTap; + final VoidCallback? onTap; final int item; final bool selected; @@ -177,13 +177,15 @@ class CardItem extends StatelessWidget { child: Container( color: Colors.primaries[item % Colors.primaries.length], child: CheckboxListTile( - dense: true, + dense: true, title: Text( 'Item $item', style: TextStyle(color: Colors.white, fontSize: 18), ), value: selected, - onChanged: (v) => onTap()), + onChanged: (v) { + onTap?.call(); + }), ), ), ); diff --git a/lib/views/widgets/StatefulWidget/AnimatedModalBarrier/node1_base.dart b/lib/views/widgets/StatefulWidget/AnimatedModalBarrier/node1_base.dart index 95ad73f..daf4666 100644 --- a/lib/views/widgets/StatefulWidget/AnimatedModalBarrier/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/AnimatedModalBarrier/node1_base.dart @@ -20,16 +20,15 @@ class AnimatedModalBarrierDemo extends StatefulWidget { class _AnimatedModalBarrierDemoState extends State with SingleTickerProviderStateMixin { - AnimationController _controller; - Animation _color; + late AnimationController _controller; + late Animation _color; @override void initState() { super.initState(); _controller = AnimationController(vsync: this, duration: Duration(seconds: 2))..forward(); - _color = ColorTween(begin: Colors.blue, end: Colors.purple) - .animate(_controller); + _color = ColorTween(begin: Colors.blue, end: Colors.purple).animate(_controller); } @override diff --git a/lib/views/widgets/StatefulWidget/AnimatedPadding/node1_base.dart b/lib/views/widgets/StatefulWidget/AnimatedPadding/node1_base.dart index f2eb951..20dce39 100644 --- a/lib/views/widgets/StatefulWidget/AnimatedPadding/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/AnimatedPadding/node1_base.dart @@ -23,7 +23,7 @@ class _CustomAnimatedPaddingState extends State { final EdgeInsets startPadding = EdgeInsets.all(10); final EdgeInsets endPadding = EdgeInsets.all(30); - EdgeInsets _padding; + late EdgeInsets _padding; @override void initState() { diff --git a/lib/views/widgets/StatefulWidget/AnimatedTheme/node1_base.dart b/lib/views/widgets/StatefulWidget/AnimatedTheme/node1_base.dart index 385a943..a176fc6 100644 --- a/lib/views/widgets/StatefulWidget/AnimatedTheme/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/AnimatedTheme/node1_base.dart @@ -35,7 +35,7 @@ class _AnimatedThemeDemoState extends State { fontSize: 16, fontWeight: FontWeight.normal))); - ThemeData them; + late ThemeData them; @override void initState() { diff --git a/lib/views/widgets/StatefulWidget/AppBar/node2_tab.dart b/lib/views/widgets/StatefulWidget/AppBar/node2_tab.dart index ac8f30e..24719d3 100755 --- a/lib/views/widgets/StatefulWidget/AppBar/node2_tab.dart +++ b/lib/views/widgets/StatefulWidget/AppBar/node2_tab.dart @@ -18,7 +18,7 @@ class TabAppBar extends StatefulWidget { class _TabAppBarState extends State with SingleTickerProviderStateMixin { final tabs = ['风画庭', '雨韵舍', '雷鸣殿', '电疾堂', '霜寒阁', '雪月楼']; - TabController _tabController; + late TabController _tabController; @override void initState() { @@ -56,7 +56,7 @@ class _TabAppBarState extends State title: Text('风雅六社'), elevation: 1, leading: BackButton(), - backgroundColor: Colors.amber[500].withAlpha(33), + backgroundColor: Colors.amber[500]!.withAlpha(33), centerTitle: true, shape: RoundedRectangleBorder( borderRadius: BorderRadius.only( diff --git a/lib/views/widgets/StatefulWidget/AutomaticKeepAlive/node1_base.dart b/lib/views/widgets/StatefulWidget/AutomaticKeepAlive/node1_base.dart index fe187be..594aed6 100644 --- a/lib/views/widgets/StatefulWidget/AutomaticKeepAlive/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/AutomaticKeepAlive/node1_base.dart @@ -17,26 +17,26 @@ import 'package:flutter/material.dart'; class AutomaticKeepAliveDemo extends StatelessWidget { final List data = [ - Colors.purple[50], - Colors.purple[100], - Colors.purple[200], - Colors.purple[300], - Colors.purple[400], - Colors.purple[500], - Colors.purple[600], - Colors.purple[700], - Colors.purple[800], - Colors.purple[900], - Colors.red[50], - Colors.red[100], - Colors.red[200], - Colors.red[300], - Colors.red[400], - Colors.red[500], - Colors.red[600], - Colors.red[700], - Colors.red[800], - Colors.red[900], + Colors.purple[50]!, + Colors.purple[100]!, + Colors.purple[200]!, + Colors.purple[300]!, + Colors.purple[400]!, + Colors.purple[500]!, + Colors.purple[600]!, + Colors.purple[700]!, + Colors.purple[800]!, + Colors.purple[900]!, + Colors.red[50]!, + Colors.red[100]!, + Colors.red[200]!, + Colors.red[300]!, + Colors.red[400]!, + Colors.red[500]!, + Colors.red[600]!, + Colors.red[700]!, + Colors.red[800]!, + Colors.red[900]!, ]; @override @@ -58,7 +58,7 @@ class ColorBox extends StatefulWidget { final Color color; final int index; - ColorBox({Key key, this.color, this.index}) : super(key: key); + ColorBox({Key? key,required this.color,required this.index}) : super(key: key); @override _ColorBoxState createState() => _ColorBoxState(); @@ -93,9 +93,9 @@ class _ColorBoxState extends State with AutomaticKeepAliveClientMixin SizedBox(width: 60,), Checkbox( value: _checked, - onChanged: (v) { + onChanged: (bool? v) { setState(() { - _checked = v; + _checked = v??false; }); }, ), diff --git a/lib/views/widgets/StatefulWidget/BottomNavigationBar/node2_page.dart b/lib/views/widgets/StatefulWidget/BottomNavigationBar/node2_page.dart index 72c3f37..c8fd7aa 100755 --- a/lib/views/widgets/StatefulWidget/BottomNavigationBar/node2_page.dart +++ b/lib/views/widgets/StatefulWidget/BottomNavigationBar/node2_page.dart @@ -31,7 +31,7 @@ class _BottomNavigationBarWithPageViewState Colors.green, Colors.purple, ]; - PageController _controller; //页面控制器,初始0 + late PageController _controller; //页面控制器,初始0 @override void initState() { diff --git a/lib/views/widgets/StatefulWidget/Checkbox/node1_base.dart b/lib/views/widgets/StatefulWidget/Checkbox/node1_base.dart index 436123b..40342d0 100644 --- a/lib/views/widgets/StatefulWidget/Checkbox/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/Checkbox/node1_base.dart @@ -33,8 +33,8 @@ class _CustomCheckboxState extends State { value: _checked, checkColor: Colors.white, activeColor: e, - onChanged: (v) => - setState(() => _checked = v))) + onChanged: (bool? value) => + setState(() => _checked = value??false))) .toList(), ); } diff --git a/lib/views/widgets/StatefulWidget/Checkbox/node2_tristate.dart b/lib/views/widgets/StatefulWidget/Checkbox/node2_tristate.dart index 81e6a21..f32ab27 100644 --- a/lib/views/widgets/StatefulWidget/Checkbox/node2_tristate.dart +++ b/lib/views/widgets/StatefulWidget/Checkbox/node2_tristate.dart @@ -33,9 +33,9 @@ class _TristateCheckBokState extends State { tristate: true, checkColor: Colors.white, activeColor: e, - onChanged: (v) { - print(v); - setState(() => _checked = v); + onChanged: (bool? value) { + print(value); + setState(() => _checked = value??false); })) .toList(), ); diff --git a/lib/views/widgets/StatefulWidget/CircularProgressIndicator/node1_base.dart b/lib/views/widgets/StatefulWidget/CircularProgressIndicator/node1_base.dart index 03b4b49..7068f72 100644 --- a/lib/views/widgets/StatefulWidget/CircularProgressIndicator/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/CircularProgressIndicator/node1_base.dart @@ -21,7 +21,7 @@ class CustomCircularProgressIndicator extends StatefulWidget { class _CustomCircularProgressIndicatorState extends State { - var data = [0.2,0.4,0.6,0.8,null]; + List data = [0.2,0.4,0.6,0.8,null]; @override Widget build(BuildContext context) { diff --git a/lib/views/widgets/StatefulWidget/CupertinoButton/node1_base.dart b/lib/views/widgets/StatefulWidget/CupertinoButton/node1_base.dart index ade5190..7f2e07d 100755 --- a/lib/views/widgets/StatefulWidget/CupertinoButton/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/CupertinoButton/node1_base.dart @@ -17,13 +17,16 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; class CustomCupertinoButton extends StatelessWidget { + + final Map data = { + CupertinoColors.activeBlue:4.0, + Colors.blue:6.0, + CupertinoColors.activeOrange:8.0, + }; + @override Widget build(BuildContext context) { - var data = { - CupertinoColors.activeBlue:4.0, - Colors.blue:6.0, - CupertinoColors.activeOrange:8.0, - }; + return Wrap( spacing: 20, children:data.keys.map((e)=> CupertinoButton( @@ -31,7 +34,7 @@ class CustomCupertinoButton extends StatelessWidget { onPressed: () => Navigator.of(context).pushNamed('AboutMePage'), color: e, pressedOpacity: 0.4, - borderRadius: BorderRadius.all(Radius.circular(data[e])), + borderRadius: BorderRadius.all(Radius.circular(data[e]!)), child: Text("iOS"), )).toList() ); diff --git a/lib/views/widgets/StatefulWidget/CupertinoScrollbar/node1_base.dart b/lib/views/widgets/StatefulWidget/CupertinoScrollbar/node1_base.dart index bc89eed..b2c5fd1 100644 --- a/lib/views/widgets/StatefulWidget/CupertinoScrollbar/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/CupertinoScrollbar/node1_base.dart @@ -13,17 +13,17 @@ import 'package:flutter/material.dart'; // "【controller】 : 控制器 【ScrollController】", // } class CustomCupertinoScrollbar extends StatelessWidget { - final data = [ - Colors.purple[50], - Colors.purple[100], - Colors.purple[200], - Colors.purple[300], - Colors.purple[400], - Colors.purple[500], - Colors.purple[600], - Colors.purple[700], - Colors.purple[800], - Colors.purple[900], + final List data = [ + Colors.purple[50]!, + Colors.purple[100]!, + Colors.purple[200]!, + Colors.purple[300]!, + Colors.purple[400]!, + Colors.purple[500]!, + Colors.purple[600]!, + Colors.purple[700]!, + Colors.purple[800]!, + Colors.purple[900]!, ]; @override diff --git a/lib/views/widgets/StatefulWidget/CupertinoSlidingSegmentedControl/node1_base.dart b/lib/views/widgets/StatefulWidget/CupertinoSlidingSegmentedControl/node1_base.dart index 24a542b..410ce82 100644 --- a/lib/views/widgets/StatefulWidget/CupertinoSlidingSegmentedControl/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/CupertinoSlidingSegmentedControl/node1_base.dart @@ -47,7 +47,8 @@ class _CupertinoSlidingSegmentedControlDemoState ); } - void _onValueChanged(int value) { + void _onValueChanged(int? value) { + if(value==null) return; setState(() { _value=value; }); diff --git a/lib/views/widgets/StatefulWidget/DecoratedBoxTransition/node1_base.dart b/lib/views/widgets/StatefulWidget/DecoratedBoxTransition/node1_base.dart index 2d98705..2087bf9 100644 --- a/lib/views/widgets/StatefulWidget/DecoratedBoxTransition/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/DecoratedBoxTransition/node1_base.dart @@ -21,7 +21,7 @@ class CustomDecoratedBoxTransition extends StatefulWidget { class _CustomDecoratedBoxTransitionState extends State with SingleTickerProviderStateMixin { - AnimationController _ctrl; + late AnimationController _ctrl; @override void initState() { diff --git a/lib/views/widgets/StatefulWidget/DefaultTabController/node1_base.dart b/lib/views/widgets/StatefulWidget/DefaultTabController/node1_base.dart index 34791a2..dc6911f 100644 --- a/lib/views/widgets/StatefulWidget/DefaultTabController/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/DefaultTabController/node1_base.dart @@ -38,7 +38,7 @@ class DefaultTabControllerDemo extends StatelessWidget { children: tabs.map((Tab tab) { return Center( child: Text( - tab.text, + '${tab.text}', style: const TextStyle(fontSize: 20), ), ); diff --git a/lib/views/widgets/StatefulWidget/DefaultTextStyleTransition/node1_base.dart b/lib/views/widgets/StatefulWidget/DefaultTextStyleTransition/node1_base.dart index 334508e..1d9260c 100644 --- a/lib/views/widgets/StatefulWidget/DefaultTextStyleTransition/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/DefaultTextStyleTransition/node1_base.dart @@ -24,7 +24,7 @@ class CustomDefaultTextStyleTransition extends StatefulWidget { class _CustomDefaultTextStyleTransitionState extends State with SingleTickerProviderStateMixin { - AnimationController _ctrl; + late AnimationController _ctrl; @override void initState() { diff --git a/lib/views/widgets/StatefulWidget/Dismissible/node1_base.dart b/lib/views/widgets/StatefulWidget/Dismissible/node1_base.dart index dda065e..18dbce6 100644 --- a/lib/views/widgets/StatefulWidget/Dismissible/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/Dismissible/node1_base.dart @@ -23,17 +23,17 @@ class CustomDismissible extends StatefulWidget { } class _CustomDismissibleState extends State { - var data = [ - Colors.purple[50], - Colors.purple[100], - Colors.purple[200], - Colors.purple[300], - Colors.purple[400], - Colors.purple[500], - Colors.purple[600], - Colors.purple[700], - Colors.purple[800], - Colors.purple[900], + final List data = [ + Colors.purple[50]!, + Colors.purple[100]!, + Colors.purple[200]!, + Colors.purple[300]!, + Colors.purple[400]!, + Colors.purple[500]!, + Colors.purple[600]!, + Colors.purple[700]!, + Colors.purple[800]!, + Colors.purple[900]!, ]; @override diff --git a/lib/views/widgets/StatefulWidget/Dismissible/node2_direction.dart b/lib/views/widgets/StatefulWidget/Dismissible/node2_direction.dart index 87f2d93..5441f28 100644 --- a/lib/views/widgets/StatefulWidget/Dismissible/node2_direction.dart +++ b/lib/views/widgets/StatefulWidget/Dismissible/node2_direction.dart @@ -20,17 +20,17 @@ class DirectionDismissible extends StatefulWidget { } class _CustomDirectionDismissibleState extends State { - var data = [ - Colors.purple[50], - Colors.purple[100], - Colors.purple[200], - Colors.purple[300], - Colors.purple[400], - Colors.purple[500], - Colors.purple[600], - Colors.purple[700], - Colors.purple[800], - Colors.purple[900], + final List data = [ + Colors.purple[50]!, + Colors.purple[100]!, + Colors.purple[200]!, + Colors.purple[300]!, + Colors.purple[400]!, + Colors.purple[500]!, + Colors.purple[600]!, + Colors.purple[700]!, + Colors.purple[800]!, + Colors.purple[900]!, ]; @override diff --git a/lib/views/widgets/StatefulWidget/DraggableScrollableSheet/node1_base.dart b/lib/views/widgets/StatefulWidget/DraggableScrollableSheet/node1_base.dart index 9d0d290..de5eea3 100644 --- a/lib/views/widgets/StatefulWidget/DraggableScrollableSheet/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/DraggableScrollableSheet/node1_base.dart @@ -36,27 +36,27 @@ class DraggableScrollableSheetDemo extends StatelessWidget { } class DraggableScrollableSheetPage extends StatelessWidget { - final data = [ - Colors.orange[50], - Colors.orange[100], - Colors.orange[200], - Colors.orange[300], - Colors.orange[400], - Colors.orange[500], - Colors.orange[600], - Colors.orange[700], - Colors.orange[800], - Colors.orange[900], - Colors.red[50], - Colors.red[100], - Colors.red[200], - Colors.red[300], - Colors.red[400], - Colors.red[500], - Colors.red[600], - Colors.red[700], - Colors.red[800], - Colors.red[900], + final List data = [ + Colors.orange[50]!, + Colors.orange[100]!, + Colors.orange[200]!, + Colors.orange[300]!, + Colors.orange[400]!, + Colors.orange[500]!, + Colors.orange[600]!, + Colors.orange[700]!, + Colors.orange[800]!, + Colors.orange[900]!, + Colors.red[50]!, + Colors.red[100]!, + Colors.red[200]!, + Colors.red[300]!, + Colors.red[400]!, + Colors.red[500]!, + Colors.red[600]!, + Colors.red[700]!, + Colors.red[800]!, + Colors.red[900]!, ]; @override diff --git a/lib/views/widgets/StatefulWidget/DropdownButton/node1_base.dart b/lib/views/widgets/StatefulWidget/DropdownButton/node1_base.dart index 6accccc..87842db 100644 --- a/lib/views/widgets/StatefulWidget/DropdownButton/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/DropdownButton/node1_base.dart @@ -45,7 +45,7 @@ class _CustomDropDownButtonState extends State { color: _color, ), items: _buildItems(), - onChanged: (v) => setState(() => _color = v)), + onChanged: (v) => setState(() => _color = v??Colors.blue)), ], ); } diff --git a/lib/views/widgets/StatefulWidget/DropdownButton/node2_style.dart b/lib/views/widgets/StatefulWidget/DropdownButton/node2_style.dart index 1689416..d5769de 100644 --- a/lib/views/widgets/StatefulWidget/DropdownButton/node2_style.dart +++ b/lib/views/widgets/StatefulWidget/DropdownButton/node2_style.dart @@ -21,8 +21,8 @@ class StyleDropDownButton extends StatefulWidget { class _StyleDropDownButtonState extends State { Color _color = Colors.red ; - final _colors = [Colors.red, Colors.yellow, Colors.blue, Colors.green]; - final _info = ["红色", "黄色", "蓝色", "绿色"]; + final List _colors = [Colors.red, Colors.yellow, Colors.blue, Colors.green]; + final List _info = ["红色", "黄色", "蓝色", "绿色"]; @override Widget build(BuildContext context) { @@ -33,16 +33,16 @@ class _StyleDropDownButtonState extends State { margin: EdgeInsets.symmetric(horizontal: 20), width: 50, height: 50, - color: _color??Colors.transparent, + color: _color, ), DropdownButton( hint: Text('请选择'), isDense: true, iconSize:20, - iconEnabledColor:_color??Colors.orange, + iconEnabledColor:_color, value: _color, items: _buildItems(), - onChanged: (v) => setState(() => _color = v)), + onChanged: (v) => setState(() => _color = v??Colors.blue)), ], ); } diff --git a/lib/views/widgets/StatefulWidget/DropdownButtonFormField/node1_base.dart b/lib/views/widgets/StatefulWidget/DropdownButtonFormField/node1_base.dart index 18b6495..595da84 100644 --- a/lib/views/widgets/StatefulWidget/DropdownButtonFormField/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/DropdownButtonFormField/node1_base.dart @@ -23,9 +23,14 @@ class DropdownButtonFormFieldDemo extends StatefulWidget { } class _DropdownButtonFormFieldDemoState extends State { - Color _color; - final _colors = [Colors.red, Colors.yellow, Colors.blue, Colors.green]; - final _info = ["红色", "黄色", "蓝色", "绿色"]; + Color _color = Colors.blue; + final List _colors = [ + Colors.red, + Colors.yellow, + Colors.blue, + Colors.green + ]; + final List _info = ["红色", "黄色", "蓝色", "绿色"]; @override Widget build(BuildContext context) { @@ -35,7 +40,7 @@ class _DropdownButtonFormFieldDemoState extends State setState(() => _color = v) - ), + onChanged: (v) => setState(() => _color = v ?? Colors.blue)), ) ], diff --git a/lib/views/widgets/StatefulWidget/ExpansionPanelList/node1_base.dart b/lib/views/widgets/StatefulWidget/ExpansionPanelList/node1_base.dart index 4ca2194..a2c6337 100644 --- a/lib/views/widgets/StatefulWidget/ExpansionPanelList/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/ExpansionPanelList/node1_base.dart @@ -20,17 +20,17 @@ class CustomExpansionPanelList extends StatefulWidget { } class _CustomExpansionPanelListState extends State { - var data = [ - Colors.red[50], - Colors.red[100], - Colors.red[200], - Colors.red[300], - Colors.red[400], - Colors.red[500], - Colors.red[600], - Colors.red[700], - Colors.red[800], - Colors.red[900], + final List data = [ + Colors.red[50]!, + Colors.red[100]!, + Colors.red[200]!, + Colors.red[300]!, + Colors.red[400]!, + Colors.red[500]!, + Colors.red[600]!, + Colors.red[700]!, + Colors.red[800]!, + Colors.red[900]!, ]; int _position = 0; diff --git a/lib/views/widgets/StatefulWidget/Form/node1_base.dart b/lib/views/widgets/StatefulWidget/Form/node1_base.dart index 4a1cfbc..dfacba8 100644 --- a/lib/views/widgets/StatefulWidget/Form/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/Form/node1_base.dart @@ -58,7 +58,7 @@ class _CustomFormState extends State { ); } - String _validateUsername(value) { + String? _validateUsername(value) { if (value.isEmpty) { return '用户名不能为空'; } @@ -80,7 +80,8 @@ class _CustomFormState extends State { } _onSubmit(){ - if (_formKey.currentState.validate()) { + if(_formKey.currentState==null) return; + if (_formKey.currentState!.validate()) { FocusScope.of(context).requestFocus(FocusNode()); Navigator.of(context).pop(); } diff --git a/lib/views/widgets/StatefulWidget/FutureBuilder/node1_base.dart b/lib/views/widgets/StatefulWidget/FutureBuilder/node1_base.dart index fc8c5f6..68f434c 100644 --- a/lib/views/widgets/StatefulWidget/FutureBuilder/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/FutureBuilder/node1_base.dart @@ -18,7 +18,7 @@ class CustomFutureBuilder extends StatefulWidget { } class _CustomFutureBuilderState extends State { - Future _future; + late Future _future; @override void initState() { @@ -34,7 +34,7 @@ class _CustomFutureBuilderState extends State { future: _future, builder: (ctx, snap) { if (snap.connectionState == ConnectionState.done) { - return Text(snap.data); + return Text('${snap.data}'); } if (snap.connectionState == ConnectionState.waiting) { return CircularProgressIndicator(); diff --git a/lib/views/widgets/StatefulWidget/GlowingOverscrollIndicator/node1_base.dart b/lib/views/widgets/StatefulWidget/GlowingOverscrollIndicator/node1_base.dart index 5fab499..b03a6ea 100644 --- a/lib/views/widgets/StatefulWidget/GlowingOverscrollIndicator/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/GlowingOverscrollIndicator/node1_base.dart @@ -18,26 +18,26 @@ import 'package:flutter/material.dart'; class GlowingOverscrollIndicatorDemo extends StatelessWidget { final List data = [ - Colors.orange[50], - Colors.orange[100], - Colors.orange[200], - Colors.orange[300], - Colors.orange[400], - Colors.orange[500], - Colors.orange[600], - Colors.orange[700], - Colors.orange[800], - Colors.orange[900], - Colors.red[50], - Colors.red[100], - Colors.red[200], - Colors.red[300], - Colors.red[400], - Colors.red[500], - Colors.red[600], - Colors.red[700], - Colors.red[800], - Colors.red[900], + Colors.orange[50]!, + Colors.orange[100]!, + Colors.orange[200]!, + Colors.orange[300]!, + Colors.orange[400]!, + Colors.orange[500]!, + Colors.orange[600]!, + Colors.orange[700]!, + Colors.orange[800]!, + Colors.orange[900]!, + Colors.red[50]!, + Colors.red[100]!, + Colors.red[200]!, + Colors.red[300]!, + Colors.red[400]!, + Colors.red[500]!, + Colors.red[600]!, + Colors.red[700]!, + Colors.red[800]!, + Colors.red[900]!, ]; @override diff --git a/lib/views/widgets/StatefulWidget/Hero/node1_base.dart b/lib/views/widgets/StatefulWidget/Hero/node1_base.dart index 8c1aeba..0cd7f58 100644 --- a/lib/views/widgets/StatefulWidget/Hero/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/Hero/node1_base.dart @@ -101,9 +101,11 @@ class Bottom2TopRouter extends PageRouteBuilder { final int duration; final Curve curve; - Bottom2TopRouter( - {this.child, this.duration = 500, this.curve = Curves.fastOutSlowIn}) - : super( + Bottom2TopRouter({ + required this.child, + this.duration = 500, + this.curve = Curves.fastOutSlowIn, + }) : super( transitionDuration: Duration(milliseconds: duration), pageBuilder: (ctx, a1, a2) { return child; diff --git a/lib/views/widgets/StatefulWidget/InteractiveViewer/node3_controller.dart b/lib/views/widgets/StatefulWidget/InteractiveViewer/node3_controller.dart index 6533789..c7a5d6b 100644 --- a/lib/views/widgets/StatefulWidget/InteractiveViewer/node3_controller.dart +++ b/lib/views/widgets/StatefulWidget/InteractiveViewer/node3_controller.dart @@ -21,14 +21,13 @@ class _InteractiveViewerDemo3State extends State with SingleTickerProviderStateMixin { final TransformationController _transformationController = TransformationController(); - Animation _animationReset; - AnimationController _controllerReset; + late Animation _animationReset; + late AnimationController _controllerReset; void _onAnimateReset() { _transformationController.value = _animationReset.value; if (!_controllerReset.isAnimating) { - _animationReset?.removeListener(_onAnimateReset); - _animationReset = null; + _animationReset.removeListener(_onAnimateReset); _controllerReset.reset(); } } @@ -45,8 +44,7 @@ class _InteractiveViewerDemo3State extends State void _animateResetStop() { _controllerReset.stop(); - _animationReset?.removeListener(_onAnimateReset); - _animationReset = null; + _animationReset.removeListener(_onAnimateReset); _controllerReset.reset(); } diff --git a/lib/views/widgets/StatefulWidget/LinearProgressIndicator/node1_base.dart b/lib/views/widgets/StatefulWidget/LinearProgressIndicator/node1_base.dart index 42cf95b..132a9f6 100644 --- a/lib/views/widgets/StatefulWidget/LinearProgressIndicator/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/LinearProgressIndicator/node1_base.dart @@ -20,7 +20,7 @@ class CustomLinearProgressIndicator extends StatefulWidget { class _CustomLinearProgressIndicatorState extends State { - var data = [0.2, 0.4, 0.6, 0.8, null]; + List data = [0.2, 0.4, 0.6, 0.8, null]; @override Widget build(BuildContext context) { diff --git a/lib/views/widgets/StatefulWidget/ListWheelScrollView/node1_base.dart b/lib/views/widgets/StatefulWidget/ListWheelScrollView/node1_base.dart index 3e4e274..81e433c 100644 --- a/lib/views/widgets/StatefulWidget/ListWheelScrollView/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/ListWheelScrollView/node1_base.dart @@ -19,17 +19,17 @@ class CustomListWheelScrollView extends StatefulWidget { } class _CustomListWheelScrollViewState extends State { - var data = [ - Colors.orange[50], - Colors.orange[100], - Colors.orange[200], - Colors.orange[300], - Colors.orange[400], - Colors.orange[500], - Colors.orange[600], - Colors.orange[700], - Colors.orange[800], - Colors.orange[900], + final List data = [ + Colors.orange[50]!, + Colors.orange[100]!, + Colors.orange[200]!, + Colors.orange[300]!, + Colors.orange[400]!, + Colors.orange[500]!, + Colors.orange[600]!, + Colors.orange[700]!, + Colors.orange[800]!, + Colors.orange[900]!, ]; Color _color = Colors.blue; diff --git a/lib/views/widgets/StatefulWidget/MergeableMaterial/node1_base.dart b/lib/views/widgets/StatefulWidget/MergeableMaterial/node1_base.dart index c4b9843..44dd5de 100644 --- a/lib/views/widgets/StatefulWidget/MergeableMaterial/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/MergeableMaterial/node1_base.dart @@ -46,16 +46,16 @@ class _MergeableMaterialDemoState extends State { } final List data = [ - Colors.orange[50], - Colors.orange[100], - Colors.orange[200], - Colors.orange[300], - Colors.orange[400], - Colors.orange[500], - Colors.orange[600], - Colors.orange[700], - Colors.orange[800], - Colors.orange[900] + Colors.orange[50]!, + Colors.orange[100]!, + Colors.orange[200]!, + Colors.orange[300]!, + Colors.orange[400]!, + Colors.orange[500]!, + Colors.orange[600]!, + Colors.orange[700]!, + Colors.orange[800]!, + Colors.orange[900]! ]; void _init(int count) { diff --git a/lib/views/widgets/StatefulWidget/Navigator/node1_base.dart b/lib/views/widgets/StatefulWidget/Navigator/node1_base.dart index 448e072..fbe547f 100644 --- a/lib/views/widgets/StatefulWidget/Navigator/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/Navigator/node1_base.dart @@ -57,7 +57,7 @@ class NavigatorDemo extends StatelessWidget { //路由监听器 class TolyNavigatorObservers extends NavigatorObserver { @override - void didPush(Route route, Route previousRoute) { + void didPush(Route route, Route? previousRoute) { print( '--didPush:--route:--${route.settings}--previousRoute:--${previousRoute?.settings}'); } @@ -68,27 +68,27 @@ class TolyNavigatorObservers extends NavigatorObserver { } @override - void didStartUserGesture(Route route, Route previousRoute) { + void didStartUserGesture(Route route, Route? previousRoute) { print( - '--didStartUserGesture:--route:--${route.settings}--previousRoute:--${previousRoute.settings}'); + '--didStartUserGesture:--route:--${route.settings}--previousRoute:--${previousRoute?.settings}'); } @override - void didReplace({Route newRoute, Route oldRoute}) { + void didReplace({Route? newRoute, Route? oldRoute}) { print( - '--didReplace:--newRoute:--${newRoute.settings}--oldRoute:--${oldRoute.settings}'); + '--didReplace:--newRoute:--${newRoute?.settings}--oldRoute:--${oldRoute?.settings}'); } @override - void didRemove(Route route, Route previousRoute) { + void didRemove(Route? route, Route? previousRoute) { print( - '--didRemove:--route:--${route.settings}--previousRoute:--${previousRoute.settings}'); + '--didRemove:--route:--${route?.settings}--previousRoute:--${previousRoute?.settings}'); } @override - void didPop(Route route, Route previousRoute) { + void didPop(Route route, Route? previousRoute) { print( - '--didPop:--route:--${route.settings}--previousRoute:--${previousRoute.settings}'); + '--didPop:--route:--${route.settings}--previousRoute:--${previousRoute?.settings}'); } } diff --git a/lib/views/widgets/StatefulWidget/Overlay/node1_base.dart b/lib/views/widgets/StatefulWidget/Overlay/node1_base.dart index 4589626..7ed1f85 100644 --- a/lib/views/widgets/StatefulWidget/Overlay/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/Overlay/node1_base.dart @@ -91,7 +91,7 @@ _buildFloating() => GestureDetector( showFloating(BuildContext context) { if (!show) { - Overlay.of(context).insert(entry); + Overlay.of(context)?.insert(entry); show = true; } } diff --git a/lib/views/widgets/StatefulWidget/PageView/node1_base.dart b/lib/views/widgets/StatefulWidget/PageView/node1_base.dart index 5927b1d..5d441db 100644 --- a/lib/views/widgets/StatefulWidget/PageView/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/PageView/node1_base.dart @@ -13,17 +13,17 @@ import 'package:flutter/material.dart'; // "【onPageChanged】 : 点击事件 【ValueChanged】", // } class CustomPageView extends StatelessWidget { - final data = [ - Colors.green[50], - Colors.green[100], - Colors.green[200], - Colors.green[300], - Colors.green[400], - Colors.green[500], - Colors.green[600], - Colors.green[700], - Colors.green[800], - Colors.green[900], + final List data = [ + Colors.green[50]!, + Colors.green[100]!, + Colors.green[200]!, + Colors.green[300]!, + Colors.green[400]!, + Colors.green[500]!, + Colors.green[600]!, + Colors.green[700]!, + Colors.green[800]!, + Colors.green[900]!, ]; @override diff --git a/lib/views/widgets/StatefulWidget/PageView/node2_direction.dart b/lib/views/widgets/StatefulWidget/PageView/node2_direction.dart index 63ccf68..ee66d31 100644 --- a/lib/views/widgets/StatefulWidget/PageView/node2_direction.dart +++ b/lib/views/widgets/StatefulWidget/PageView/node2_direction.dart @@ -13,17 +13,17 @@ import 'package:flutter/material.dart'; // "【reverse】 : 是否反向 【bool】", // } class DirectionPageView extends StatelessWidget { - final data = [ - Colors.orange[50], - Colors.orange[100], - Colors.orange[200], - Colors.orange[300], - Colors.orange[400], - Colors.orange[500], - Colors.orange[600], - Colors.orange[700], - Colors.orange[800], - Colors.orange[900], + final List data = [ + Colors.orange[50]!, + Colors.orange[100]!, + Colors.orange[200]!, + Colors.orange[300]!, + Colors.orange[400]!, + Colors.orange[500]!, + Colors.orange[600]!, + Colors.orange[700]!, + Colors.orange[800]!, + Colors.orange[900]!, ]; @override diff --git a/lib/views/widgets/StatefulWidget/PageView/node3_controller.dart b/lib/views/widgets/StatefulWidget/PageView/node3_controller.dart index e98c0ba..048171d 100644 --- a/lib/views/widgets/StatefulWidget/PageView/node3_controller.dart +++ b/lib/views/widgets/StatefulWidget/PageView/node3_controller.dart @@ -17,20 +17,20 @@ class CtrlPageView extends StatefulWidget { } class _CtrlPageViewState extends State { - final data = [ - Colors.orange[50], - Colors.orange[100], - Colors.orange[200], - Colors.orange[300], - Colors.orange[400], - Colors.orange[500], - Colors.orange[600], - Colors.orange[700], - Colors.orange[800], - Colors.orange[900], + final List data = [ + Colors.orange[50]!, + Colors.orange[100]!, + Colors.orange[200]!, + Colors.orange[300]!, + Colors.orange[400]!, + Colors.orange[500]!, + Colors.orange[600]!, + Colors.orange[700]!, + Colors.orange[800]!, + Colors.orange[900]!, ]; - PageController _controller; + late PageController _controller; @override void dispose() { diff --git a/lib/views/widgets/StatefulWidget/PaginatedDataTable/node1_base.dart b/lib/views/widgets/StatefulWidget/PaginatedDataTable/node1_base.dart index 2d56de2..591fc71 100644 --- a/lib/views/widgets/StatefulWidget/PaginatedDataTable/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/PaginatedDataTable/node1_base.dart @@ -29,7 +29,7 @@ class PaginatedDataTableDemo extends StatefulWidget { class _PaginatedDataTableDemoState extends State { int _rowsPerPage = 5; - int _sortColumnIndex; + int _sortColumnIndex = 0; bool _sortAscending = true; final DessertDataSource _dessertsDataSource = DessertDataSource(); @@ -59,9 +59,9 @@ class _PaginatedDataTableDemoState extends State { ), rowsPerPage: _rowsPerPage, availableRowsPerPage: [5, 8, 10, 15], - onRowsPerPageChanged: (int value) { + onRowsPerPageChanged: (int? value) { setState(() { - _rowsPerPage = value; + _rowsPerPage = value ?? 0; }); }, sortColumnIndex: _sortColumnIndex, @@ -175,14 +175,14 @@ class DessertDataSource extends DataTableSource { int _selectedCount = 0; @override - DataRow getRow(int index) { + DataRow? getRow(int index) { if (index >= _desserts.length) return null; final HeroInfo dessert = _desserts[index]; return DataRow.byIndex( index: index, selected: dessert.selected, - onSelectChanged: (bool value) { - if (dessert.selected != value) { + onSelectChanged: (bool? value) { + if (dessert.selected != value && value != null) { _selectedCount += value ? 1 : -1; assert(_selectedCount >= 0); dessert.selected = value; @@ -206,7 +206,8 @@ class DessertDataSource extends DataTableSource { @override int get selectedRowCount => _selectedCount; - void _selectAll(bool checked) { + void _selectAll(bool? checked) { + if (checked == null) return; for (HeroInfo dessert in _desserts) dessert.selected = checked; _selectedCount = checked ? _desserts.length : 0; notifyListeners(); diff --git a/lib/views/widgets/StatefulWidget/PositionedTransition/node1_base.dart b/lib/views/widgets/StatefulWidget/PositionedTransition/node1_base.dart index 0413296..8f78f53 100644 --- a/lib/views/widgets/StatefulWidget/PositionedTransition/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/PositionedTransition/node1_base.dart @@ -19,7 +19,7 @@ class CustomPositionedTransition extends StatefulWidget { class _CustomPositionedTransitionState extends State with SingleTickerProviderStateMixin { - AnimationController _ctrl; + late AnimationController _ctrl; @override void initState() { diff --git a/lib/views/widgets/StatefulWidget/Radio/node1_base.dart b/lib/views/widgets/StatefulWidget/Radio/node1_base.dart index f365991..9486e99 100644 --- a/lib/views/widgets/StatefulWidget/Radio/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/Radio/node1_base.dart @@ -19,7 +19,7 @@ class CustomRadio extends StatefulWidget { } class _CustomRadioState extends State { - var data = [1, 2, 3, 4, 5]; + List data = [1, 2, 3, 4, 5]; double _value = 1; @override @@ -31,7 +31,7 @@ class _CustomRadioState extends State { activeColor: Colors.orangeAccent, value: e, groupValue: _value, - onChanged: (v) => setState(() => _value = v))) + onChanged: (v) => setState(() => _value = v??0))) .toList(), ); } diff --git a/lib/views/widgets/StatefulWidget/RelativePositionedTransition/node1_base.dart b/lib/views/widgets/StatefulWidget/RelativePositionedTransition/node1_base.dart index 8792e6e..dcbd292 100644 --- a/lib/views/widgets/StatefulWidget/RelativePositionedTransition/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/RelativePositionedTransition/node1_base.dart @@ -22,11 +22,16 @@ class CustomRelativePositionedTransition extends StatefulWidget { class _CustomRelativePositionedTransitionState extends State with SingleTickerProviderStateMixin { - AnimationController _ctrl; - + late AnimationController _ctrl; + late Animation rectAnimation; @override void initState() { - _ctrl = AnimationController(vsync: this, duration: Duration(seconds: 2)); + _ctrl = AnimationController(vsync: this, duration: const Duration(seconds: 2)); + rectAnimation = RectTween( + begin: Rect.fromLTRB(0, 0, 50, 50), + end: Rect.fromLTRB(0, 0, 50, 50).translate(100, 50), + ).animate(_ctrl); + _ctrl.forward(); super.initState(); } @@ -49,10 +54,7 @@ class _CustomRelativePositionedTransitionState children: [ RelativePositionedTransition( size: Size(200, 100), - rect: RectTween( - begin: Rect.fromLTRB(0, 0, 50, 50), - end: Rect.fromLTRB(0, 0, 50, 50).translate(100, 50), - ).animate(_ctrl), + rect: rectAnimation as Animation, child: Icon( Icons.android, color: Colors.green, diff --git a/lib/views/widgets/StatefulWidget/ReorderableListView/node1_base.dart b/lib/views/widgets/StatefulWidget/ReorderableListView/node1_base.dart index 09c2bfa..1d2b32f 100644 --- a/lib/views/widgets/StatefulWidget/ReorderableListView/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/ReorderableListView/node1_base.dart @@ -19,17 +19,18 @@ class CustomReorderableListView extends StatefulWidget { } class _CustomReorderableListViewState extends State { - var data = [ - Colors.yellow[50], - Colors.yellow[100], - Colors.yellow[200], - Colors.yellow[300], - Colors.yellow[400], - Colors.yellow[500], - Colors.yellow[600], - Colors.yellow[700], - Colors.yellow[800], - Colors.yellow[900], + +final List data = [ + Colors.yellow[50]!, + Colors.yellow[100]!, + Colors.yellow[200]!, + Colors.yellow[300]!, + Colors.yellow[400]!, + Colors.yellow[500]!, + Colors.yellow[600]!, + Colors.yellow[700]!, + Colors.yellow[800]!, + Colors.yellow[900]!, ]; @override diff --git a/lib/views/widgets/StatefulWidget/ReorderableListView/node2_direction.dart b/lib/views/widgets/StatefulWidget/ReorderableListView/node2_direction.dart index a073612..14b26d4 100644 --- a/lib/views/widgets/StatefulWidget/ReorderableListView/node2_direction.dart +++ b/lib/views/widgets/StatefulWidget/ReorderableListView/node2_direction.dart @@ -18,17 +18,17 @@ class DirectionReorderableListView extends StatefulWidget { } class _DirectionReorderableListViewState extends State { - var data = [ - Colors.yellow[50], - Colors.yellow[100], - Colors.yellow[200], - Colors.yellow[300], - Colors.yellow[400], - Colors.yellow[500], - Colors.yellow[600], - Colors.yellow[700], - Colors.yellow[800], - Colors.yellow[900], + final List data = [ + Colors.yellow[50]!, + Colors.yellow[100]!, + Colors.yellow[200]!, + Colors.yellow[300]!, + Colors.yellow[400]!, + Colors.yellow[500]!, + Colors.yellow[600]!, + Colors.yellow[700]!, + Colors.yellow[800]!, + Colors.yellow[900]!, ]; @override diff --git a/lib/views/widgets/StatefulWidget/RotationTransition/node1_base.dart b/lib/views/widgets/StatefulWidget/RotationTransition/node1_base.dart index cacf18b..78afa33 100644 --- a/lib/views/widgets/StatefulWidget/RotationTransition/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/RotationTransition/node1_base.dart @@ -19,15 +19,19 @@ class CustomRotationTransition extends StatefulWidget { class _CustomRotationTransitionState extends State with SingleTickerProviderStateMixin{ - AnimationController _ctrl; + late AnimationController _ctrl; @override void initState() { - _ctrl= AnimationController(vsync: this,duration: const Duration(seconds: 2)); - _ctrl.forward(); super.initState(); + _ctrl = AnimationController( + vsync: this, + duration: const Duration(seconds: 2), + ); + _ctrl.forward(); } -@override + + @override void dispose() { _ctrl.dispose(); super.dispose(); @@ -35,7 +39,6 @@ class _CustomRotationTransitionState extends State wit @override Widget build(BuildContext context) { - return GestureDetector( onTap: () => _ctrl.forward(from: 0), child: Container( @@ -43,8 +46,15 @@ class _CustomRotationTransitionState extends State wit width: 100, height: 100, child: RotationTransition( - turns: CurvedAnimation(parent: _ctrl, curve: Curves.linear), - child: const Icon(Icons.camera_outlined,color: Colors.green,size: 60), + turns: CurvedAnimation( + parent: _ctrl, + curve: Curves.linear, + ), + child: const Icon( + Icons.camera_outlined, + color: Colors.green, + size: 60, + ), ), ), ); diff --git a/lib/views/widgets/StatefulWidget/Scaffold/node1_base.dart b/lib/views/widgets/StatefulWidget/Scaffold/node1_base.dart index d18c178..84b072e 100755 --- a/lib/views/widgets/StatefulWidget/Scaffold/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/Scaffold/node1_base.dart @@ -18,7 +18,7 @@ import '../PopupMenuButton/node1_base.dart'; // "【floatingActionButtonLocation】 : 浮动按钮位置 【FloatingActionButtonLocation】", // } class CustomScaffold extends StatefulWidget { - CustomScaffold({Key key}) : super(key: key); + CustomScaffold({Key? key}) : super(key: key); @override State createState() => _CustomScaffoldState(); @@ -43,7 +43,7 @@ class _CustomScaffoldState extends State with SingleTickerProviderStateMixin { Colors.purple, ]; - TabController _tabController; + late TabController _tabController; @override void initState() { @@ -91,7 +91,7 @@ class _CustomScaffoldState extends State with SingleTickerProviderStateMixin { ), ); - Widget _buildTabBar() => TabBar( + PreferredSizeWidget _buildTabBar() => TabBar( isScrollable: true, controller: _tabController, indicatorColor: Colors.orangeAccent, diff --git a/lib/views/widgets/StatefulWidget/ScaleTransition/node1_base.dart b/lib/views/widgets/StatefulWidget/ScaleTransition/node1_base.dart index 167ba93..d308161 100644 --- a/lib/views/widgets/StatefulWidget/ScaleTransition/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/ScaleTransition/node1_base.dart @@ -17,7 +17,7 @@ class CustomScaleTransition extends StatefulWidget { class _CustomScaleTransitionState extends State with SingleTickerProviderStateMixin { - AnimationController _ctrl; + late AnimationController _ctrl; @override void initState() { diff --git a/lib/views/widgets/StatefulWidget/Scrollbar/node1_base.dart b/lib/views/widgets/StatefulWidget/Scrollbar/node1_base.dart index af04fac..10b7cd0 100644 --- a/lib/views/widgets/StatefulWidget/Scrollbar/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/Scrollbar/node1_base.dart @@ -12,17 +12,17 @@ import 'package:flutter/material.dart'; // "【controller】 : 控制器 【ScrollController】", // } class CustomScrollbar extends StatelessWidget { - final data = [ - Colors.purple[50], - Colors.purple[100], - Colors.purple[200], - Colors.purple[300], - Colors.purple[400], - Colors.purple[500], - Colors.purple[600], - Colors.purple[700], - Colors.purple[800], - Colors.purple[900], + final List data = [ + Colors.purple[50]!, + Colors.purple[100]!, + Colors.purple[200]!, + Colors.purple[300]!, + Colors.purple[400]!, + Colors.purple[500]!, + Colors.purple[600]!, + Colors.purple[700]!, + Colors.purple[800]!, + Colors.purple[900]!, ]; @override diff --git a/lib/views/widgets/StatefulWidget/SelectableText/node2_align.dart b/lib/views/widgets/StatefulWidget/SelectableText/node2_align.dart index 41667e8..96f4d82 100644 --- a/lib/views/widgets/StatefulWidget/SelectableText/node2_align.dart +++ b/lib/views/widgets/StatefulWidget/SelectableText/node2_align.dart @@ -17,11 +17,11 @@ class AlignSelectableText extends StatefulWidget { } class _AlignSelectableTextState extends State { - final text = + final String text = "The [SelectableText] widget displays a string of text with a single style." "The string might break across multiple lines or might all be displayed on" "the same line depending on the layout constraints."; - var _textAlign = TextAlign.left; + TextAlign _textAlign = TextAlign.left; @override Widget build(BuildContext context) { @@ -64,7 +64,7 @@ class _AlignSelectableTextState extends State { .toList(), onChanged: (e) { setState(() { - _textAlign = e; + _textAlign = e??_textAlign; }); }), ], diff --git a/lib/views/widgets/StatefulWidget/SizeTransition/node1_base.dart b/lib/views/widgets/StatefulWidget/SizeTransition/node1_base.dart index 31c4d73..d0cf9c3 100644 --- a/lib/views/widgets/StatefulWidget/SizeTransition/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/SizeTransition/node1_base.dart @@ -19,7 +19,7 @@ class CustomSizeTransition extends StatefulWidget { class _CustomSizeTransitionState extends State with SingleTickerProviderStateMixin { - AnimationController _ctrl; + late AnimationController _ctrl; @override void initState() { diff --git a/lib/views/widgets/StatefulWidget/SlideTransition/node1_base.dart b/lib/views/widgets/StatefulWidget/SlideTransition/node1_base.dart index 1828987..198cbc3 100644 --- a/lib/views/widgets/StatefulWidget/SlideTransition/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/SlideTransition/node1_base.dart @@ -19,8 +19,8 @@ class CustomSlideTransition extends StatefulWidget { class _CustomSlideTransitionState extends State with SingleTickerProviderStateMixin { - AnimationController _ctrl; - Animation animation; + late AnimationController _ctrl; + late Animation animation; @override void initState() { diff --git a/lib/views/widgets/StatefulWidget/StatusTransitionWidget/node1_base.dart b/lib/views/widgets/StatefulWidget/StatusTransitionWidget/node1_base.dart index abfbd8d..d56bbff 100644 --- a/lib/views/widgets/StatefulWidget/StatusTransitionWidget/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/StatusTransitionWidget/node1_base.dart @@ -22,7 +22,7 @@ class StatusTransitionWidgetDemo extends StatefulWidget { class _StatusTransitionWidgetDemoState extends State with SingleTickerProviderStateMixin { - AnimationController _ctrl; + late AnimationController _ctrl; @override void initState() { @@ -46,7 +46,7 @@ class _StatusTransitionWidgetDemoState extends State class ColorStatusTransitionWidget extends StatusTransitionWidget { final Animation animation; - ColorStatusTransitionWidget({Key key, this.animation}) + ColorStatusTransitionWidget({Key? key,required this.animation}) : super(key: key, animation: animation); @override diff --git a/lib/views/widgets/StatefulWidget/Stepper/node1_base.dart b/lib/views/widgets/StatefulWidget/Stepper/node1_base.dart index d77d9a9..bf4e654 100644 --- a/lib/views/widgets/StatefulWidget/Stepper/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/Stepper/node1_base.dart @@ -64,7 +64,7 @@ class _StepperDemoState extends State { } }, controlsBuilder: (_, - {VoidCallback onStepContinue, VoidCallback onStepCancel}) { + {VoidCallback? onStepContinue, VoidCallback? onStepCancel}) { return Row( children: [ RaisedButton( @@ -98,7 +98,7 @@ class _StepperDemoState extends State { title: Text(e,style: TextStyle(color: isActive?Colors.blue:Colors.black),), isActive: isActive, state: _getState(stepsData.keys.toList().indexOf(e)), - content: Container(height: 60, child: Text(stepsData[e])), + content: Container(height: 60, child: Text(stepsData[e]!)), ); }).toList()), ); diff --git a/lib/views/widgets/StatefulWidget/Stepper/node2_type.dart b/lib/views/widgets/StatefulWidget/Stepper/node2_type.dart index 1269040..e55be7a 100644 --- a/lib/views/widgets/StatefulWidget/Stepper/node2_type.dart +++ b/lib/views/widgets/StatefulWidget/Stepper/node2_type.dart @@ -19,13 +19,13 @@ class VerticalStepper extends StatefulWidget { class _VerticalStepperState extends State { int _position = 0; - final stepsData = { + final Map stepsData = { "填写表单": '请按表单填写个人信息。', "邮箱校验": '已将邮件发送至您的邮箱,请按照相关指示对您的账号进行邮箱校验。', "注册完成": '恭喜您,注册完成!', }; - final steps = [ + final List steps = [ Step( title: Text("填写表单"), content: Container(height: 60, child: Text("请按表单填写个人信息")), @@ -60,7 +60,7 @@ class _VerticalStepperState extends State { } }, controlsBuilder: (_, - {VoidCallback onStepContinue, VoidCallback onStepCancel}) { + {VoidCallback? onStepContinue, VoidCallback? onStepCancel}) { return Row( children: [ RaisedButton( @@ -97,7 +97,7 @@ class _VerticalStepperState extends State { ), isActive: isActive, state: _getState(stepsData.keys.toList().indexOf(e)), - content: Container(height: 60, child: Text(stepsData[e])), + content: Container(height: 60, child: Text(stepsData[e]!)), ); }).toList()), ); diff --git a/lib/views/widgets/StatefulWidget/TabBarView/node1_base.dart b/lib/views/widgets/StatefulWidget/TabBarView/node1_base.dart index a47bbdb..09f9e15 100644 --- a/lib/views/widgets/StatefulWidget/TabBarView/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/TabBarView/node1_base.dart @@ -18,7 +18,7 @@ class CustomTabBarView extends StatefulWidget { class _CustomTabBarViewState extends State with SingleTickerProviderStateMixin { final tabs = ['风画庭', '雨韵舍', '雷鸣殿', '电疾堂', '霜寒阁', '雪月楼']; - TabController _tabController; + late TabController _tabController; @override void initState() { diff --git a/lib/views/widgets/StatefulWidget/TextField/node1_base.dart b/lib/views/widgets/StatefulWidget/TextField/node1_base.dart index ae14934..de32b11 100644 --- a/lib/views/widgets/StatefulWidget/TextField/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/TextField/node1_base.dart @@ -21,7 +21,7 @@ class CustomTextField extends StatefulWidget { class _CustomTextFieldState extends State { final FocusNode _focusNode = FocusNode(); - TextEditingController _controller; + late TextEditingController _controller; void initState() { super.initState(); diff --git a/lib/views/widgets/StatefulWidget/TextFormField/node1_base.dart b/lib/views/widgets/StatefulWidget/TextFormField/node1_base.dart index 2605f83..3f07cdc 100644 --- a/lib/views/widgets/StatefulWidget/TextFormField/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/TextFormField/node1_base.dart @@ -43,7 +43,7 @@ class _CustomTextFormFieldState extends State { ); } - String _validateUsername(value) { + String? _validateUsername(value) { if (value.isEmpty) { return '用户名不能为空'; } @@ -72,8 +72,9 @@ class _CustomTextFormFieldState extends State { } _onSubmit(){ - _formKey.currentState.save(); - if (_formKey.currentState.validate()) { + if(_formKey.currentState==null) return; + _formKey.currentState!.save(); + if (_formKey.currentState!.validate()) { FocusScope.of(context).requestFocus(FocusNode()); } } diff --git a/lib/views/widgets/StatefulWidget/TweenAnimationBuilder/node1_base.dart b/lib/views/widgets/StatefulWidget/TweenAnimationBuilder/node1_base.dart index 38f8c8b..8cc025c 100644 --- a/lib/views/widgets/StatefulWidget/TweenAnimationBuilder/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/TweenAnimationBuilder/node1_base.dart @@ -33,7 +33,7 @@ class _TweenAnimationBuilderDemoState extends State { return TweenAnimationBuilder( tween: ColorTween(begin: Colors.blue, end: _value), duration: Duration(milliseconds: 800), - builder: (BuildContext context, Color color, Widget child) { + builder: (BuildContext context, Color? color, Widget? child) { return GestureDetector( onTap: () { setState(() { diff --git a/lib/views/widgets/StatefulWidget/ValueListenableBuilder/node1_base.dart b/lib/views/widgets/StatefulWidget/ValueListenableBuilder/node1_base.dart index b60bade..edb5201 100644 --- a/lib/views/widgets/StatefulWidget/ValueListenableBuilder/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/ValueListenableBuilder/node1_base.dart @@ -13,7 +13,7 @@ import 'package:flutter/material.dart'; // } class ValueListenableBuilderDemo extends StatelessWidget { - ValueListenableBuilderDemo({Key key}) : super(key: key); + ValueListenableBuilderDemo({Key? key}) : super(key: key); final ValueNotifier _counter = ValueNotifier(0); @@ -44,12 +44,12 @@ class ValueListenableBuilderDemo extends StatelessWidget { ); } - Widget _buildWithValue(BuildContext context, int value, Widget child) { + Widget _buildWithValue(BuildContext context, int value, Widget? child) { return Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Text('$value'), - child, + child ?? const SizedBox.shrink(), ], ); } diff --git a/lib/views/widgets/StatelessWidget/AnimatedIcon/node1_base.dart b/lib/views/widgets/StatelessWidget/AnimatedIcon/node1_base.dart index db924a9..496faae 100644 --- a/lib/views/widgets/StatelessWidget/AnimatedIcon/node1_base.dart +++ b/lib/views/widgets/StatelessWidget/AnimatedIcon/node1_base.dart @@ -1,19 +1,6 @@ /// create by 张风捷特烈 on 2020/4/25 /// contact me by email 1981462002@qq.com -/// 说明: - -// { -// "widgetId": 125, -// "name": 'AnimatedIcon基本使用', -// "priority": 1, -// "subtitle": -// "【icon】 : 动画图标数据 【AnimatedIcons】\n" -// "【size】 : 大小 【double】\n" -// "【color】 : 颜色 【Color】\n" -// "【progress】 : 动画 【Animation】", -// } - - +/// 说明: import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -24,7 +11,7 @@ class CustomAnimatedIcon extends StatefulWidget { class _CustomAnimatedIconState extends State with SingleTickerProviderStateMixin { - AnimationController _ctrl; + late AnimationController _ctrl; @override void initState() { @@ -50,7 +37,7 @@ class _CustomAnimatedIconState extends State ); } - final data = { + final Map data = { Colors.orange: AnimatedIcons.menu_arrow, Colors.blue: AnimatedIcons.ellipsis_search, Colors.red: AnimatedIcons.close_menu, @@ -59,12 +46,13 @@ class _CustomAnimatedIconState extends State Colors.purple: AnimatedIcons.pause_play, }; - List _buildChildren() => data.keys - .map((e) => AnimatedIcon( - size: 50, - color: e, - icon: data[e], - progress: _ctrl, - )) + List _buildChildren() => + data.keys + .map((Color color) => AnimatedIcon( + size: 50, + color: color, + icon: data[color]!, + progress: _ctrl, + )) .toList(); } diff --git a/lib/views/widgets/StatelessWidget/Banner/node1_base.dart b/lib/views/widgets/StatelessWidget/Banner/node1_base.dart index 5fff743..7d0811b 100644 --- a/lib/views/widgets/StatelessWidget/Banner/node1_base.dart +++ b/lib/views/widgets/StatelessWidget/Banner/node1_base.dart @@ -1,41 +1,31 @@ /// create by 张风捷特烈 on 2020/4/30 /// contact me by email 1981462002@qq.com /// 说明: -// { -// "widgetId": 5, -// "priority": 1, -// "name": "用于显示一个角标", -// "subtitle": "【message】 : 显示的文字信息 【String】\n" -// "【location】 : 位置*4 【BannerLocation】\n" -// "【color】: 角标颜色 【Color】\n" -// "【child】: 孩子 【Widget】\n" -// "【textStyle】: 文字样式 【TextStyle】", -// } - import 'package:flutter/material.dart'; class CustomBanner extends StatelessWidget { + + final Map data = { + BannerLocation.topStart: Colors.red, + BannerLocation.topEnd: Colors.blue, + BannerLocation.bottomStart: Colors.green, + BannerLocation.bottomEnd: Colors.yellow, + }; + @override Widget build(BuildContext context) { - var data = { - BannerLocation.topStart: Colors.red, - BannerLocation.topEnd: Colors.blue, - BannerLocation.bottomStart: Colors.green, - BannerLocation.bottomEnd: Colors.yellow, - }; - return Wrap( spacing: 10, runSpacing: 10, - children: data.keys.map((e) => - Container( - color: Color(0xffD8F5FF), - width: 150, + children: data.keys + .map((BannerLocation location) => Container( + color: Color(0xffD8F5FF), + width: 150, height: 150 * 0.618, child: Banner( - message: "Flutter 1.12发布", - location: e, - color: data[e], + message: "Flutter 2.2.3发布", + location: location, + color: data[location]!, child: Padding( padding: EdgeInsets.all(20), child: FlutterLogo(textColor: Colors.blue, diff --git a/lib/views/widgets/StatelessWidget/BoxScrollView/node1_base.dart b/lib/views/widgets/StatelessWidget/BoxScrollView/node1_base.dart index 1170546..e0a79f7 100644 --- a/lib/views/widgets/StatelessWidget/BoxScrollView/node1_base.dart +++ b/lib/views/widgets/StatelessWidget/BoxScrollView/node1_base.dart @@ -47,16 +47,16 @@ class BoxScrollViewDemo extends StatelessWidget { class MyBoxScrollView extends BoxScrollView { final List data = [ - Colors.purple[50], - Colors.purple[100], - Colors.purple[200], - Colors.purple[300], - Colors.purple[400], - Colors.purple[500], - Colors.purple[600], - Colors.purple[700], - Colors.purple[800], - Colors.purple[900], + Colors.purple[50]!, + Colors.purple[100]!, + Colors.purple[200]!, + Colors.purple[300]!, + Colors.purple[400]!, + Colors.purple[500]!, + Colors.purple[600]!, + Colors.purple[700]!, + Colors.purple[800]!, + Colors.purple[900]!, ]; String colorString(Color color) => diff --git a/lib/views/widgets/StatelessWidget/Card/node2_shape.dart b/lib/views/widgets/StatelessWidget/Card/node2_shape.dart index 3f5f622..8e2e9c9 100644 --- a/lib/views/widgets/StatelessWidget/Card/node2_shape.dart +++ b/lib/views/widgets/StatelessWidget/Card/node2_shape.dart @@ -35,23 +35,23 @@ class ShapeCard extends StatelessWidget { class StarShapeBorder extends ShapeBorder { @override - EdgeInsetsGeometry get dimensions => null; + EdgeInsetsGeometry get dimensions => EdgeInsets.zero; @override - Path getInnerPath(Rect rect, {TextDirection textDirection}) { - return null; + Path getInnerPath(Rect rect, {TextDirection? textDirection}) { + return Path(); } @override - Path getOuterPath(Rect rect, {TextDirection textDirection}) => + Path getOuterPath(Rect rect, {TextDirection? textDirection}) => Pather.create.nStarPath(9, 50, 40, dx: 50, dy: 50); @override - void paint(Canvas canvas, Rect rect, {TextDirection textDirection}) { + void paint(Canvas canvas, Rect rect, {TextDirection? textDirection}) { } @override ShapeBorder scale(double t) { - return null; + return this; } } \ No newline at end of file diff --git a/lib/views/widgets/StatelessWidget/CupertinoTheme/node1_base.dart b/lib/views/widgets/StatelessWidget/CupertinoTheme/node1_base.dart index b63b08b..f2acd06 100644 --- a/lib/views/widgets/StatelessWidget/CupertinoTheme/node1_base.dart +++ b/lib/views/widgets/StatelessWidget/CupertinoTheme/node1_base.dart @@ -29,7 +29,7 @@ class TextCupertinoTheme extends StatelessWidget { return Container( child: Column( - children: styles.keys.map((e) => buildItem(e, styles[e])).toList(), + children: styles.keys.map((e) => buildItem(e, styles[e]!)).toList(), ), ); } diff --git a/lib/views/widgets/StatelessWidget/CupertinoTheme/node2_use.dart b/lib/views/widgets/StatelessWidget/CupertinoTheme/node2_use.dart index 31f3624..4c4dabd 100644 --- a/lib/views/widgets/StatelessWidget/CupertinoTheme/node2_use.dart +++ b/lib/views/widgets/StatelessWidget/CupertinoTheme/node2_use.dart @@ -28,7 +28,7 @@ class CustomCupertinoTheme extends StatelessWidget { class _ChildUseTheme extends StatelessWidget { const _ChildUseTheme({ - Key key, + Key? key, }) : super(key: key); @override diff --git a/lib/views/widgets/StatelessWidget/DataTable/node2_operation.dart b/lib/views/widgets/StatelessWidget/DataTable/node2_operation.dart index 29022dd..cd2380c 100644 --- a/lib/views/widgets/StatelessWidget/DataTable/node2_operation.dart +++ b/lib/views/widgets/StatelessWidget/DataTable/node2_operation.dart @@ -87,7 +87,8 @@ class _SortDataTableState extends State { }); } - _onSelectOne(bool selected, _BeanOp e) { + void _onSelectOne(bool? selected, _BeanOp e) { + if(selected==null) return; setState(() { if (selected) { //选中 @@ -100,7 +101,8 @@ class _SortDataTableState extends State { }); } - _onSelectAll(bool select) { + void _onSelectAll(bool? select) { + if(select==null) return; setState(() { if (select) { data.forEach((e) => e.select = true); diff --git a/lib/views/widgets/StatelessWidget/Divider/node2_height.dart b/lib/views/widgets/StatelessWidget/Divider/node2_height.dart index 820a669..eb541b6 100644 --- a/lib/views/widgets/StatelessWidget/Divider/node2_height.dart +++ b/lib/views/widgets/StatelessWidget/Divider/node2_height.dart @@ -16,21 +16,24 @@ import 'package:flutter/material.dart'; class HeightDivider extends StatelessWidget { + + final List dataColor = [ + Colors.red, Colors.yellow, + Colors.blue, Colors.green]; + @override Widget build(BuildContext context) { - var dataColor = [ - Colors.red, Colors.yellow, - Colors.blue, Colors.green]; + var dataThickness = [10.0, 20.0, 30.0, 40.0]; var data = Map.fromIterables(dataColor, dataThickness); return Column( children: dataColor - .map((e) => Divider( - color: e, - indent:data[e], - endIndent: data[e]*2, - height: data[e], - thickness: data[e]/10, + .map((Color color) => Divider( + color: color, + indent:data[color], + endIndent: data[color]!*2, + height: data[color], + thickness: data[color]!/10, )) .toList(), ); diff --git a/lib/views/widgets/StatelessWidget/DraggableScrollableActuator/node1_base.dart b/lib/views/widgets/StatelessWidget/DraggableScrollableActuator/node1_base.dart index 710ea96..f660d35 100644 --- a/lib/views/widgets/StatelessWidget/DraggableScrollableActuator/node1_base.dart +++ b/lib/views/widgets/StatelessWidget/DraggableScrollableActuator/node1_base.dart @@ -34,26 +34,26 @@ class DraggableScrollableActuatorDemo extends StatelessWidget { class DraggableScrollableActuatorPage extends StatelessWidget { final List data = [ - Colors.orange[50], - Colors.orange[100], - Colors.orange[200], - Colors.orange[300], - Colors.orange[400], - Colors.orange[500], - Colors.orange[600], - Colors.orange[700], - Colors.orange[800], - Colors.orange[900], - Colors.red[50], - Colors.red[100], - Colors.red[200], - Colors.red[300], - Colors.red[400], - Colors.red[500], - Colors.red[600], - Colors.red[700], - Colors.red[800], - Colors.red[900], + Colors.orange[50]!, + Colors.orange[100]!, + Colors.orange[200]!, + Colors.orange[300]!, + Colors.orange[400]!, + Colors.orange[500]!, + Colors.orange[600]!, + Colors.orange[700]!, + Colors.orange[800]!, + Colors.orange[900]!, + Colors.red[50]!, + Colors.red[100]!, + Colors.red[200]!, + Colors.red[300]!, + Colors.red[400]!, + Colors.red[500]!, + Colors.red[600]!, + Colors.red[700]!, + Colors.red[800]!, + Colors.red[900]!, ]; @override diff --git a/lib/views/widgets/StatelessWidget/FadeInImage/node1_base.dart b/lib/views/widgets/StatelessWidget/FadeInImage/node1_base.dart index 7ff1738..809abff 100644 --- a/lib/views/widgets/StatelessWidget/FadeInImage/node1_base.dart +++ b/lib/views/widgets/StatelessWidget/FadeInImage/node1_base.dart @@ -25,9 +25,9 @@ class CustomFadeInImage extends StatelessWidget { Widget build(BuildContext context) { var placeholder = "assets/images/icon_head.webp"; var img = - "https://user-gold-cdn.xitu.io/2017/8/24/" - "d324efef8cbee6468a018aad7ab2ba6b?imageView2/" - "1/w/180/h/180/q/85/format/webp/interlace/1"; + "https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/" + "15739960c2da4de3a263eeabcb60057f~tplv-k3u1fbpfcp-zoom-crop-mark" + ":1304:1304:1304:734.awebp"; return FadeInImage.assetNetwork( placeholder: placeholder, image: img, @@ -36,7 +36,7 @@ class CustomFadeInImage extends StatelessWidget { fit: BoxFit.cover, repeat:ImageRepeat.noRepeat, alignment: Alignment.center, - fadeInDuration: Duration(seconds: 5), + fadeInDuration:const Duration(seconds: 5), fadeInCurve: Curves.easeInCubic, ); } diff --git a/lib/views/widgets/StatelessWidget/FilterChip/node1_base.dart b/lib/views/widgets/StatelessWidget/FilterChip/node1_base.dart index df87142..2642330 100644 --- a/lib/views/widgets/StatelessWidget/FilterChip/node1_base.dart +++ b/lib/views/widgets/StatelessWidget/FilterChip/node1_base.dart @@ -53,12 +53,12 @@ class _CustomFilterChipState extends State { pressElevation: 5, elevation: 3, avatar: CircleAvatar(child: Text(key)), - label: Text(map[key]), + label: Text(map[key]!), selected: _selected.contains(map[key]), onSelected: (bool value) { setState(() { if (value) { - _selected.add(map[key]); + _selected.add(map[key]!); } else { _selected.removeWhere((name) => name == map[key]); } diff --git a/lib/views/widgets/StatelessWidget/FloatingActionButton/node3_shape.dart b/lib/views/widgets/StatelessWidget/FloatingActionButton/node3_shape.dart index 9b5551c..fb4a3ad 100644 --- a/lib/views/widgets/StatelessWidget/FloatingActionButton/node3_shape.dart +++ b/lib/views/widgets/StatelessWidget/FloatingActionButton/node3_shape.dart @@ -43,24 +43,24 @@ class ShapeFAB extends StatelessWidget { /// 边线形状类 class StarBorder extends ShapeBorder { @override - EdgeInsetsGeometry get dimensions => null; + EdgeInsetsGeometry get dimensions => EdgeInsets.zero; @override - Path getInnerPath(Rect rect, {TextDirection textDirection}) { - return null; + Path getInnerPath(Rect rect, {TextDirection? textDirection}) { + return Path(); } @override - Path getOuterPath(Rect rect, {TextDirection textDirection}) { + Path getOuterPath(Rect rect, {TextDirection? textDirection}) { return Pather.create.nStarPath(20, 25, 25 * cos((360 / 9 / 2) * pi / 180), dx: rect.height / 2, dy: rect.width / 2); } @override - void paint(Canvas canvas, Rect rect, {TextDirection textDirection}) {} + void paint(Canvas canvas, Rect rect, {TextDirection? textDirection}) {} @override ShapeBorder scale(double t) { - return null; + return this; } } \ No newline at end of file diff --git a/lib/views/widgets/StatelessWidget/FlutterLogo/node2_style.dart b/lib/views/widgets/StatelessWidget/FlutterLogo/node2_style.dart index 559a501..0ff28a6 100644 --- a/lib/views/widgets/StatelessWidget/FlutterLogo/node2_style.dart +++ b/lib/views/widgets/StatelessWidget/FlutterLogo/node2_style.dart @@ -12,20 +12,23 @@ import 'package:flutter/material.dart'; class FlutterLogoWithText extends StatelessWidget { + + final Map data = { + FlutterLogoStyle.horizontal:Colors.blue, + FlutterLogoStyle.markOnly:Colors.red, + FlutterLogoStyle.stacked:Colors.green, + }; + + @override Widget build(BuildContext context) { - var data = { - FlutterLogoStyle.horizontal:Colors.blue, - FlutterLogoStyle.markOnly:Colors.red, - FlutterLogoStyle.stacked:Colors.green, - }; return Wrap( spacing: 20, - children: data.keys.map((e) => FlutterLogo( + children: data.keys.map((FlutterLogoStyle style) => FlutterLogo( size: 80, - style: e, - textColor: data[e], + style: style, + textColor: data[style]!, )) .toList(), ); diff --git a/lib/views/widgets/StatelessWidget/ListView/node1_base.dart b/lib/views/widgets/StatelessWidget/ListView/node1_base.dart index 0d417a6..b4ae391 100644 --- a/lib/views/widgets/StatelessWidget/ListView/node1_base.dart +++ b/lib/views/widgets/StatelessWidget/ListView/node1_base.dart @@ -12,17 +12,17 @@ import 'package:flutter/material.dart'; // "【padding】 : 内边距 【EdgeInsetsGeometry】", // } class CustomListView extends StatelessWidget { - final data = [ - Colors.purple[50], - Colors.purple[100], - Colors.purple[200], - Colors.purple[300], - Colors.purple[400], - Colors.purple[500], - Colors.purple[600], - Colors.purple[700], - Colors.purple[800], - Colors.purple[900], + final List data = [ + Colors.purple[50]!, + Colors.purple[100]!, + Colors.purple[200]!, + Colors.purple[300]!, + Colors.purple[400]!, + Colors.purple[500]!, + Colors.purple[600]!, + Colors.purple[700]!, + Colors.purple[800]!, + Colors.purple[900]!, ]; @override diff --git a/lib/views/widgets/StatelessWidget/ListView/node2_direction.dart b/lib/views/widgets/StatelessWidget/ListView/node2_direction.dart index 7a5803a..e61591c 100644 --- a/lib/views/widgets/StatelessWidget/ListView/node2_direction.dart +++ b/lib/views/widgets/StatelessWidget/ListView/node2_direction.dart @@ -14,17 +14,17 @@ import 'package:flutter/material.dart'; // "【shrinkWrap】 : 无边界时是否包裹 【bool】", // } class HorizontalListView extends StatelessWidget { - final data = [ - Colors.purple[50], - Colors.purple[100], - Colors.purple[200], - Colors.purple[300], - Colors.purple[400], - Colors.purple[500], - Colors.purple[600], - Colors.purple[700], - Colors.purple[800], - Colors.purple[900], + final List data = [ + Colors.purple[50]!, + Colors.purple[100]!, + Colors.purple[200]!, + Colors.purple[300]!, + Colors.purple[400]!, + Colors.purple[500]!, + Colors.purple[600]!, + Colors.purple[700]!, + Colors.purple[800]!, + Colors.purple[900]!, ]; @override diff --git a/lib/views/widgets/StatelessWidget/ListView/node3_builder.dart b/lib/views/widgets/StatelessWidget/ListView/node3_builder.dart index f34be64..4ccdfba 100644 --- a/lib/views/widgets/StatelessWidget/ListView/node3_builder.dart +++ b/lib/views/widgets/StatelessWidget/ListView/node3_builder.dart @@ -13,17 +13,17 @@ import 'package:flutter/material.dart'; // "【itemBuilder】 : 条目构造器 【IndexedWidgetBuilder】", // } class BuilderListView extends StatelessWidget { - final data = [ - Colors.purple[50], - Colors.purple[100], - Colors.purple[200], - Colors.purple[300], - Colors.purple[400], - Colors.purple[500], - Colors.purple[600], - Colors.purple[700], - Colors.purple[800], - Colors.purple[900], + final List data = [ + Colors.purple[50]!, + Colors.purple[100]!, + Colors.purple[200]!, + Colors.purple[300]!, + Colors.purple[400]!, + Colors.purple[500]!, + Colors.purple[600]!, + Colors.purple[700]!, + Colors.purple[800]!, + Colors.purple[900]!, ]; @override diff --git a/lib/views/widgets/StatelessWidget/ListView/node4_separated.dart b/lib/views/widgets/StatelessWidget/ListView/node4_separated.dart index 52cd7e5..8a63bfc 100644 --- a/lib/views/widgets/StatelessWidget/ListView/node4_separated.dart +++ b/lib/views/widgets/StatelessWidget/ListView/node4_separated.dart @@ -12,19 +12,18 @@ import 'package:flutter/material.dart'; // "【separatorBuilder】 : 条目构造器 【IndexedWidgetBuilder】", // } class SeparatedListView extends StatelessWidget { - final data = [ - Colors.purple[50], - Colors.purple[100], - Colors.purple[200], - Colors.purple[300], - Colors.purple[400], - Colors.purple[500], - Colors.purple[600], - Colors.purple[700], - Colors.purple[800], - Colors.purple[900], + final List data = [ + Colors.purple[50]!, + Colors.purple[100]!, + Colors.purple[200]!, + Colors.purple[300]!, + Colors.purple[400]!, + Colors.purple[500]!, + Colors.purple[600]!, + Colors.purple[700]!, + Colors.purple[800]!, + Colors.purple[900]!, ]; - @override Widget build(BuildContext context) { return Container( diff --git a/lib/views/widgets/StatelessWidget/PageStorage/node1_base.dart b/lib/views/widgets/StatelessWidget/PageStorage/node1_base.dart index 09e4931..390978f 100644 --- a/lib/views/widgets/StatelessWidget/PageStorage/node1_base.dart +++ b/lib/views/widgets/StatelessWidget/PageStorage/node1_base.dart @@ -68,7 +68,7 @@ class _PageStorageDemoState extends State { } class CountWidget extends StatefulWidget { - CountWidget({Key key}) : super(key: key); + CountWidget({Key? key}) : super(key: key); @override _CountWidgetState createState() => _CountWidgetState(); @@ -80,7 +80,7 @@ class _CountWidgetState extends State { @override void initState() { super.initState(); - _count = PageStorage.of(context)?.readState(context) as int ?? 0; + _count = PageStorage.of(context)?.readState(context); } @override diff --git a/lib/views/widgets/StatelessWidget/RadioListTile/node1_base.dart b/lib/views/widgets/StatelessWidget/RadioListTile/node1_base.dart index 7687994..4187b89 100644 --- a/lib/views/widgets/StatelessWidget/RadioListTile/node1_base.dart +++ b/lib/views/widgets/StatelessWidget/RadioListTile/node1_base.dart @@ -45,7 +45,7 @@ class _CustomRadioListTileState extends State { ItemType.dart: ItemBean("Dart", "世界上最优雅的语言", "assets/images/dart.webp"), }; - var _type = ItemType.java; + ItemType _type = ItemType.java; @override Widget build(BuildContext context) { @@ -57,13 +57,13 @@ class _CustomRadioListTileState extends State { .map((type) => RadioListTile( value: type, groupValue: _type, - title: Text(languages[type].title), - subtitle: Text(languages[type].subTitle), + title: Text(languages[type]!.title), + subtitle: Text(languages[type]!.subTitle), selected: _type == type, secondary: CircleAvatar( - backgroundImage: AssetImage(languages[type].imgUrl), + backgroundImage: AssetImage(languages[type]!.imgUrl), ), - onChanged: (type) => setState(() => _type = type), + onChanged: (ItemType? type) => setState(() => _type = type?? _type), )) .toList()), ); diff --git a/lib/views/widgets/StatelessWidget/RadioListTile/node2_dense.dart b/lib/views/widgets/StatelessWidget/RadioListTile/node2_dense.dart index df7b743..e3c715d 100644 --- a/lib/views/widgets/StatelessWidget/RadioListTile/node2_dense.dart +++ b/lib/views/widgets/StatelessWidget/RadioListTile/node2_dense.dart @@ -33,14 +33,12 @@ class DenseRadioListTile extends StatefulWidget { class _DenseRadioListTileState extends State { final Map languages = { - ItemType.java: - ItemBean("Java", "曾经世界上最流行的语言", "assets/images/java.webp"), + ItemType.java: ItemBean("Java", "曾经世界上最流行的语言", "assets/images/java.webp"), ItemType.kotlin: - ItemBean("Kotlin", "未来世界上最流行的语言", "assets/images/kotlin.webp"), - ItemType.dart: - ItemBean("Dart", "世界上最优雅的语言", "assets/images/dart.webp"), + ItemBean("Kotlin", "未来世界上最流行的语言", "assets/images/kotlin.webp"), + ItemType.dart: ItemBean("Dart", "世界上最优雅的语言", "assets/images/dart.webp"), }; - var _type = ItemType.java; + ItemType _type = ItemType.java; @override Widget build(BuildContext context) { @@ -50,18 +48,19 @@ class _DenseRadioListTileState extends State { mainAxisSize: MainAxisSize.min, children: languages.keys .map((type) => RadioListTile( - value: type, - groupValue: _type, - title: Text(languages[type].title), - activeColor: Colors.orangeAccent, - dense: true, - subtitle: Text(languages[type].subTitle), - selected: _type == type, - secondary: CircleAvatar( - backgroundImage: AssetImage(languages[type].imgUrl), - ), - onChanged: (type) => setState(() => _type = type), - )) + value: type, + groupValue: _type, + title: Text(languages[type]!.title), + activeColor: Colors.orangeAccent, + dense: true, + subtitle: Text(languages[type]!.subTitle), + selected: _type == type, + secondary: CircleAvatar( + backgroundImage: AssetImage(languages[type]!.imgUrl), + ), + onChanged: (ItemType? type) => + setState(() => _type = type ?? _type), + )) .toList()), ); } diff --git a/lib/views/widgets/StatelessWidget/ScrollView/node1_base.dart b/lib/views/widgets/StatelessWidget/ScrollView/node1_base.dart index 09e8ed6..d03eba5 100644 --- a/lib/views/widgets/StatelessWidget/ScrollView/node1_base.dart +++ b/lib/views/widgets/StatelessWidget/ScrollView/node1_base.dart @@ -36,16 +36,16 @@ class MyScrollView extends ScrollView { 'ListView 和 GridView 在底层源码中也是使用 Sliver 家族相关组件实现的。'; final List data = [ - Colors.purple[50], - Colors.purple[100], - Colors.purple[200], - Colors.purple[300], - Colors.purple[400], - Colors.purple[500], - Colors.purple[600], - Colors.purple[700], - Colors.purple[800], - Colors.purple[900], + Colors.purple[50]!, + Colors.purple[100]!, + Colors.purple[200]!, + Colors.purple[300]!, + Colors.purple[400]!, + Colors.purple[500]!, + Colors.purple[600]!, + Colors.purple[700]!, + Colors.purple[800]!, + Colors.purple[900]!, ]; @override diff --git a/lib/views/widgets/StatelessWidget/SingleChildScrollView/node1_base.dart b/lib/views/widgets/StatelessWidget/SingleChildScrollView/node1_base.dart index d6bc4fd..e9f748b 100644 --- a/lib/views/widgets/StatelessWidget/SingleChildScrollView/node1_base.dart +++ b/lib/views/widgets/StatelessWidget/SingleChildScrollView/node1_base.dart @@ -13,17 +13,17 @@ import 'package:flutter/material.dart'; // "【padding】 : 内边距 【EdgeInsetsGeometry】", // } class CustomSingleChildScrollView extends StatelessWidget { - final data = [ - Colors.blue[50], - Colors.blue[100], - Colors.blue[200], - Colors.blue[300], - Colors.blue[400], - Colors.blue[500], - Colors.blue[600], - Colors.blue[700], - Colors.blue[800], - Colors.blue[900], + final List data = [ + Colors.blue[50]!, + Colors.blue[100]!, + Colors.blue[200]!, + Colors.blue[300]!, + Colors.blue[400]!, + Colors.blue[500]!, + Colors.blue[600]!, + Colors.blue[700]!, + Colors.blue[800]!, + Colors.blue[900]!, ]; @override diff --git a/lib/views/widgets/StatelessWidget/SingleChildScrollView/node2_direction.dart b/lib/views/widgets/StatelessWidget/SingleChildScrollView/node2_direction.dart index 77d9a0d..6c68e42 100644 --- a/lib/views/widgets/StatelessWidget/SingleChildScrollView/node2_direction.dart +++ b/lib/views/widgets/StatelessWidget/SingleChildScrollView/node2_direction.dart @@ -13,17 +13,17 @@ import 'package:flutter/material.dart'; // "【reverse】 : 是否反向 【Axis】", // } class DirectionSingleChildScrollView extends StatelessWidget { - final data = [ - Colors.blue[50], - Colors.blue[100], - Colors.blue[200], - Colors.blue[300], - Colors.blue[400], - Colors.blue[500], - Colors.blue[600], - Colors.blue[700], - Colors.blue[800], - Colors.blue[900], + final List data = [ + Colors.blue[50]!, + Colors.blue[100]!, + Colors.blue[200]!, + Colors.blue[300]!, + Colors.blue[400]!, + Colors.blue[500]!, + Colors.blue[600]!, + Colors.blue[700]!, + Colors.blue[800]!, + Colors.blue[900]!, ]; @override diff --git a/lib/views/widgets/StatelessWidget/SnackBar/node1_base.dart b/lib/views/widgets/StatelessWidget/SnackBar/node1_base.dart index 5e6a0e9..c3bb710 100644 --- a/lib/views/widgets/StatelessWidget/SnackBar/node1_base.dart +++ b/lib/views/widgets/StatelessWidget/SnackBar/node1_base.dart @@ -35,7 +35,7 @@ class _CustomSnackBarState extends State { ))); } - Widget _buildSnackBar() { + SnackBar _buildSnackBar() { return SnackBar( elevation: 3, shape: RoundedRectangleBorder( diff --git a/lib/views/widgets/StatelessWidget/TabBar/node1_base.dart b/lib/views/widgets/StatelessWidget/TabBar/node1_base.dart index f2b9cc0..2d65120 100644 --- a/lib/views/widgets/StatelessWidget/TabBar/node1_base.dart +++ b/lib/views/widgets/StatelessWidget/TabBar/node1_base.dart @@ -27,7 +27,7 @@ class CustomTabBar extends StatefulWidget { class _CustomTabBarState extends State with SingleTickerProviderStateMixin { final tabs = ['风画庭', '雨韵舍', '雷鸣殿', '电疾堂', '霜寒阁', '雪月楼']; - TabController _tabController; + late TabController _tabController; @override void initState() { diff --git a/lib/views/widgets/StatelessWidget/TabBar/node2_noShadow.dart b/lib/views/widgets/StatelessWidget/TabBar/node2_noShadow.dart index 281c3ea..e7c4058 100644 --- a/lib/views/widgets/StatelessWidget/TabBar/node2_noShadow.dart +++ b/lib/views/widgets/StatelessWidget/TabBar/node2_noShadow.dart @@ -19,7 +19,7 @@ class NoShadowTabBarDemo extends StatefulWidget { class _NSTabBarState extends State with SingleTickerProviderStateMixin { final tabs = ['风画庭', '雨韵舍', '雷鸣殿', '电疾堂', '霜寒阁', '雪月楼']; - TabController _tabController; + late TabController _tabController; @override void initState() { diff --git a/lib/views/widgets/StatelessWidget/TabPageSelector/node1_base.dart b/lib/views/widgets/StatelessWidget/TabPageSelector/node1_base.dart index dfddfcc..d176e62 100644 --- a/lib/views/widgets/StatelessWidget/TabPageSelector/node1_base.dart +++ b/lib/views/widgets/StatelessWidget/TabPageSelector/node1_base.dart @@ -22,7 +22,7 @@ class TabPageSelectorDemo extends StatefulWidget { class _TabPageSelectorDemoState extends State with SingleTickerProviderStateMixin { final tabs = ['风画庭', '雨韵舍', '雷鸣殿', '电疾堂', '霜寒阁', '雪月楼']; - TabController _tabController; + late TabController _tabController; @override void initState() { diff --git a/lib/views/widgets/StatelessWidget/Theme/node1_base.dart b/lib/views/widgets/StatelessWidget/Theme/node1_base.dart index 5ca9fe9..2e9633b 100644 --- a/lib/views/widgets/StatelessWidget/Theme/node1_base.dart +++ b/lib/views/widgets/StatelessWidget/Theme/node1_base.dart @@ -15,25 +15,25 @@ class TextThemeDemo extends StatelessWidget { Widget build(BuildContext context) { TextTheme queryData = Theme.of(context).textTheme; Map styles = { - "headline: ": queryData.headline, - "title: ": queryData.title, - "subhead: ": queryData.subhead, - "body1: ": queryData.body1, - "body2: ": queryData.body2, - "button: ": queryData.button, - "overline: ": queryData.overline, - "subtitle: ": queryData.subtitle, - "caption: ": queryData.caption, - "display1: ": queryData.display1, - "display2: ": queryData.display2, - "display3: ": queryData.display3, - "display4: ": queryData.display4, + "headline: ": queryData.headline!, + "title: ": queryData.title!, + "subhead: ": queryData.subhead!, + "body1: ": queryData.body1!, + "body2: ": queryData.body2!, + "button: ": queryData.button!, + "overline: ": queryData.overline!, + "subtitle: ": queryData.subtitle!, + "caption: ": queryData.caption!, + "display1: ": queryData.display1!, + "display2: ": queryData.display2!, + "display3: ": queryData.display3!, + "display4: ": queryData.display4!, }; return Container( child: Column( children: styles.keys - .map((String styleInfo) => buildItem(styleInfo, styles[styleInfo])) + .map((String styleInfo) => buildItem(styleInfo, styles[styleInfo]!)) .toList(), ), ); diff --git a/lib/views/widgets/StatelessWidget/VerticalDivider/node2_height.dart b/lib/views/widgets/StatelessWidget/VerticalDivider/node2_height.dart index 87c6843..c6dbe87 100644 --- a/lib/views/widgets/StatelessWidget/VerticalDivider/node2_height.dart +++ b/lib/views/widgets/StatelessWidget/VerticalDivider/node2_height.dart @@ -30,9 +30,9 @@ class HeightVerticalDivider extends StatelessWidget { .map((e) => VerticalDivider( color: e, indent:data[e], - endIndent: data[e]*2, + endIndent: data[e]!*2, width: data[e], - thickness: data[e]/10, + thickness: data[e]!/10, )) .toList(), ), diff --git a/plugins/install_plugin-2.0.1/.gitignore b/plugins/install_plugin-2.0.1/.gitignore new file mode 100644 index 0000000..8470f19 --- /dev/null +++ b/plugins/install_plugin-2.0.1/.gitignore @@ -0,0 +1,9 @@ +.DS_Store +.dart_tool/ + +.packages +.pub/ +pubspec.lock + +build/ +.idea/ diff --git a/plugins/install_plugin-2.0.1/.travis.yml b/plugins/install_plugin-2.0.1/.travis.yml new file mode 100644 index 0000000..b197bc2 --- /dev/null +++ b/plugins/install_plugin-2.0.1/.travis.yml @@ -0,0 +1,19 @@ +os: + - linux +sudo: false +addons: + apt: + # Flutter depends on /usr/lib/x86_64-linux-gnu/libstdc++.so.6 version GLIBCXX_3.4.18 + sources: + - ubuntu-toolchain-r-test # if we don't specify this, the libstdc++6 we get is the wrong version + packages: + - libstdc++6 + - fonts-droid +before_script: + - git clone https://github.com/flutter/flutter.git -b stable --depth 1 + - ./flutter/bin/flutter doctor +script: + - ./flutter/bin/flutter test +cache: + directories: + - $HOME/.pub-cache \ No newline at end of file diff --git a/plugins/install_plugin-2.0.1/CHANGELOG.md b/plugins/install_plugin-2.0.1/CHANGELOG.md new file mode 100644 index 0000000..be92820 --- /dev/null +++ b/plugins/install_plugin-2.0.1/CHANGELOG.md @@ -0,0 +1,31 @@ +## 2.0.1 + +* fix issue 15,17 + +## 2.0.0 + +* Breaking change. Migrate from the deprecated original Android Support Library to AndroidX.This shouldn't result in any functional changes, but it requires any Android apps using this plugin to also migrate if they're using the original support library. + +## 1.2.0 + +* Upgrade kotlin(1.2.71) and gradle build plugin version(3.2.1). + +## 1.1.0 + +* Remove `getPlatformVersion` function. + +## 1.0.0 + +* Add CHANGELOG and README. +* Remove unused code. +* Update plugin homepage url. + +## 0.0.2 + +* Fix the bug that Pixel Device install apk fail. +* Optimize the user experience when app asking for `Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES` permission for Android device above ANDROID.O. + +## 0.0.1 + +* Add `installApk` function for android to install apk, supporting ANDROID.O. +* Add `gotoAppStore` function for iOS to launch a url to App Store. \ No newline at end of file diff --git a/plugins/install_plugin-2.0.1/LICENSE b/plugins/install_plugin-2.0.1/LICENSE new file mode 100644 index 0000000..a67f704 --- /dev/null +++ b/plugins/install_plugin-2.0.1/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) [year] [akindone] + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/plugins/install_plugin-2.0.1/README.md b/plugins/install_plugin-2.0.1/README.md new file mode 100644 index 0000000..933f4fb --- /dev/null +++ b/plugins/install_plugin-2.0.1/README.md @@ -0,0 +1,120 @@ +# install_plugin + +[![Build Status](https://travis-ci.org/hui-z/flutter_install_plugin.svg?branch=master)](https://travis-ci.org/hui-z/flutter_install_plugin#) +[![pub package](https://img.shields.io/pub/v/install_plugin.svg)](https://pub.dartlang.org/packages/install_plugin) +[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/hui-z/flutter_install_plugin/blob/master/LICENSE) + + +A flutter plugin for install apk for android; and using url to go to app store for iOS. + +## Usage + +To use this plugin, add `install_plugin` as a dependency in your pubspec.yaml file. + +```dart + /// for Android : install apk by its file absolute path; + /// if the target platform is higher than android 24: + /// a [appId] is required + /// (the caller's applicationId which is defined in build.gradle) + static Future installApk(String filePath, String appId) async { + Map params = {'filePath': filePath, 'appId': appId}; + return await _channel.invokeMethod('installApk', params); + } + + /// for iOS: go to app store by the url + static Future gotoAppStore(String urlString) async { + Map params = {'urlString': urlString}; + return await _channel.invokeMethod('gotoAppStore', params); + } +``` + +### Example + +For Android, you may need to request permission for READ_EXTERNAL_STORAGE to read the apk file. In the example, I used the `permission_handler` [plugin](https://pub.dartlang.org/packages/permission_handler). + +```dart +import 'dart:async'; + +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:install_plugin/install_plugin.dart'; +import 'package:permission_handler/permission_handler.dart'; + +void main() => runApp(new MyApp()); + +class MyApp extends StatefulWidget { + @override + _MyAppState createState() => new _MyAppState(); +} + +class _MyAppState extends State { + String _appUrl = ''; + String _apkFilePath = ''; + + @override + Widget build(BuildContext context) { + return new MaterialApp( + home: new Scaffold( + appBar: new AppBar( + title: const Text('Plugin example app'), + ), + body: new Column( + children: [ + TextField( + decoration: InputDecoration( + hintText: + 'apk file path to install. Like /storage/emulated/0/demo/update.apk'), + onChanged: (path) => _apkFilePath = path, + ), + FlatButton( + onPressed: () { + onClickInstallApk(); + }, + child: Text('install')), + TextField( + decoration: + InputDecoration(hintText: 'URL for app store to launch'), + onChanged: (url) => _appUrl = url, + ), + FlatButton( + onPressed: () => onClickGotoAppStore(_appUrl), + child: Text('gotoAppStore')) + ], + ), + ), + ); + } + + void onClickInstallApk() async { + if (_apkFilePath.isEmpty) { + print('make sure the apk file is set'); + return; + } + Map permissions = + await PermissionHandler().requestPermissions([PermissionGroup.storage]); + if (permissions[PermissionGroup.storage] == PermissionStatus.granted) { + InstallPlugin.installApk(_apkFilePath, 'com.zaihui.installpluginexample') + .then((result) { + print('install apk $result'); + }).catchError((error) { + print('install apk error: $error'); + }); + } else { + print('Permission request fail!'); + } + } + + void onClickGotoAppStore(String url) { + url = url.isEmpty + ? 'https://itunes.apple.com/cn/app/%E5%86%8D%E6%83%A0%E5%90%88%E4%BC%99%E4%BA%BA/id1375433239?l=zh&ls=1&mt=8' + : url; + InstallPlugin.gotoAppStore(url); + } +} + +``` + +For help getting started with Flutter, view our online +[documentation](https://flutter.io/). + +For help on editing plugin code, view the [documentation](https://flutter.io/developing-packages/#edit-plugin-package). diff --git a/plugins/install_plugin-2.0.1/analysis_options.yaml b/plugins/install_plugin-2.0.1/analysis_options.yaml new file mode 100644 index 0000000..d140be8 --- /dev/null +++ b/plugins/install_plugin-2.0.1/analysis_options.yaml @@ -0,0 +1,11 @@ +# https://www.dartlang.org/guides/language/analysis-options +# Source of linter options: +# http://dart-lang.github.io/linter/lints/options/options.html +linter: + rules: + - camel_case_types + - hash_and_equals + - iterable_contains_unrelated_type + - list_remove_unrelated_type + - unrelated_type_equality_checks + - valid_regexps \ No newline at end of file diff --git a/plugins/install_plugin-2.0.1/android/.gitignore b/plugins/install_plugin-2.0.1/android/.gitignore new file mode 100644 index 0000000..c6cbe56 --- /dev/null +++ b/plugins/install_plugin-2.0.1/android/.gitignore @@ -0,0 +1,8 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures diff --git a/plugins/install_plugin-2.0.1/android/build.gradle b/plugins/install_plugin-2.0.1/android/build.gradle new file mode 100644 index 0000000..1432285 --- /dev/null +++ b/plugins/install_plugin-2.0.1/android/build.gradle @@ -0,0 +1,46 @@ + +group 'com.example.installplugin' +version '1.0-SNAPSHOT' + +buildscript { + ext.kotlin_version = '1.3.20' + repositories { + google() + jcenter() + } + + dependencies { + classpath 'com.android.tools.build:gradle:3.3.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +rootProject.allprojects { + repositories { + google() + jcenter() + } +} + +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' + +android { + compileSdkVersion 28 + + sourceSets { + main.java.srcDirs += 'src/main/kotlin' + } + defaultConfig { + minSdkVersion 16 + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + lintOptions { + disable 'InvalidPackage' + } +} + +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation "androidx.legacy:legacy-support-v4:1.0.0" +} diff --git a/plugins/install_plugin-2.0.1/android/gradle.properties b/plugins/install_plugin-2.0.1/android/gradle.properties new file mode 100644 index 0000000..08f2b5f --- /dev/null +++ b/plugins/install_plugin-2.0.1/android/gradle.properties @@ -0,0 +1,3 @@ +org.gradle.jvmargs=-Xmx1536M +android.enableJetifier=true +android.useAndroidX=true diff --git a/plugins/install_plugin-2.0.1/android/settings.gradle b/plugins/install_plugin-2.0.1/android/settings.gradle new file mode 100644 index 0000000..55ffb46 --- /dev/null +++ b/plugins/install_plugin-2.0.1/android/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'install_plugin' diff --git a/plugins/install_plugin-2.0.1/android/src/main/AndroidManifest.xml b/plugins/install_plugin-2.0.1/android/src/main/AndroidManifest.xml new file mode 100644 index 0000000..4d1c8ce --- /dev/null +++ b/plugins/install_plugin-2.0.1/android/src/main/AndroidManifest.xml @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/plugins/install_plugin-2.0.1/android/src/main/kotlin/com/zaihui/installplugin/InstallPlugin.kt b/plugins/install_plugin-2.0.1/android/src/main/kotlin/com/zaihui/installplugin/InstallPlugin.kt new file mode 100644 index 0000000..44f3d75 --- /dev/null +++ b/plugins/install_plugin-2.0.1/android/src/main/kotlin/com/zaihui/installplugin/InstallPlugin.kt @@ -0,0 +1,134 @@ +package com.zaihui.installplugin + +import android.app.Activity +import android.content.Context +import android.content.Intent +import android.net.Uri +import android.os.Build +import android.provider.Settings +import android.util.Log +import androidx.core.content.FileProvider +import io.flutter.plugin.common.MethodCall +import io.flutter.plugin.common.MethodChannel +import io.flutter.plugin.common.MethodChannel.MethodCallHandler +import io.flutter.plugin.common.MethodChannel.Result +import io.flutter.plugin.common.PluginRegistry.Registrar +import java.io.File +import java.io.FileNotFoundException + +/** + * 1 获取Registrar 这个接口可以获取 context + * 2 添加自身所需依赖 + * @property registrar Registrar + * @constructor + */ +class InstallPlugin(private val registrar: Registrar) : MethodCallHandler { + private var apkFile: File? = null + private var appId: String? = null + + companion object { + private const val installRequestCode = 1234 + + @JvmStatic + fun registerWith(registrar: Registrar): Unit { + val channel = MethodChannel(registrar.messenger(), "install_plugin") + val installPlugin = InstallPlugin(registrar) + channel.setMethodCallHandler(installPlugin) + registrar.addActivityResultListener { requestCode, resultCode, intent -> + Log.d( + "ActivityResultListener", + "requestCode=$requestCode, resultCode = $resultCode, intent = $intent" + ) + if (resultCode == Activity.RESULT_OK && requestCode == installRequestCode) { + installPlugin.install24(registrar.context(), installPlugin.apkFile, installPlugin.appId) + true + } else + + false + } + } + } + + override fun onMethodCall(call: MethodCall, result: Result) { + when (call.method) { + "getPlatformVersion" -> { + result.success("Android ${android.os.Build.VERSION.RELEASE}") + } + "installApk" -> { + val filePath = call.argument("filePath") + val appId = call.argument("appId") + Log.d("android plugin", "installApk $filePath $appId") + try { + installApk(filePath, appId) + result.success("Success") + } catch (e: Throwable) { + result.error(e.javaClass.simpleName, e.message, null) + } + } + else -> result.notImplemented() + } + } + + private fun installApk(filePath: String?, appId: String?) { + if (filePath == null) throw NullPointerException("fillPath is null!") + val activity: Activity = + registrar.activity() ?: throw NullPointerException("context is null!") + + val file = File(filePath) + if (!file.exists()) throw FileNotFoundException("$filePath is not exist! or check permission") + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + if (canRequestPackageInstalls(activity)) install24(activity, file, appId) + else { + showSettingPackageInstall(activity) + this.apkFile = file + this.appId = appId + } + } else { + installBelow24(activity, file) + } + } + + + private fun showSettingPackageInstall(activity: Activity) { // todo to test with android 26 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + Log.d("SettingPackageInstall", ">= Build.VERSION_CODES.O") + val intent = Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES) + intent.data = Uri.parse("package:" + activity.packageName) + activity.startActivityForResult(intent, installRequestCode) + } else { + throw RuntimeException("VERSION.SDK_INT < O") + } + + } + + private fun canRequestPackageInstalls(activity: Activity): Boolean { + return Build.VERSION.SDK_INT <= Build.VERSION_CODES.O || activity.packageManager.canRequestPackageInstalls() + } + + private fun installBelow24(context: Context, file: File?) { + val intent = Intent(Intent.ACTION_VIEW) + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + val uri = Uri.fromFile(file) + intent.setDataAndType(uri, "application/vnd.android.package-archive") + context.startActivity(intent) + } + + /** + * android24及以上安装需要通过 ContentProvider 获取文件Uri, + * 需在应用中的AndroidManifest.xml 文件添加 provider 标签, + * 并新增文件路径配置文件 res/xml/provider_path.xml + * 在android 6.0 以上如果没有动态申请文件读写权限,会导致文件读取失败,你将会收到一个异常。 + * 插件中不封装申请权限逻辑,是为了使模块功能单一,调用者可以引入独立的权限申请插件 + */ + private fun install24(context: Context?, file: File?, appId: String?) { + if (context == null) throw NullPointerException("context is null!") + if (file == null) throw NullPointerException("file is null!") + if (appId == null) throw NullPointerException("appId is null!") + val intent = Intent(Intent.ACTION_VIEW) + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + val uri: Uri = FileProvider.getUriForFile(context, "$appId.fileProvider.install", file) + intent.setDataAndType(uri, "application/vnd.android.package-archive") + context.startActivity(intent) + } +} diff --git a/plugins/install_plugin-2.0.1/android/src/main/res/xml/provider_install_paths.xml b/plugins/install_plugin-2.0.1/android/src/main/res/xml/provider_install_paths.xml new file mode 100644 index 0000000..3829895 --- /dev/null +++ b/plugins/install_plugin-2.0.1/android/src/main/res/xml/provider_install_paths.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/plugins/install_plugin-2.0.1/ios/.gitignore b/plugins/install_plugin-2.0.1/ios/.gitignore new file mode 100644 index 0000000..710ec6c --- /dev/null +++ b/plugins/install_plugin-2.0.1/ios/.gitignore @@ -0,0 +1,36 @@ +.idea/ +.vagrant/ +.sconsign.dblite +.svn/ + +.DS_Store +*.swp +profile + +DerivedData/ +build/ +GeneratedPluginRegistrant.h +GeneratedPluginRegistrant.m + +.generated/ + +*.pbxuser +*.mode1v3 +*.mode2v3 +*.perspectivev3 + +!default.pbxuser +!default.mode1v3 +!default.mode2v3 +!default.perspectivev3 + +xcuserdata + +*.moved-aside + +*.pyc +*sync/ +Icon? +.tags* + +/Flutter/Generated.xcconfig diff --git a/plugins/install_plugin-2.0.1/ios/Assets/.gitkeep b/plugins/install_plugin-2.0.1/ios/Assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/plugins/install_plugin-2.0.1/ios/Classes/InstallPlugin.h b/plugins/install_plugin-2.0.1/ios/Classes/InstallPlugin.h new file mode 100644 index 0000000..74b2618 --- /dev/null +++ b/plugins/install_plugin-2.0.1/ios/Classes/InstallPlugin.h @@ -0,0 +1,4 @@ +#import + +@interface InstallPlugin : NSObject +@end diff --git a/plugins/install_plugin-2.0.1/ios/Classes/InstallPlugin.m b/plugins/install_plugin-2.0.1/ios/Classes/InstallPlugin.m new file mode 100644 index 0000000..5ba24b0 --- /dev/null +++ b/plugins/install_plugin-2.0.1/ios/Classes/InstallPlugin.m @@ -0,0 +1,8 @@ +#import "InstallPlugin.h" +#import + +@implementation InstallPlugin ++ (void)registerWithRegistrar:(NSObject*)registrar { + [SwiftInstallPlugin registerWithRegistrar:registrar]; +} +@end diff --git a/plugins/install_plugin-2.0.1/ios/Classes/SwiftInstallPlugin.swift b/plugins/install_plugin-2.0.1/ios/Classes/SwiftInstallPlugin.swift new file mode 100644 index 0000000..62eac36 --- /dev/null +++ b/plugins/install_plugin-2.0.1/ios/Classes/SwiftInstallPlugin.swift @@ -0,0 +1,36 @@ +import Flutter +import UIKit + +public class SwiftInstallPlugin: NSObject, FlutterPlugin { + public static func register(with registrar: FlutterPluginRegistrar) { + let channel = FlutterMethodChannel(name: "install_plugin", binaryMessenger: registrar.messenger()) + let instance = SwiftInstallPlugin() + registrar.addMethodCallDelegate(instance, channel: channel) + } + + public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { + switch call.method { + case "gotoAppStore": + print(call.arguments ?? "null") + guard let urlString = (call.arguments as? Dictionary)?["urlString"] as? String else { + result(FlutterError(code: "参数url不能为空", message: nil, details: nil)) + return + } + gotoAppStore(urlString: urlString) + default: + result(FlutterMethodNotImplemented) + } + } + + //跳转到应用的AppStore页页面 + func gotoAppStore(urlString: String) { + if let url = URL(string: urlString) { + //根据iOS系统版本,分别处理 + if #available(iOS 10, *) { + UIApplication.shared.open(url, options: [:],completionHandler: {(success) in }) + } else { + UIApplication.shared.openURL(url) + } + } + } +} diff --git a/plugins/install_plugin-2.0.1/ios/install_plugin.podspec b/plugins/install_plugin-2.0.1/ios/install_plugin.podspec new file mode 100644 index 0000000..b5780bd --- /dev/null +++ b/plugins/install_plugin-2.0.1/ios/install_plugin.podspec @@ -0,0 +1,21 @@ +# +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html +# +Pod::Spec.new do |s| + s.name = 'install_plugin' + s.version = '0.0.1' + s.summary = 'A new flutter plugin project.' + s.description = <<-DESC +A new flutter plugin project. + DESC + s.homepage = 'http://example.com' + s.license = { :file => '../LICENSE' } + s.author = { 'Your Company' => 'email@example.com' } + s.source = { :path => '.' } + s.source_files = 'Classes/**/*' + s.public_header_files = 'Classes/**/*.h' + s.dependency 'Flutter' + + s.ios.deployment_target = '8.0' +end + diff --git a/plugins/install_plugin-2.0.1/lib/install_plugin.dart b/plugins/install_plugin-2.0.1/lib/install_plugin.dart new file mode 100644 index 0000000..90198f8 --- /dev/null +++ b/plugins/install_plugin-2.0.1/lib/install_plugin.dart @@ -0,0 +1,22 @@ +import 'dart:async'; + +import 'package:flutter/services.dart'; + +class InstallPlugin { + static const MethodChannel _channel = const MethodChannel('install_plugin'); + + /// for Android : install apk by its file absolute path; + /// if the target platform is higher than android 24: + /// a [appId] is required + /// (the caller's applicationId which is defined in build.gradle) + static Future installApk(String filePath, String appId) async { + Map params = {'filePath': filePath, 'appId': appId}; + return await _channel.invokeMethod('installApk', params); + } + + /// for iOS: go to app store by the url + static Future gotoAppStore(String urlString) async { + Map params = {'urlString': urlString}; + return await _channel.invokeMethod('gotoAppStore', params); + } +} diff --git a/plugins/install_plugin-2.0.1/pubspec.yaml b/plugins/install_plugin-2.0.1/pubspec.yaml new file mode 100644 index 0000000..62e9b2a --- /dev/null +++ b/plugins/install_plugin-2.0.1/pubspec.yaml @@ -0,0 +1,24 @@ +name: install_plugin +description: A flutter plugin for install apk for android; and using url to go to app store for iOS. +version: 2.0.1 +author: akindone +homepage: https://github.com/hui-z/flutter_install_plugin + +environment: + sdk: ">=2.12.0 <3.0.0" + +dependencies: + flutter: + sdk: flutter +# For information on the generic Dart part of this file, see the +# following page: https://www.dartlang.org/tools/pub/pubspec + +# The following section is specific to Flutter. +flutter: + plugin: + androidPackage: com.zaihui.installplugin + pluginClass: InstallPlugin + +dev_dependencies: + flutter_test: + sdk: flutter diff --git a/plugins/install_plugin-2.0.1/test/install_plugin_test.dart b/plugins/install_plugin-2.0.1/test/install_plugin_test.dart new file mode 100644 index 0000000..5e77789 --- /dev/null +++ b/plugins/install_plugin-2.0.1/test/install_plugin_test.dart @@ -0,0 +1,45 @@ +// import 'package:flutter/services.dart'; +// import 'package:flutter_test/flutter_test.dart'; +// import 'package:install_plugin/install_plugin.dart'; +// +// void main() { +// const MethodChannel channel = MethodChannel('install_plugin'); +// final List log = []; +// String response; +// +// channel.setMockMethodCallHandler((MethodCall methodCall) async { +// log.add(methodCall); +// return response; +// }); +// +// tearDown(() { +// log.clear(); +// }); +// +// +// test('installApk test', () async { +// response = 'Success'; +// final fakePath = 'fake.apk'; +// final fakeAppId = 'com.example.install'; +// final String result = await InstallPlugin.installApk(fakePath, fakeAppId); +// expect( +// log, +// [isMethodCall('installApk', arguments: {'filePath': fakePath, 'appId': fakeAppId})], +// ); +// expect(result, response); +// }); +// +// test('gotoAppStore test', () async { +// response = null; +// final fakeUrl = 'fake_url'; +// final String result = await InstallPlugin.gotoAppStore(fakeUrl); +// expect( +// log, +// [ +// isMethodCall('gotoAppStore', arguments: {'urlString': fakeUrl}) +// ], +// ); +// expect(result, isNull); +// }); +// +// } \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index 4a26443..8e5884a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -70,14 +70,14 @@ packages: name: dio url: "https://pub.flutter-io.cn" source: hosted - version: "3.0.10" + version: "4.0.0" equatable: dependency: "direct main" description: name: equatable url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.0" + version: "2.0.3" fake_async: dependency: transitive description: @@ -110,14 +110,14 @@ packages: name: flutter_bloc url: "https://pub.flutter-io.cn" source: hosted - version: "7.0.0" + version: "7.1.0" flutter_markdown: dependency: "direct main" description: name: flutter_markdown url: "https://pub.flutter-io.cn" source: hosted - version: "0.6.1" + version: "0.6.4" flutter_spinkit: dependency: "direct main" description: @@ -131,7 +131,7 @@ packages: name: flutter_star url: "https://pub.flutter-io.cn" source: hosted - version: "0.1.2" + version: "1.0.2" flutter_test: dependency: "direct dev" description: flutter @@ -148,13 +148,13 @@ packages: name: http_parser url: "https://pub.flutter-io.cn" source: hosted - version: "3.1.4" + version: "4.0.0" install_plugin: dependency: "direct main" description: - name: install_plugin - url: "https://pub.flutter-io.cn" - source: hosted + path: "plugins/install_plugin-2.0.1" + relative: true + source: path version: "2.0.1" intl: dependency: "direct main" @@ -232,7 +232,7 @@ packages: name: path_provider url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.1" + version: "2.0.2" path_provider_linux: dependency: transitive description: @@ -295,14 +295,14 @@ packages: name: share url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.1" + version: "2.0.4" shared_preferences: dependency: "direct main" description: name: shared_preferences url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.5" + version: "2.0.6" shared_preferences_linux: dependency: transitive description: @@ -412,7 +412,7 @@ packages: name: toggle_rotate url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.5" + version: "1.0.1" typed_data: dependency: transitive description: @@ -426,7 +426,7 @@ packages: name: url_launcher url: "https://pub.flutter-io.cn" source: hosted - version: "6.0.3" + version: "6.0.9" url_launcher_linux: dependency: transitive description: @@ -447,7 +447,7 @@ packages: name: url_launcher_platform_interface url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.2" + version: "2.0.4" url_launcher_web: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 6e42aa6..879a7e1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,35 +1,36 @@ name: flutter_unit description: A new Flutter application. -version: 1.5.3 +version: 1.6.0 author: 张风捷特烈 <1981462002@qq.com> homepage: https://juejin.cn/user/149189281194766/posts environment: - sdk: ">=2.7.0 <3.0.0" + sdk: ">=2.12.0 <3.0.0" dependencies: flutter: sdk: flutter cupertino_icons: ^1.0.2 - flutter_bloc: ^7.0.0 # 状态管理 - equatable: ^2.0.0 # 相等辅助 + flutter_bloc: ^7.1.0 # 状态管理 + equatable: ^2.0.3 # 相等辅助 package_info: ^2.0.2 # 应用包信息 sqflite: ^2.0.0+3 # 数据库 - shared_preferences: ^2.0.5 # xml 固化 + shared_preferences: ^2.0.6 # xml 固化 jwt_decoder: ^2.0.1 # jwt 解析 - toggle_rotate: ^0.0.5 - install_plugin: ^2.0.1 - flutter_star: ^0.1.2 # 星星组件 - url_launcher: ^6.0.3 # url - share: ^2.0.1 # 文字分享 + toggle_rotate: ^1.0.1 + install_plugin: + path: ./plugins/install_plugin-2.0.1 + flutter_star: ^1.0.2 # 星星组件 + url_launcher: ^6.0.9 # url + share: ^2.0.4 # 文字分享 intl: ^0.17.0 - path_provider: ^2.0.1 # 路径 + path_provider: ^2.0.2 # 路径 # connectivity: ^3.0.3 #网络状态 flutter_spinkit: ^5.0.0 # loading - flutter_markdown: ^0.6.1 # markdown - dio: ^3.0.10 # 网络请求 + flutter_markdown: ^0.6.4 # markdown + dio: ^4.0.0 # 网络请求 dev_dependencies: flutter_test: