Skip to content

Commit

Permalink
Migration to null-safety.
Browse files Browse the repository at this point in the history
  • Loading branch information
aloisdeniel committed Mar 3, 2021
1 parent e10cd34 commit 6dccf60
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 142 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## [0.7.0]

* Migration to null-safety.

## [0.6.4]

* Fixed parsing issue with `g` tag.
Expand Down
12 changes: 6 additions & 6 deletions example/lib/main.dart
Expand Up @@ -22,7 +22,7 @@ class ExampleApp extends StatelessWidget {

class HomePage extends StatefulWidget {
const HomePage({
Key key,
Key? key,
}) : super(key: key);

@override
Expand All @@ -40,7 +40,7 @@ class _HomePageState extends State<HomePage> {
child: SafeArea(
child: Column(
children: [
Picker(
Picker<Color>(
values: {
Colors.black: 'black',
Colors.red: 'red',
Expand Down Expand Up @@ -100,10 +100,10 @@ class _HomePageState extends State<HomePage> {

class Picker<T> extends StatelessWidget {
const Picker({
Key key,
@required this.value,
@required this.onSelected,
@required this.values,
Key? key,
required this.value,
required this.onSelected,
required this.values,
}) : super(key: key);

final Map<T, String> values;
Expand Down
57 changes: 25 additions & 32 deletions example/pubspec.lock
Expand Up @@ -7,49 +7,42 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.0-nullsafety.3"
version: "2.5.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.3"
version: "2.1.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.5"
version: "1.1.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.3"
version: "1.2.0"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.3"
version: "1.1.0"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0-nullsafety.5"
convert:
dependency: transitive
description:
name: convert
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
version: "1.15.0"
cupertino_icons:
dependency: "direct main"
description:
Expand All @@ -63,7 +56,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.3"
version: "1.2.0"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -80,49 +73,49 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10-nullsafety.3"
version: "0.12.10"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0-nullsafety.6"
version: "1.3.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0-nullsafety.3"
version: "1.8.0"
path_drawing:
dependency: transitive
description:
name: path_drawing
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.1+1"
version: "0.5.0-nullsafety.0"
path_icon:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "0.6.4"
version: "0.7.0"
path_parsing:
dependency: transitive
description:
name: path_parsing
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
version: "0.2.0-nullsafety.0"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.0"
version: "4.0.2"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -134,63 +127,63 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0-nullsafety.4"
version: "1.8.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0-nullsafety.6"
version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.3"
version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.3"
version: "1.1.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.3"
version: "1.2.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19-nullsafety.6"
version: "0.2.19"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0-nullsafety.5"
version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.5"
version: "2.1.0"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "4.5.1"
version: "5.0.2"
sdks:
dart: ">=2.12.0-0.0 <3.0.0"
flutter: ">=1.17.0 <2.0.0"
dart: ">=2.12.0 <3.0.0"
flutter: ">=2.0.0"
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Expand Up @@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1

environment:
sdk: ">=2.7.0 <3.0.0"
sdk: ">=2.12.0 <3.0.0"

dependencies:
path_icon:
Expand Down
18 changes: 7 additions & 11 deletions lib/src/animated_icon.dart
Expand Up @@ -16,17 +16,13 @@ class AnimatedPathIcon extends ImplicitlyAnimatedWidget {
/// The [curve] and [duration] arguments must not be null.
const AnimatedPathIcon(
this.data, {
@required Duration duration,
required Duration duration,
Curve curve = Curves.easeInOut,
Key key,
Key? key,
this.size = 24,
this.color = Colors.black,
this.semanticLabel,
}) : assert(data != null),
assert(duration != null),
assert(size != null),
assert(color != null),
super(
}) : super(
key: key,
duration: duration,
curve: curve,
Expand All @@ -52,7 +48,7 @@ class AnimatedPathIcon extends ImplicitlyAnimatedWidget {
///
/// Announced in accessibility modes (e.g TalkBack/VoiceOver).
/// This label does not show in the UI.
final String semanticLabel;
final String? semanticLabel;

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
Expand All @@ -69,8 +65,8 @@ class AnimatedPathIcon extends ImplicitlyAnimatedWidget {
}

class _AnimatedPathIconState extends AnimatedWidgetBaseState<AnimatedPathIcon> {
ColorTween _color;
BoxConstraintsTween _constraints;
ColorTween? _color;
BoxConstraintsTween? _constraints;

@override
void forEachTween(TweenVisitor<dynamic> visitor) {
Expand All @@ -90,7 +86,7 @@ class _AnimatedPathIconState extends AnimatedWidgetBaseState<AnimatedPathIcon> {
final color = _color?.evaluate(animation);
final constraints = _constraints?.evaluate(animation);
return ConstrainedBox(
constraints: constraints,
constraints: constraints ?? BoxConstraints(),
child: CustomPaint(
painter: PathIconPainter(
path: widget.data.path,
Expand Down
28 changes: 14 additions & 14 deletions lib/src/data.dart
Expand Up @@ -10,11 +10,10 @@ import 'svg_parsing.dart';
class PathIconData {
/// Create data from the given [path] and its [viewBox] describing the effective area.
const PathIconData({
@required this.path,
@required this.viewBox,
required this.path,
required this.viewBox,
this.id,
}) : assert(path != null),
assert(viewBox != null);
});

/// Create data from the given [path].
///
Expand All @@ -23,11 +22,10 @@ class PathIconData {
///
/// A [fillType] can override the given [path]'s one.
factory PathIconData.sanitized({
@required Path path,
Rect viewBox,
PathFillType fillType,
required Path path,
Rect? viewBox,
PathFillType? fillType,
}) {
assert(path != null);
final bounds = path.getBounds();

if (viewBox == null) {
Expand All @@ -54,10 +52,9 @@ class PathIconData {
/// A [fillType] can be given, else `PathFillType.evenOdd`.
factory PathIconData.fromData(
String data, {
Rect viewBox,
PathFillType fillType,
Rect? viewBox,
PathFillType? fillType,
}) {
assert(data != null);
final path = parseSvgPathData(data);
return PathIconData.sanitized(
path: path,
Expand All @@ -76,17 +73,20 @@ class PathIconData {
String data, {
PathFillType fillType = PathFillType.evenOdd,
}) {
assert(data != null);
final document = XmlDocument.parse(data);

if (document.rootElement.name.local != 'svg') {
throw Exception('The provided is not an SVG content');
}

final viewBoxData = document.rootElement.getAttribute('viewBox');
final viewBox = parseViewBox(viewBoxData);
final viewBox = viewBoxData == null ? Rect.zero : parseViewBox(viewBoxData);
final path = parseSvgElements(document.rootElement);

if (path == null) {
throw Exception('Empty path');
}

return PathIconData.sanitized(
path: path,
fillType: fillType,
Expand All @@ -101,7 +101,7 @@ class PathIconData {
final Rect viewBox;

/// An optional identifier that may help for debug.
final String id;
final String? id;

@override
String toString() {
Expand Down

0 comments on commit 6dccf60

Please sign in to comment.