Skip to content

upgrade sdk support with latest flutter #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
47 changes: 26 additions & 21 deletions lib/src/icon_toggle.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import 'package:flutter/material.dart';
import 'dart:math' as math;

Expand All @@ -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<bool> onChanged;
final ValueChanged<bool>? onChanged;
final AnimatedSwitcherTransitionBuilder transitionBuilder;
final Duration duration;
final Duration reverseDuration;
final Duration? reverseDuration;

@override
_IconToggleState createState() => _IconToggleState();
}

class _IconToggleState extends State<IconToggle>
with SingleTickerProviderStateMixin {
AnimationController _controller;
Animation<double> _position;
late AnimationController _controller;
late Animation<double> _position;
bool _cancel = false;

@override
Expand All @@ -51,14 +52,14 @@ class _IconToggleState extends State<IconToggle>
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();
}

Expand All @@ -68,14 +69,14 @@ class _IconToggleState extends State<IconToggle>
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),
Expand All @@ -88,7 +89,9 @@ class _IconToggleState extends State<IconToggle>
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<bool>(widget.value),
Expand All @@ -102,19 +105,20 @@ class _IconToggleState extends State<IconToggle>

class _IconToggleable<T> extends AnimatedWidget {
_IconToggleable({
Animation<T> listenable,
this.activeColor,
this.inactiveColor,
this.child,
required Animation<T> 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<double>,
activeColor: activeColor,
inactiveColor: inactiveColor,
),
Expand All @@ -125,20 +129,21 @@ class _IconToggleable<T> 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<double> 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;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ author: flutter-studio<[email protected]>
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:
Expand Down
2 changes: 0 additions & 2 deletions test/flutter_icons_test.dart
Original file line number Diff line number Diff line change
@@ -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())
Expand Down