Skip to content

Commit

Permalink
migrate to nnbd
Browse files Browse the repository at this point in the history
  • Loading branch information
miDeb committed Jan 30, 2021
1 parent aa50fbc commit bb48371
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 27 deletions.
6 changes: 3 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -92,7 +92,7 @@ class _HomeScreenState extends State<HomeScreen> {
);
}

Widget _tabBar() {
PreferredSizeWidget _tabBar() {
return TabBar(tabs: [
Tab(
icon: Badge(
Expand Down Expand Up @@ -238,7 +238,7 @@ class _HomeScreenState extends State<HomeScreen> {
);
}

Widget _getExampleBadge({double padding}) {
Widget _getExampleBadge({double? padding}) {
return Padding(
padding: const EdgeInsets.all(4),
child: Badge(
Expand Down
4 changes: 4 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: example
description: A new Flutter project.

environment:
sdk: '>=2.12.0-0 <3.0.0'

dependencies:
flutter:
sdk: flutter
Expand All @@ -13,6 +16,7 @@ dependencies:
path: ../

dev_dependencies:
pedantic: ^1.9.2
flutter_test:
sdk: flutter

Expand Down
16 changes: 8 additions & 8 deletions lib/src/badge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,7 +22,7 @@ class Badge extends StatefulWidget {
final BorderSide borderSide;

Badge({
Key key,
Key? key,
this.badgeContent,
this.child,
this.badgeColor = Colors.red,
Expand All @@ -47,8 +47,8 @@ class Badge extends StatefulWidget {
}

class BadgeState extends State<Badge> with SingleTickerProviderStateMixin {
AnimationController _animationController;
Animation<double> _animation;
late AnimationController _animationController;
late Animation<double> _animation;

final Tween<Offset> _positionTween = Tween(
begin: const Offset(-0.5, 0.9),
Expand Down Expand Up @@ -86,7 +86,7 @@ class BadgeState extends State<Badge> with SingleTickerProviderStateMixin {
alignment: widget.alignment,
overflow: Overflow.visible,
children: [
widget.child,
widget.child!,
BadgePositioned(
position: widget.position,
child: widget.ignorePointer
Expand All @@ -103,7 +103,7 @@ class BadgeState extends State<Badge> with SingleTickerProviderStateMixin {
? CircleBorder(side: widget.borderSide)
: RoundedRectangleBorder(
side: widget.borderSide,
borderRadius: widget.borderRadius ?? BorderRadius.zero,
borderRadius: widget.borderRadius,
);

Widget badgeView() {
Expand Down
16 changes: 8 additions & 8 deletions lib/src/badge_position.dart
Original file line number Diff line number Diff line change
@@ -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);
}
}
13 changes: 7 additions & 6 deletions lib/src/badge_positioned.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
);
}
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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"

0 comments on commit bb48371

Please sign in to comment.