Skip to content

Commit

Permalink
Merge pull request #3 from cb-cloud/feature/null-safety
Browse files Browse the repository at this point in the history
Migrate null-safety
  • Loading branch information
Kurogoma4D authored Jun 7, 2021
2 parents f2aa1c7 + bb173b9 commit 900fb8e
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 79 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
name: Testing

on:
push:
pull_request:
types: [opened, reopened, ready_for_review]

jobs:
flutter:
runs-on: ubuntu-latest
container: cirrusci/flutter:1.22.6
container: cirrusci/flutter:2.2.1

steps:
- uses: actions/checkout@v2
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
## 0.2.0
**BREAKING: Migrate to sound null safety.**
CHORE:
- Changed description.
- Added pub.dev badge to README.

## 0.1.0
First release.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 💬 in_app_notification
A Flutter package for show custom in-app notification.
[![pub package](https://img.shields.io/pub/v/in_app_notification.svg)](https://pub.dev/packages/in_app_notification)
A Flutter package to show custom in-app notification with any Widgets.

<p align="center">
<image src="https://raw.githubusercontent.com/wiki/cb-cloud/flutter_in_app_notification/assets/doc/top.gif"/>
Expand Down Expand Up @@ -41,7 +42,7 @@ A Flutter package for show custom in-app notification.
```

## 🗺 Roadmap / Known issue
- Null-safety migration
- ~~Null-safety migration~~ ✅
- Implementation for more gesture
- Swipe horizontal
- Performance optimization
Expand Down
6 changes: 5 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
include: package:pedantic/analysis_options.1.9.0.yaml
include: package:pedantic/analysis_options.1.11.0.yaml

linter:
rules:
unawaited_futures: false
2 changes: 1 addition & 1 deletion example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include: package:pedantic/analysis_options.1.9.0.yaml
include: package:pedantic/analysis_options.1.11.0.yaml
12 changes: 6 additions & 6 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void main() {
}

class App extends StatelessWidget {
const App({Key key}) : super(key: key);
const App({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
Expand All @@ -22,14 +22,14 @@ class App extends StatelessWidget {
builder: (context, child) => InAppNotification(
safeAreaPadding: MediaQuery.of(context).viewPadding,
minAlertHeight: 60.0,
child: child,
child: child!,
),
);
}
}

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

@override
_HomePageState createState() => _HomePageState();
Expand Down Expand Up @@ -64,7 +64,7 @@ class _HomePageState extends State<HomePage> {
ElevatedButton(
onPressed: () {
_incrementCount();
InAppNotification.of(context).show(
InAppNotification.of(context)?.show(
child: NotificationBody(count: _count),
onTap: () => print('Notification tapped!'),
duration: Duration(milliseconds: _duration),
Expand All @@ -86,7 +86,7 @@ class NotificationBody extends StatelessWidget {
final int count;

NotificationBody({
Key key,
Key? key,
this.count = 0,
}) : super(key: key);

Expand Down Expand Up @@ -124,7 +124,7 @@ class NotificationBody extends StatelessWidget {
'Count: $count',
style: Theme.of(context)
.textTheme
.headline4
.headline4!
.copyWith(color: Colors.white),
),
),
Expand Down
42 changes: 21 additions & 21 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,49 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.0-nullsafety.1"
version: "2.6.1"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.1"
version: "2.1.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.3"
version: "1.1.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.1"
version: "1.2.0"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.1"
version: "1.1.0"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0-nullsafety.3"
version: "1.15.0"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.1"
version: "1.2.0"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -66,35 +66,35 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.1"
version: "0.1.0"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10-nullsafety.1"
version: "0.12.10"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0-nullsafety.3"
version: "1.3.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0-nullsafety.1"
version: "1.8.0"
pedantic:
dependency: "direct dev"
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.2"
version: "1.11.0"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -106,56 +106,56 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0-nullsafety.2"
version: "1.8.1"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0-nullsafety.1"
version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.1"
version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.1"
version: "1.1.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.1"
version: "1.2.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19-nullsafety.2"
version: "0.3.0"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0-nullsafety.3"
version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.3"
version: "2.1.0"
sdks:
dart: ">=2.10.0-110 <2.11.0"
dart: ">=2.12.0 <3.0.0"
flutter: ">=1.17.0"
4 changes: 2 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ publish_to: 'none'
version: 1.0.0+1

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

dependencies:
flutter:
Expand All @@ -16,7 +16,7 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
pedantic: ^1.9.2
pedantic: ^1.11.0

flutter:
uses-material-design: true
35 changes: 17 additions & 18 deletions lib/src/in_app_notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ class InAppNotification extends StatefulWidget {
///
/// The [safeAreaPadding] must not be null.
const InAppNotification({
Key key,
@required this.safeAreaPadding,
Key? key,
required this.safeAreaPadding,
this.minAlertHeight = 120.0,
this.child,
}) : assert(safeAreaPadding != null),
super(key: key);
required this.child,
}) : super(key: key);

final Widget child;

Expand All @@ -48,7 +47,7 @@ class InAppNotification extends StatefulWidget {
/// The default value is 120.0.
final double minAlertHeight;

static InAppNotificationState of(BuildContext context) =>
static InAppNotificationState? of(BuildContext context) =>
context.findAncestorStateOfType<InAppNotificationState>();

@override
Expand All @@ -57,11 +56,11 @@ class InAppNotification extends StatefulWidget {

class InAppNotificationState extends State<InAppNotification>
with SingleTickerProviderStateMixin {
Widget _body;
VoidCallback _onTap;
AnimationController _controller;
Timer _timer;
Animation<double> _alertAnimation;
Widget? _body;
VoidCallback? _onTap;
AnimationController? _controller;
Timer? _timer;
late Animation<double> _alertAnimation;
double _initialPosition = 0.0;
double _dragDistance = 0.0;

Expand All @@ -71,7 +70,7 @@ class InAppNotificationState extends State<InAppNotification>
void initState() {
_controller =
AnimationController(vsync: this, duration: notificationShowingDuration);
final curve = CurvedAnimation(parent: _controller, curve: Curves.ease);
final curve = CurvedAnimation(parent: _controller!, curve: Curves.ease);
_initialPosition = -widget.minAlertHeight - widget.safeAreaPadding.top;
_alertAnimation = Tween(begin: _initialPosition, end: 0.0).animate(curve);
super.initState();
Expand All @@ -89,13 +88,13 @@ class InAppNotificationState extends State<InAppNotification>
/// 3. After the [duration] has elapsed,
/// play the animation in reverse and dispose the notification.
Future<void> show({
@required Widget child,
VoidCallback onTap,
required Widget child,
VoidCallback? onTap,
Duration duration = const Duration(seconds: 10),
}) async {
_timer?.cancel();

if (_controller.isCompleted) {
if (_controller!.isCompleted) {
await dismiss();
}

Expand All @@ -106,11 +105,11 @@ class InAppNotificationState extends State<InAppNotification>
});
_controller?.forward(from: 0.0);

if (duration?.inMicroseconds == 0) return;
if (duration.inMicroseconds == 0) return;
_timer = Timer(duration, () => dismiss());
}

Future dismiss({double from}) async {
Future dismiss({double? from}) async {
_timer?.cancel();
await _controller?.reverse(from: from ?? 1.0);
setState(() => _body = null);
Expand All @@ -120,7 +119,7 @@ class InAppNotificationState extends State<InAppNotification>
if (_onTap == null) return;

dismiss();
_onTap();
_onTap!();
}

void _onTapDown() {
Expand Down
Loading

0 comments on commit 900fb8e

Please sign in to comment.