From 09de3c61f7b77a985621132901a84519b848276f Mon Sep 17 00:00:00 2001 From: SUMIT KUMAR Date: Wed, 22 Sep 2021 19:06:00 +0530 Subject: [PATCH] moved to null safety --- .../ios/Flutter/flutter_export_environment.sh | 11 +++-- lib/src/icon_toggle.dart | 49 ++++++++++--------- pubspec.yaml | 3 +- 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh index e5b6c73..f20ff2d 100644 --- a/example/ios/Flutter/flutter_export_environment.sh +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -1,10 +1,13 @@ #!/bin/sh # This is a generated file; do not edit or check into version control. -export "FLUTTER_ROOT=D:\develop\flutter" -export "FLUTTER_APPLICATION_PATH=D:\Code\flutter-icons\example" +export "FLUTTER_ROOT=C:\flutter" +export "FLUTTER_APPLICATION_PATH=D:\flutter\lib\flutter-icons\example" +export "COCOAPODS_PARALLEL_CODE_SIGN=true" export "FLUTTER_TARGET=lib\main.dart" export "FLUTTER_BUILD_DIR=build" -export "SYMROOT=${SOURCE_ROOT}/../build\ios" -export "FLUTTER_FRAMEWORK_DIR=D:\develop\flutter\bin\cache\artifacts\engine\ios" export "FLUTTER_BUILD_NAME=1.0.0" export "FLUTTER_BUILD_NUMBER=1" +export "DART_OBFUSCATION=false" +export "TRACK_WIDGET_CREATION=false" +export "TREE_SHAKE_ICONS=false" +export "PACKAGE_CONFIG=.packages" diff --git a/lib/src/icon_toggle.dart b/lib/src/icon_toggle.dart index f051102..e89f5d5 100644 --- a/lib/src/icon_toggle.dart +++ b/lib/src/icon_toggle.dart @@ -1,4 +1,3 @@ - import 'package:flutter/material.dart'; import 'dart:math' as math; @@ -18,14 +17,14 @@ class IconToggle extends StatefulWidget { this.onChanged, this.transitionBuilder = _defaultTransitionBuilder, this.duration = const Duration(milliseconds: 100), - this.reverseDuration, + required this.reverseDuration, }); final IconData selectedIconData; final IconData unselectedIconData; final Color activeColor; final Color inactiveColor; final bool value; - final ValueChanged onChanged; + final ValueChanged? onChanged; final AnimatedSwitcherTransitionBuilder transitionBuilder; final Duration duration; final Duration reverseDuration; @@ -35,30 +34,31 @@ class IconToggle extends StatefulWidget { class _IconToggleState extends State with SingleTickerProviderStateMixin { - AnimationController _controller; - Animation _position; + late final AnimationController _controller; + late final Animation _position; bool _cancel = false; @override void initState() { super.initState(); _controller = AnimationController( - vsync: this, - duration: Duration(milliseconds: 100), - reverseDuration: Duration(milliseconds: 50)); + vsync: this, + duration: Duration(milliseconds: 100), + reverseDuration: Duration(milliseconds: 50), + ); _position = CurvedAnimation(parent: _controller, curve: Curves.linear); _position.addStatusListener((status) { if (status == AnimationStatus.dismissed && widget.onChanged != null && _cancel == false) { - widget.onChanged(!widget.value); + widget.onChanged!(!widget.value); } }); } @override void dispose() { - _controller?.dispose(); + _controller.dispose(); super.dispose(); } @@ -68,14 +68,14 @@ class _IconToggleState extends State behavior: HitTestBehavior.opaque, onTapDown: (event) { _cancel = false; - _controller?.forward(); + _controller.forward(); }, onTapUp: (event) { - _controller?.reverse(); + _controller.reverse(); }, onTapCancel: () { _cancel = true; - _controller?.reverse(); + _controller.reverse(); }, child: Padding( padding: const EdgeInsets.all(10.0), @@ -88,7 +88,9 @@ class _IconToggleState extends State reverseDuration: widget.reverseDuration, transitionBuilder: widget.transitionBuilder, child: Icon( - widget.value ? widget.selectedIconData : widget.unselectedIconData, + widget.value + ? widget.selectedIconData + : widget.unselectedIconData, color: widget.value ? widget.activeColor : widget.inactiveColor, size: 22, key: ValueKey(widget.value), @@ -102,14 +104,15 @@ class _IconToggleState extends State class _IconToggleable extends AnimatedWidget { _IconToggleable({ - Animation listenable, - this.activeColor, - this.inactiveColor, - this.child, + required this.listenable, + required this.activeColor, + required this.inactiveColor, + required this.child, }) : super(listenable: listenable); final Color activeColor; final Color inactiveColor; final Widget child; + final Animation listenable; @override Widget build(BuildContext context) { return CustomPaint( @@ -125,20 +128,20 @@ class _IconToggleable extends AnimatedWidget { class _IconPainter extends CustomPainter { _IconPainter({ - @required this.position, - this.activeColor, - this.inactiveColor, + required this.position, + required this.activeColor, + required this.inactiveColor, }); final Animation position; final Color activeColor; final Color inactiveColor; - double get _value => position != null ? position.value : 0; + double get _value => position.value; @override void paint(Canvas canvas, Size size) { final Paint paint = Paint() - ..color = Color.lerp(inactiveColor, activeColor, _value) + ..color = Color.lerp(inactiveColor, activeColor, _value)! .withOpacity(math.min(_value, 0.15)) ..style = PaintingStyle.fill ..strokeWidth = 2.0; diff --git a/pubspec.yaml b/pubspec.yaml index 34d2c55..e5a2c9f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,11 +1,10 @@ name: flutter_icons description: Customizable Icons for Flutter,you can use with over 3K+ icons in your flutter project version: 1.1.0 -author: flutter-studio<2534290808@qq.com> homepage: https://github.com/flutter-studio/flutter-icons.git environment: - sdk: ">=2.0.0-dev.68.0 <3.0.0" + sdk: ">=2.12.0 <3.0.0" dependencies: flutter: