Skip to content

Commit

Permalink
feat: added badge for notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
alienc0der committed Aug 5, 2023
1 parent 6ffe120 commit 85cbef8
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
4 changes: 3 additions & 1 deletion lib/blocs/notifications_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import 'package:zenon_syrius_wallet_flutter/utils/constants.dart';
class NotificationsBloc extends BaseBloc<WalletNotification?> {
Future<void> addNotification(WalletNotification? notification) async {
try {
await Hive.openBox(kNotificationsBox);
if (!Hive.box(kNotificationsBox).isOpen) {
await Hive.openBox(kNotificationsBox);
}
Box notificationsBox = Hive.box(kNotificationsBox);
if (notificationsBox.length >= kNotificationsEntriesLimit) {
while (notificationsBox.length >= kNotificationsEntriesLimit) {
Expand Down
8 changes: 5 additions & 3 deletions lib/utils/init_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class InitUtils {
await NodeUtils.setNode();
_setChainId();
await NodeUtils.loadDbNodes();

await _openFavoriteTokensBox();
await _openNotificationsBox();
await _openRecipientBox();
} catch (e) {
rethrow;
}
Expand Down Expand Up @@ -74,9 +78,7 @@ class InitUtils {
zenon!.defaultKeyPair = kKeyStore!.getKeyPair(
kDefaultAddressList.indexOf(kSelectedAddress),
);
await _openFavoriteTokensBox();
await _openNotificationsBox();
await _openRecipientBox();

await NodeUtils.initWebSocketClient();
await _setWalletVersion();
kWalletInitCompleted = true;
Expand Down
24 changes: 18 additions & 6 deletions lib/widgets/main_app_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import 'dart:async';
import 'dart:io';

import 'package:app_links/app_links.dart';
import 'package:badges/badges.dart' as badges;
import 'package:clipboard_watcher/clipboard_watcher.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_svg/svg.dart';
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
import 'package:hive/hive.dart';
import 'package:logging/logging.dart';
import 'package:provider/provider.dart';
import 'package:wallet_connect_uri_validator/wallet_connect_uri_validator.dart';
Expand Down Expand Up @@ -112,6 +114,7 @@ class _MainAppContainerState extends State<MainAppContainer>
_initLockBlock();
_handleIncomingLinks();
_handleInitialUri();

super.initState();
}

Expand Down Expand Up @@ -333,12 +336,21 @@ class _MainAppContainerState extends State<MainAppContainer>
),
),
Tab(
child: Icon(
Icons.notifications,
size: 24.0,
color: _isTabSelected(Tabs.notifications)
? AppColors.znnColor
: Theme.of(context).iconTheme.color,
child: badges.Badge(
position: badges.BadgePosition.topEnd(top: -10, end: -10),
showBadge: (Hive.box(kNotificationsBox).length > 0),
badgeContent: Text(Hive.box(kNotificationsBox).length.toString()),
badgeStyle: const badges.BadgeStyle(
shape: badges.BadgeShape.circle,
badgeColor: AppColors.znnColor,
),
child: Icon(
Icons.notifications,
size: 24.0,
color: _isTabSelected(Tabs.notifications)
? AppColors.znnColor
: Theme.of(context).iconTheme.color,
),
),
),
Tab(
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.0"
badges:
dependency: "direct main"
description:
name: badges
sha256: "6e7f3ec561ec08f47f912cfe349d4a1707afdc8dda271e17b046aa6d42c89e77"
url: "https://pub.dev"
source: hosted
version: "3.1.1"
base_x:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ dependencies:
wallet_connect_uri_validator: ^0.1.0
big_decimal: ^0.5.0
ai_barcode_scanner: ^0.0.7
badges: ^3.1.1

dev_dependencies:
build_runner: ^2.4.6
Expand Down

0 comments on commit 85cbef8

Please sign in to comment.