From bb4837129f7c91fdf8c85fead60bde35c7964452 Mon Sep 17 00:00:00 2001 From: Michael Debertol Date: Sat, 30 Jan 2021 12:36:10 +0100 Subject: [PATCH] migrate to nnbd --- example/lib/main.dart | 6 +++--- example/pubspec.yaml | 4 ++++ lib/src/badge.dart | 16 ++++++++-------- lib/src/badge_position.dart | 16 ++++++++-------- lib/src/badge_positioned.dart | 13 +++++++------ pubspec.yaml | 4 ++-- 6 files changed, 32 insertions(+), 27 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 266bf81..0bb1f22 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -15,7 +15,7 @@ class MyApp extends StatelessWidget { } ThemeData _buildTheme() { - final ThemeData base = ThemeData.light(); + final base = ThemeData.light(); return base.copyWith( primaryIconTheme: base.iconTheme.copyWith(color: Colors.black)); } @@ -92,7 +92,7 @@ class _HomeScreenState extends State { ); } - Widget _tabBar() { + PreferredSizeWidget _tabBar() { return TabBar(tabs: [ Tab( icon: Badge( @@ -238,7 +238,7 @@ class _HomeScreenState extends State { ); } - Widget _getExampleBadge({double padding}) { + Widget _getExampleBadge({double? padding}) { return Padding( padding: const EdgeInsets.all(4), child: Badge( diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 991ee89..a442e90 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,6 +1,9 @@ name: example description: A new Flutter project. +environment: + sdk: '>=2.12.0-0 <3.0.0' + dependencies: flutter: sdk: flutter @@ -13,6 +16,7 @@ dependencies: path: ../ dev_dependencies: + pedantic: ^1.9.2 flutter_test: sdk: flutter diff --git a/lib/src/badge.dart b/lib/src/badge.dart index bc7749f..902b989 100644 --- a/lib/src/badge.dart +++ b/lib/src/badge.dart @@ -5,12 +5,12 @@ import 'package:badges/src/badge_shape.dart'; import 'package:flutter/material.dart'; class Badge extends StatefulWidget { - final Widget badgeContent; + final Widget? badgeContent; final Color badgeColor; - final Widget child; + final Widget? child; final double elevation; final bool toAnimate; - final BadgePosition position; + final BadgePosition? position; final BadgeShape shape; final EdgeInsetsGeometry padding; final Duration animationDuration; @@ -22,7 +22,7 @@ class Badge extends StatefulWidget { final BorderSide borderSide; Badge({ - Key key, + Key? key, this.badgeContent, this.child, this.badgeColor = Colors.red, @@ -47,8 +47,8 @@ class Badge extends StatefulWidget { } class BadgeState extends State with SingleTickerProviderStateMixin { - AnimationController _animationController; - Animation _animation; + late AnimationController _animationController; + late Animation _animation; final Tween _positionTween = Tween( begin: const Offset(-0.5, 0.9), @@ -86,7 +86,7 @@ class BadgeState extends State with SingleTickerProviderStateMixin { alignment: widget.alignment, overflow: Overflow.visible, children: [ - widget.child, + widget.child!, BadgePositioned( position: widget.position, child: widget.ignorePointer @@ -103,7 +103,7 @@ class BadgeState extends State with SingleTickerProviderStateMixin { ? CircleBorder(side: widget.borderSide) : RoundedRectangleBorder( side: widget.borderSide, - borderRadius: widget.borderRadius ?? BorderRadius.zero, + borderRadius: widget.borderRadius, ); Widget badgeView() { diff --git a/lib/src/badge_position.dart b/lib/src/badge_position.dart index 753539a..d9f6bda 100644 --- a/lib/src/badge_position.dart +++ b/lib/src/badge_position.dart @@ -1,24 +1,24 @@ class BadgePosition { - final double top; - final double end; - final double bottom; - final double start; + final double? top; + final double? end; + final double? bottom; + final double? start; const BadgePosition({this.top, this.end, this.bottom, this.start}); - factory BadgePosition.topStart({double top, double start}) { + factory BadgePosition.topStart({double? top, double? start}) { return BadgePosition(top: top ?? -5, start: start ?? -10); } - factory BadgePosition.topEnd({double top, double end}) { + factory BadgePosition.topEnd({double? top, double? end}) { return BadgePosition(top: top ?? -8, end: end ?? -10); } - factory BadgePosition.bottomEnd({double bottom, double end}) { + factory BadgePosition.bottomEnd({double? bottom, double? end}) { return BadgePosition(bottom: bottom ?? -8, end: end ?? -10); } - factory BadgePosition.bottomStart({double bottom, double start}) { + factory BadgePosition.bottomStart({double? bottom, double? start}) { return BadgePosition(bottom: bottom ?? -8, start: start ?? -10); } } diff --git a/lib/src/badge_positioned.dart b/lib/src/badge_positioned.dart index 685920c..0264234 100644 --- a/lib/src/badge_positioned.dart +++ b/lib/src/badge_positioned.dart @@ -3,9 +3,10 @@ import 'package:flutter/widgets.dart'; class BadgePositioned extends StatelessWidget { final Widget child; - final BadgePosition position; + final BadgePosition? position; - const BadgePositioned({Key key, this.position, this.child}) : super(key: key); + const BadgePositioned({Key? key, this.position, required this.child}) + : super(key: key); @override Widget build(BuildContext context) { @@ -18,10 +19,10 @@ class BadgePositioned extends StatelessWidget { ); } return PositionedDirectional( - top: position.top, - end: position.end, - bottom: position.bottom, - start: position.start, + top: position!.top, + end: position!.end, + bottom: position!.bottom, + start: position!.start, child: child, ); } diff --git a/pubspec.yaml b/pubspec.yaml index 4b69a1f..c6422a5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: badges description: A flutter package for creating badges. Badges can be used for an additional marker for any widget, e.g. show a number of items in a shopping cart. -version: 1.1.6 +version: 2.0.0-nullsafety.1 homepage: https://github.com/yadaniyil/flutter_badges dependencies: @@ -13,5 +13,5 @@ dev_dependencies: pedantic: ^1.9.2 environment: - sdk: ">=2.8.0 <3.0.0" + sdk: ">=2.12.0-0 <3.0.0" flutter: ">=0.2.5 <2.0.0"