Skip to content
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

migrated to null safety #48

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
11 changes: 7 additions & 4 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -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"
49 changes: 26 additions & 23 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 @@ -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<bool> onChanged;
final ValueChanged<bool>? onChanged;
final AnimatedSwitcherTransitionBuilder transitionBuilder;
final Duration duration;
final Duration reverseDuration;
Expand All @@ -35,30 +34,31 @@ class IconToggle extends StatefulWidget {

class _IconToggleState extends State<IconToggle>
with SingleTickerProviderStateMixin {
AnimationController _controller;
Animation<double> _position;
late final AnimationController _controller;
late final Animation<double> _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();
}

Expand All @@ -68,14 +68,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 +88,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,14 +104,15 @@ class _IconToggleState extends State<IconToggle>

class _IconToggleable<T> extends AnimatedWidget {
_IconToggleable({
Animation<T> 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<double> listenable;
@override
Widget build(BuildContext context) {
return CustomPaint(
Expand All @@ -125,20 +128,20 @@ 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
3 changes: 1 addition & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down