Skip to content

Feature: Notifications module #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .idea/flutter-base.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 21 additions & 21 deletions .idea/libraries/Dart_SDK.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 66 additions & 1 deletion app/lib/main/app.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:app/presentation/themes/local_theme.dart';
import 'package:common/core/resource.dart';
import 'package:flutter/material.dart';
import 'package:domain/bloc/app/app_cubit.dart';
Expand All @@ -11,6 +12,10 @@ import 'package:app/presentation/utils/lang_extensions.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:go_router/go_router.dart';
import 'package:notifications/bloc/notification_cubit.dart';
import 'package:notifications/presentation/notification_widget.dart';
import 'package:notifications/service/notification_service.dart';
import 'package:notifications/utils/notification_constants.dart';

import 'init.dart';

Expand All @@ -25,6 +30,9 @@ class App extends StatelessWidget {
providers: [
BlocProvider(create: (_) => getIt<AppCubit>()),
BlocProvider(create: (_) => getIt<AuthCubit>()),
BlocProvider.value(
value: getIt<NotificationService>().notificationCubit,
),
],
child: BlocBuilder<AppCubit, AppState>(
builder: (context, state) {
Expand All @@ -51,7 +59,64 @@ class App extends StatelessWidget {
}
}
},
child: child,
child: Stack(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Podemos mover estos cambios para el modulo example asi es mas facil de quitar cuando empezamos un proyecto nuevo usando el template

children: [
child ?? const SizedBox.shrink(),
BlocBuilder<NotificationCubit, NotificationState?>(
buildWhen: (previous, current) => previous != current,
builder: (context, state) {
return state?.message?.isNotEmpty ?? false
? Positioned(
top: NotificationConstants
.notificationButtonPadding,
child: SizedBox(
width: MediaQuery.of(context).size.width,
child: Row(
children: [
const Spacer(),
// Change according on project needs
NotificationWidget(
onClose: () {
getIt<NotificationService>()
.clearNotification();
},
message: state!.message!,
style: Theme.of(context)
.textTheme
.headlineMedium
?.copyWith(
color: context
.colors.neutralVariant.v0,
),
status: state.status,
maxWidth:
NotificationConstants.toastMaxWidth,
progressBarColor: switch (
state.status) {
NotificationStatus.idle =>
context.colors.primary.v10,
NotificationStatus.information =>
context.colors.primary.v99,
NotificationStatus.success =>
context.colors.primary.v0,
NotificationStatus.error =>
context.colors.error.v40,
},
progressBarBorderColor:
context.colors.neutral.v0,
progressBarBackgroundColor:
context.colors.neutral.v0,
),
const Spacer(),
],
),
),
)
: const SizedBox.shrink();
},
),
],
),
);
},
routerConfig: _goRouter,
Expand Down
2 changes: 2 additions & 0 deletions app/lib/main/init.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:example_domain/init.dart';
import 'package:example_data/init.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:notifications/init.dart';
import 'package:url_strategy/url_strategy.dart';

void init() async {
Expand All @@ -21,6 +22,7 @@ Future<void> initialize() async {
await CommonInit.initialize(getIt);
await DataInit.initialize(getIt);
await DomainInit.initialize(getIt);
await NotificationsInit.initialize(getIt);

// Example Module init
await ExampleDomainInit.initialize(getIt);
Expand Down
44 changes: 42 additions & 2 deletions app/lib/presentation/ui/pages/login/login_page.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import 'package:app/main/init.dart';
import 'package:app/presentation/themes/app_themes.dart';
import 'package:app/presentation/themes/local_theme.dart';
import 'package:app/presentation/themes/resources/app_theme_data.dart';
import 'package:common/core/resource.dart';
import 'package:domain/bloc/auth/auth_cubit.dart';
import 'package:domain/services/AuthService.dart';
import 'package:flutter/material.dart';
import 'package:app/presentation/ui/custom/app_theme_switch.dart';
import 'package:app/presentation/ui/custom/loading_screen.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:notifications/service/notification_service.dart';

class LoginPage extends StatelessWidget {
AuthService get _authService => getIt();

NotificationService get _notificationService => getIt();

const LoginPage({Key? key}) : super(key: key);

@override
Expand Down Expand Up @@ -41,6 +42,45 @@ class LoginPage extends StatelessWidget {
},
),
),
const SizedBox(height: 16),
SizedBox(
width: double.maxFinite,
child: ElevatedButton(
child: const Text('Success notification'),
onPressed: () {
_notificationService.notify(
'Success message',
NotificationStatus.success,
);
},
),
),
const SizedBox(height: 16),
SizedBox(
width: double.maxFinite,
child: ElevatedButton(
child: const Text('Error notification'),
onPressed: () {
_notificationService.notify(
'Error message',
NotificationStatus.error,
);
},
),
),
const SizedBox(height: 16),
SizedBox(
width: double.maxFinite,
child: ElevatedButton(
child: const Text('Information notification'),
onPressed: () {
_notificationService.notify(
'Information message',
NotificationStatus.information,
);
},
),
),
],
),
),
Expand Down
2 changes: 2 additions & 0 deletions app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ dependencies:
path: ../modules/common
data:
path: ../modules/data
notifications:
path: ../modules/notifications

# Remove example dependencies
example_data:
Expand Down
11 changes: 6 additions & 5 deletions modules/common/.flutter-plugins
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This is a generated file; do not edit or check into version control.
package_info_plus=/Users/fabianvalencia/.pub-cache/hosted/pub.dev/package_info_plus-4.2.0/
permission_handler=/Users/fabianvalencia/.pub-cache/hosted/pub.dev/permission_handler-10.4.5/
permission_handler_android=/Users/fabianvalencia/.pub-cache/hosted/pub.dev/permission_handler_android-10.3.6/
permission_handler_apple=/Users/fabianvalencia/.pub-cache/hosted/pub.dev/permission_handler_apple-9.1.4/
permission_handler_windows=/Users/fabianvalencia/.pub-cache/hosted/pub.dev/permission_handler_windows-0.1.3/
package_info_plus=/Users/juanrodriguez/.pub-cache/hosted/pub.dev/package_info_plus-8.3.0/
permission_handler=/Users/juanrodriguez/.pub-cache/hosted/pub.dev/permission_handler-11.4.0/
permission_handler_android=/Users/juanrodriguez/.pub-cache/hosted/pub.dev/permission_handler_android-12.1.0/
permission_handler_apple=/Users/juanrodriguez/.pub-cache/hosted/pub.dev/permission_handler_apple-9.4.7/
permission_handler_html=/Users/juanrodriguez/.pub-cache/hosted/pub.dev/permission_handler_html-0.1.3+5/
permission_handler_windows=/Users/juanrodriguez/.pub-cache/hosted/pub.dev/permission_handler_windows-0.2.1/
2 changes: 1 addition & 1 deletion modules/common/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"package_info_plus","path":"/Users/fabianvalencia/.pub-cache/hosted/pub.dev/package_info_plus-4.2.0/","native_build":true,"dependencies":[]},{"name":"permission_handler_apple","path":"/Users/fabianvalencia/.pub-cache/hosted/pub.dev/permission_handler_apple-9.1.4/","native_build":true,"dependencies":[]}],"android":[{"name":"package_info_plus","path":"/Users/fabianvalencia/.pub-cache/hosted/pub.dev/package_info_plus-4.2.0/","native_build":true,"dependencies":[]},{"name":"permission_handler_android","path":"/Users/fabianvalencia/.pub-cache/hosted/pub.dev/permission_handler_android-10.3.6/","native_build":true,"dependencies":[]}],"macos":[{"name":"package_info_plus","path":"/Users/fabianvalencia/.pub-cache/hosted/pub.dev/package_info_plus-4.2.0/","native_build":true,"dependencies":[]}],"linux":[{"name":"package_info_plus","path":"/Users/fabianvalencia/.pub-cache/hosted/pub.dev/package_info_plus-4.2.0/","native_build":false,"dependencies":[]}],"windows":[{"name":"package_info_plus","path":"/Users/fabianvalencia/.pub-cache/hosted/pub.dev/package_info_plus-4.2.0/","native_build":false,"dependencies":[]},{"name":"permission_handler_windows","path":"/Users/fabianvalencia/.pub-cache/hosted/pub.dev/permission_handler_windows-0.1.3/","native_build":true,"dependencies":[]}],"web":[{"name":"package_info_plus","path":"/Users/fabianvalencia/.pub-cache/hosted/pub.dev/package_info_plus-4.2.0/","dependencies":[]}]},"dependencyGraph":[{"name":"package_info_plus","dependencies":[]},{"name":"permission_handler","dependencies":["permission_handler_android","permission_handler_apple","permission_handler_windows"]},{"name":"permission_handler_android","dependencies":[]},{"name":"permission_handler_apple","dependencies":[]},{"name":"permission_handler_windows","dependencies":[]}],"date_created":"2024-05-02 16:35:44.210631","version":"3.19.3"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"package_info_plus","path":"/Users/juanrodriguez/.pub-cache/hosted/pub.dev/package_info_plus-8.3.0/","native_build":true,"dependencies":[]},{"name":"permission_handler_apple","path":"/Users/juanrodriguez/.pub-cache/hosted/pub.dev/permission_handler_apple-9.4.7/","native_build":true,"dependencies":[]}],"android":[{"name":"package_info_plus","path":"/Users/juanrodriguez/.pub-cache/hosted/pub.dev/package_info_plus-8.3.0/","native_build":true,"dependencies":[]},{"name":"permission_handler_android","path":"/Users/juanrodriguez/.pub-cache/hosted/pub.dev/permission_handler_android-12.1.0/","native_build":true,"dependencies":[]}],"macos":[{"name":"package_info_plus","path":"/Users/juanrodriguez/.pub-cache/hosted/pub.dev/package_info_plus-8.3.0/","native_build":true,"dependencies":[]}],"linux":[{"name":"package_info_plus","path":"/Users/juanrodriguez/.pub-cache/hosted/pub.dev/package_info_plus-8.3.0/","native_build":false,"dependencies":[]}],"windows":[{"name":"package_info_plus","path":"/Users/juanrodriguez/.pub-cache/hosted/pub.dev/package_info_plus-8.3.0/","native_build":false,"dependencies":[]},{"name":"permission_handler_windows","path":"/Users/juanrodriguez/.pub-cache/hosted/pub.dev/permission_handler_windows-0.2.1/","native_build":true,"dependencies":[]}],"web":[{"name":"package_info_plus","path":"/Users/juanrodriguez/.pub-cache/hosted/pub.dev/package_info_plus-8.3.0/","dependencies":[]},{"name":"permission_handler_html","path":"/Users/juanrodriguez/.pub-cache/hosted/pub.dev/permission_handler_html-0.1.3+5/","dependencies":[]}]},"dependencyGraph":[{"name":"package_info_plus","dependencies":[]},{"name":"permission_handler","dependencies":["permission_handler_android","permission_handler_apple","permission_handler_html","permission_handler_windows"]},{"name":"permission_handler_android","dependencies":[]},{"name":"permission_handler_apple","dependencies":[]},{"name":"permission_handler_html","dependencies":[]},{"name":"permission_handler_windows","dependencies":[]}],"date_created":"2025-07-31 12:46:11.975084","version":"3.24.5","swift_package_manager_enabled":false}
Loading
Loading