Skip to content

Commit

Permalink
Merge pull request #44 from miDeb/nnbd
Browse files Browse the repository at this point in the history
  • Loading branch information
yadaniyil authored Mar 13, 2021
2 parents 9173ba2 + a4571e5 commit 097f50f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 39 deletions.
22 changes: 11 additions & 11 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 All @@ -27,7 +27,7 @@ class HomeScreen extends StatefulWidget {

class _HomeScreenState extends State<HomeScreen> {
int _counter = 0;
bool showRaisedButtonBadge = true;
bool showElevatedButtonBadge = true;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -56,7 +56,7 @@ class _HomeScreenState extends State<HomeScreen> {
_addRemoveCartButtons(),
_textBadge(),
_directionalBadge(),
_raisedButtonBadge(),
_elevatedButtonBadge(),
_chipWithZeroPadding(),
expandedBadge(),
_badgeWithZeroPadding(),
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 @@ -159,15 +159,15 @@ class _HomeScreenState extends State<HomeScreen> {
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
RaisedButton.icon(
ElevatedButton.icon(
onPressed: () {
setState(() {
_counter++;
});
},
icon: Icon(Icons.add),
label: Text('Add to cart')),
RaisedButton.icon(
ElevatedButton.icon(
onPressed: () {
if (_counter > 0) {
setState(() {
Expand Down Expand Up @@ -197,19 +197,19 @@ class _HomeScreenState extends State<HomeScreen> {
);
}

Widget _raisedButtonBadge() {
Widget _elevatedButtonBadge() {
return Badge(
showBadge: showRaisedButtonBadge,
showBadge: showElevatedButtonBadge,
padding: EdgeInsets.all(8),
badgeColor: Colors.deepPurple,
badgeContent: Text(
'!',
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
),
child: RaisedButton(
child: ElevatedButton(
onPressed: () {
setState(() {
showRaisedButtonBadge = !showRaisedButtonBadge;
showElevatedButtonBadge = !showElevatedButtonBadge;
});
},
child: Text('Raised Button'),
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: 2 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ name: example
description: A new Flutter project.

environment:
sdk: ">=2.8.0 <3.0.0"
flutter: ">=0.2.5 <2.0.0"
sdk: '>=2.12.0 <3.0.0'

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

dev_dependencies:
pedantic: ^1.9.2
flutter_test:
sdk: flutter

Expand Down
18 changes: 9 additions & 9 deletions lib/src/badge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:flutter/material.dart';
class Badge extends StatefulWidget {
/// Creates a [Badge].
///
/// If [child] is null, it doesn't make sens to set [ignorePointer],
/// If [child] is null, it doesn't make sense to set [ignorePointer],
/// [position] and [alignment]
///
/// See also:
Expand All @@ -18,7 +18,7 @@ class Badge extends StatefulWidget {
/// * [BadgeAnimationType]
/// * [BorderSide]
Badge({
Key key,
Key? key,
this.badgeContent,
this.child,
this.badgeColor = Colors.red,
Expand All @@ -37,7 +37,7 @@ class Badge extends StatefulWidget {
}) : super(key: key);

/// It defines the widget that will be wrapped by this [badgeContent].
final Widget child;
final Widget? child;

/// This defines alignment for your [child].
///
Expand All @@ -48,10 +48,10 @@ class Badge extends StatefulWidget {
/// according to [child].
///
/// If [child] is null, it doesn't make sense to use it.
final BadgePosition position;
final BadgePosition? position;

/// Content of this badge widget
final Widget badgeContent;
final Widget? badgeContent;

/// Can make your [badgeContent] interactive.
///
Expand Down Expand Up @@ -133,8 +133,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 @@ -172,7 +172,7 @@ class BadgeState extends State<Badge> with SingleTickerProviderStateMixin {
alignment: widget.alignment,
clipBehavior: Clip.none,
children: [
widget.child,
widget.child!,
BadgePositioned(
position: widget.position,
child: widget.ignorePointer
Expand All @@ -189,7 +189,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
24 changes: 12 additions & 12 deletions lib/src/badge_position.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,41 @@ import 'package:badges/badges.dart';
/// This contain a custom position for the [Badge]
class BadgePosition {
/// This is the distance to the top side of a parent widget.
final double top;
final double? top;

/// This is the distance to the end side of a parent widget.
final double end;
final double? end;

/// This is the distance to the start side of a parent widget.
final double start;
final double? start;

/// This is the distance to the bottom side of a parent widget.
final double bottom;
final double? bottom;

/// This creates a new instance of this widget
const BadgePosition({this.top, this.end, this.bottom, this.start});

/// Factory method that creates a new instance of this widget
/// according to [top] and [start]
factory BadgePosition.topStart({double top, double start}) {
return BadgePosition(top: top ?? -5, start: start ?? -10);
factory BadgePosition.topStart({double top = -5, double start = -10}) {
return BadgePosition(top: top, start: start);
}

/// Factory method that creates a new instance of this widget
/// according to [top] and [end]
factory BadgePosition.topEnd({double top, double end}) {
return BadgePosition(top: top ?? -8, end: end ?? -10);
factory BadgePosition.topEnd({double top = -8, double end = -10}) {
return BadgePosition(top: top, end: end);
}

/// Factory method that creates a new instance of this widget
/// according to [bottom] and [end]
factory BadgePosition.bottomEnd({double bottom, double end}) {
return BadgePosition(bottom: bottom ?? -8, end: end ?? -10);
factory BadgePosition.bottomEnd({double bottom = -8, double end = -10}) {
return BadgePosition(bottom: bottom, end: end);
}

/// Factory method that creates a new instance of this widget
/// according to [bottom] and [start]
factory BadgePosition.bottomStart({double bottom, double start}) {
return BadgePosition(bottom: bottom ?? -8, start: start ?? -10);
factory BadgePosition.bottomStart({double bottom = -8, double start = -10}) {
return BadgePosition(bottom: bottom, start: start);
}
}
6 changes: 4 additions & 2 deletions lib/src/badge_positioned.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:flutter/widgets.dart';
/// [BadgePosition] and [child].
class BadgePositioned extends StatelessWidget {
/// This specify a badge position according to [child]
final BadgePosition position;
final BadgePosition? position;

/// It is a child that will be displayed according to [position]
final Widget child;
Expand All @@ -17,10 +17,12 @@ class BadgePositioned extends StatelessWidget {
///
/// See also:
/// * [PositionedDirectional]
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) {
final position = this.position;
if (position == null) {
final topRight = BadgePosition.topEnd();
return PositionedDirectional(
Expand Down
6 changes: 3 additions & 3 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.2.0
version: 2.0.0
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"
flutter: ">=0.2.5 <2.0.0"
sdk: ">=2.12.0 <3.0.0"
flutter: ">=0.2.5"

0 comments on commit 097f50f

Please sign in to comment.