From 56684685496d5dcd185d90f4e497d50ebf3a9812 Mon Sep 17 00:00:00 2001 From: Oeng Mengthong Date: Fri, 11 Oct 2024 16:39:30 +0700 Subject: [PATCH] upgrade sdk --- example/lib/main.dart | 2 +- example/pubspec.yaml | 2 +- lib/src/icon_toggle.dart | 47 ++++++++++++++++++++---------------- pubspec.yaml | 2 +- test/flutter_icons_test.dart | 2 -- 5 files changed, 29 insertions(+), 26 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 995d9c3..6577995 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -27,7 +27,7 @@ class MyApp extends StatelessWidget { } class MyHomePage extends StatefulWidget { - MyHomePage({Key key, this.title}) : super(key: key); + MyHomePage({super.key, required this.title}); final String title; diff --git a/example/pubspec.yaml b/example/pubspec.yaml index e84e54d..c89acf6 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -10,7 +10,7 @@ description: A new Flutter application. version: 1.0.0+1 environment: - sdk: ">=2.1.0 <3.0.0" + sdk: ">=3.0.0 <4.0.0" dependencies: flutter: diff --git a/lib/src/icon_toggle.dart b/lib/src/icon_toggle.dart index f051102..03a545d 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; @@ -20,23 +19,25 @@ class IconToggle extends StatefulWidget { this.duration = const Duration(milliseconds: 100), 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; + final Duration? reverseDuration; + @override _IconToggleState createState() => _IconToggleState(); } class _IconToggleState extends State with SingleTickerProviderStateMixin { - AnimationController _controller; - Animation _position; + late AnimationController _controller; + late Animation _position; bool _cancel = false; @override @@ -51,14 +52,14 @@ class _IconToggleState extends State 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 +69,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 +89,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,19 +105,20 @@ class _IconToggleState extends State class _IconToggleable extends AnimatedWidget { _IconToggleable({ - Animation listenable, - this.activeColor, - this.inactiveColor, - this.child, + required Animation listenable, + required this.activeColor, + required this.inactiveColor, + required this.child, }) : super(listenable: listenable); final Color activeColor; final Color inactiveColor; final Widget child; + @override Widget build(BuildContext context) { return CustomPaint( painter: _IconPainter( - position: listenable, + position: listenable as Animation, activeColor: activeColor, inactiveColor: inactiveColor, ), @@ -125,20 +129,21 @@ 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..5bbd38d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ 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: ">=3.0.0 <4.0.0" dependencies: flutter: diff --git a/test/flutter_icons_test.dart b/test/flutter_icons_test.dart index 6935c5d..78faec9 100644 --- a/test/flutter_icons_test.dart +++ b/test/flutter_icons_test.dart @@ -1,6 +1,4 @@ -import 'dart:async'; import 'dart:io'; -import 'file:///Users/makisu/flutter-icons/test/a.dart'; //void main() async { // File file = File("././lib/src/a.dart"); // if (!file.existsSync())