Skip to content

Commit

Permalink
Merge pull request #15 from cb-cloud/feature/refactoring
Browse files Browse the repository at this point in the history
Refactoring and bug fixes around animation curve.
  • Loading branch information
Kurogoma4D authored Mar 2, 2022
2 parents 5989f28 + 3114c97 commit 8e718c6
Show file tree
Hide file tree
Showing 11 changed files with 370 additions and 112 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 1.0.2
### FIX
- Fixed a bug that `curve` option in `InAppNotification.show()` didn't affect.

### FEAT
- Added `dismissCurve` option in `InAppNotification.show()`.
### CHORE
- Refactored a whole of code.
- More readable logic around showing and dismissing notification.
- Isolated `AnimationController` for interactions from one for showing.
- Expanded example app to change sample notification size.

## 1.0.1
### FIX
- Fixed a bug that the notification doesn't apppear when swiping previous one.
Expand Down
92 changes: 58 additions & 34 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:math' as math;
import 'dart:ui';

import 'package:flutter/material.dart';
Expand Down Expand Up @@ -35,6 +36,7 @@ class HomePage extends StatefulWidget {
class _HomePageState extends State<HomePage> {
int _count = 0;
int _duration = 3000;
double _minHeight = 0.0;

void _incrementCount() => setState(() => _count++);

Expand All @@ -57,12 +59,25 @@ class _HomePageState extends State<HomePage> {
min: 500,
max: 5000,
),
const SizedBox(height: 24),
Text('Notification minimum height: $_minHeight '),
const SizedBox(height: 16),
Slider.adaptive(
value: _minHeight,
onChanged: (value) =>
setState(() => _minHeight = value.floorToDouble()),
min: 0.0,
max: MediaQuery.of(context).size.height,
),
const SizedBox(height: 32),
ElevatedButton(
onPressed: () {
_incrementCount();
InAppNotification.show(
child: NotificationBody(count: _count),
child: NotificationBody(
count: _count,
minHeight: _minHeight,
),
context: context,
onTap: () => print('Notification tapped!'),
duration: Duration(milliseconds: _duration),
Expand All @@ -82,48 +97,57 @@ class _HomePageState extends State<HomePage> {
/// Please replace this into your own Widget.
class NotificationBody extends StatelessWidget {
final int count;
final double minHeight;

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

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.fromLTRB(16, 4, 16, 0),
child: DecoratedBox(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
spreadRadius: 12,
blurRadius: 16,
),
],
),
child: ClipRRect(
borderRadius: BorderRadius.circular(16),
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 24, sigmaY: 24),
child: DecoratedBox(
decoration: BoxDecoration(
color: Colors.lightGreen.withOpacity(0.4),
borderRadius: BorderRadius.circular(16.0),
border: Border.all(
width: 1.4,
color: Colors.lightGreen.withOpacity(0.2),
),
final minHeight = math.min(
this.minHeight,
MediaQuery.of(context).size.height,
);
return ConstrainedBox(
constraints: BoxConstraints(minHeight: minHeight),
child: Padding(
padding: const EdgeInsets.fromLTRB(16, 4, 16, 0),
child: DecoratedBox(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
spreadRadius: 12,
blurRadius: 16,
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Center(
child: Text(
'Count: $count',
style: Theme.of(context)
.textTheme
.headline4!
.copyWith(color: Colors.white),
],
),
child: ClipRRect(
borderRadius: BorderRadius.circular(16),
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 24, sigmaY: 24),
child: DecoratedBox(
decoration: BoxDecoration(
color: Colors.lightGreen.withOpacity(0.4),
borderRadius: BorderRadius.circular(16.0),
border: Border.all(
width: 1.4,
color: Colors.lightGreen.withOpacity(0.2),
),
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Center(
child: Text(
'Count: $count',
style: Theme.of(context)
.textTheme
.headline4!
.copyWith(color: Colors.white),
),
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.1"
version: "1.0.2"
matcher:
dependency: transitive
description:
Expand Down
Binary file added example/web/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/web/icons/Icon-192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/web/icons/Icon-512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
98 changes: 98 additions & 0 deletions example/web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<!DOCTYPE html>
<html>
<head>
<!--
If you are serving your web app in a path other than the root, change the
href value below to reflect the base path you are serving from.
The path provided below has to start and end with a slash "/" in order for
it to work correctly.
For more details:
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
-->
<base href="/">

<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="A new Flutter project.">

<!-- iOS meta tags & icons -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="example">
<link rel="apple-touch-icon" href="icons/Icon-192.png">

<title>example</title>
<link rel="manifest" href="manifest.json">
</head>
<body>
<!-- This script installs service_worker.js to provide PWA functionality to
application. For more information, see:
https://developers.google.com/web/fundamentals/primers/service-workers -->
<script>
var serviceWorkerVersion = null;
var scriptLoaded = false;
function loadMainDartJs() {
if (scriptLoaded) {
return;
}
scriptLoaded = true;
var scriptTag = document.createElement('script');
scriptTag.src = 'main.dart.js';
scriptTag.type = 'application/javascript';
document.body.append(scriptTag);
}

if ('serviceWorker' in navigator) {
// Service workers are supported. Use them.
window.addEventListener('load', function () {
// Wait for registration to finish before dropping the <script> tag.
// Otherwise, the browser will load the script multiple times,
// potentially different versions.
var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
navigator.serviceWorker.register(serviceWorkerUrl)
.then((reg) => {
function waitForActivation(serviceWorker) {
serviceWorker.addEventListener('statechange', () => {
if (serviceWorker.state == 'activated') {
console.log('Installed new service worker.');
loadMainDartJs();
}
});
}
if (!reg.active && (reg.installing || reg.waiting)) {
// No active web worker and we have installed or are installing
// one for the first time. Simply wait for it to activate.
waitForActivation(reg.installing ?? reg.waiting);
} else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
// When the app updates the serviceWorkerVersion changes, so we
// need to ask the service worker to update.
console.log('New service worker available.');
reg.update();
waitForActivation(reg.installing);
} else {
// Existing service worker is still good.
console.log('Loading app from service worker.');
loadMainDartJs();
}
});

// If service worker doesn't succeed in a reasonable amount of time,
// fallback to plaint <script> tag.
setTimeout(() => {
if (!scriptLoaded) {
console.warn(
'Failed to load app from service worker. Falling back to plain <script> tag.',
);
loadMainDartJs();
}
}, 4000);
});
} else {
// Service workers not supported. Just drop the <script> tag.
loadMainDartJs();
}
</script>
</body>
</html>
23 changes: 23 additions & 0 deletions example/web/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "example",
"short_name": "example",
"start_url": ".",
"display": "standalone",
"background_color": "#0175C2",
"theme_color": "#0175C2",
"description": "A new Flutter project.",
"orientation": "portrait-primary",
"prefer_related_applications": false,
"icons": [
{
"src": "icons/Icon-192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "icons/Icon-512.png",
"sizes": "512x512",
"type": "image/png"
}
]
}
Loading

0 comments on commit 8e718c6

Please sign in to comment.