Add message notification snackbar

This commit is contained in:
Thomas Fransolet 2021-05-06 20:55:52 +02:00
parent 69664c4bec
commit 6b0f3145c1
9 changed files with 55 additions and 84 deletions

View File

@ -1,30 +1,22 @@
import 'package:flutter/material.dart';
class MessageNotification extends StatelessWidget {
final VoidCallback onReplay;
const MessageNotification({Key key, this.onReplay}) : super(key: key);
@override
Widget build(BuildContext context) {
return Card(
margin: const EdgeInsets.symmetric(horizontal: 4),
child: SafeArea(
child: ListTile(
leading: SizedBox.fromSize(
size: const Size(40, 40),
child: Text("YOLO")),
title: Text('Lily MacDonald'),
subtitle: Text('Do you want to see a movie?'),
trailing: IconButton(
icon: Icon(Icons.reply),
onPressed: () {
///TODO i'm not sure it should be use this widget' BuildContext to create a Dialog
///maybe i will give the answer in the future
if (onReplay != null) onReplay();
}),
),
showNotification (Color backgroundColor, Color textColor, String text, BuildContext context) {
final snackBar = SnackBar(
behavior: SnackBarBehavior.floating,
duration: const Duration(milliseconds: 1500),
width: 280.0, // Width of the SnackBar.
backgroundColor: backgroundColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
);
}
padding: const EdgeInsets.symmetric(
horizontal: 8.0, // Inner padding for SnackBar content.
),
content: Text(
text,
textAlign: TextAlign.center,
style: TextStyle(color: textColor),
)
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}

View File

View File

@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:manager_app/Components/confirmation_dialog.dart';
import 'package:manager_app/Components/fetch_section_icon.dart';
import 'package:manager_app/Components/message_notification.dart';
import 'package:manager_app/Components/multi_select_container.dart';
import 'package:manager_app/Components/multi_string_input_container.dart';
import 'package:manager_app/Components/rounded_button.dart';
@ -10,7 +11,6 @@ import 'package:manager_app/app_context.dart';
import 'package:manager_app/client.dart';
import 'package:manager_app/constants.dart';
import 'package:managerapi/api.dart';
import 'package:overlay_support/overlay_support.dart';
import 'package:provider/provider.dart';
import 'package:intl/intl.dart';
@ -259,14 +259,7 @@ class _SectionDetailScreenState extends State<SectionDetailScreen> {
managerAppContext.selectedSection = section;
appContext.setContext(managerAppContext);
// popup a toast.
toast('La section a été sauvegardée avec succès');
// show a notification at top of screen.
/*showSimpleNotification(
Text("La configuration a été sauvegardée avec succès"),
position: NotificationPosition.bottom,
background: Colors.green);*/
showNotification(Colors.green, kWhite, 'La section a été sauvegardée avec succès', context);
}
getSpecificData(SectionDTO sectionDTO, AppContext appContext) {

View File

@ -5,6 +5,7 @@ import 'package:flutter/painting.dart';
import 'package:manager_app/Components/color_picker_input_container.dart';
import 'package:manager_app/Components/confirmation_dialog.dart';
import 'package:manager_app/Components/fetch_section_icon.dart';
import 'package:manager_app/Components/message_notification.dart';
import 'package:manager_app/Components/multi_select_container.dart';
import 'package:manager_app/Components/rounded_button.dart';
import 'package:manager_app/Components/string_input_container.dart';
@ -14,7 +15,6 @@ import 'package:manager_app/app_context.dart';
import 'package:manager_app/client.dart';
import 'package:manager_app/constants.dart';
import 'package:managerapi/api.dart';
import 'package:overlay_support/overlay_support.dart';
import 'package:provider/provider.dart';
import 'package:intl/intl.dart';
@ -361,14 +361,7 @@ class _ConfigurationDetailScreenState extends State<ConfigurationDetailScreen> {
managerAppContext.selectedConfiguration = configuration;
appContext.setContext(managerAppContext);
// popup a toast.
toast('La configuration a été sauvegardée avec succès');
// show a notification at top of screen.
/*showSimpleNotification(
Text("La configuration a été sauvegardée avec succès"),
position: NotificationPosition.bottom,
background: Colors.green);*/
showNotification(Colors.green, kWhite, 'La configuration a été sauvegardée avec succès', context);
}
Future<ConfigurationDTO> getConfiguration(ConfigurationDetailScreen widget, Client client) async {

View File

@ -1,11 +1,11 @@
import 'package:flutter/material.dart';
import 'package:manager_app/Components/message_notification.dart';
import 'package:manager_app/Components/rounded_button.dart';
import 'package:manager_app/Components/string_input_container.dart';
import 'package:manager_app/Models/managerContext.dart';
import 'package:manager_app/app_context.dart';
import 'package:manager_app/constants.dart';
import 'package:managerapi/api.dart';
import 'package:overlay_support/overlay_support.dart';
void showNewConfiguration(AppContext appContext, BuildContext context) {
ConfigurationDTO configurationDTO = new ConfigurationDTO();
@ -83,7 +83,6 @@ void create(ConfigurationDTO configurationDTO, AppContext appContext, context) a
managerAppContext.selectedConfiguration = null;
appContext.setContext(managerAppContext);
// popup a toast.
toast('La configuration a été créée avec succès');
showNotification(Colors.green, kWhite, 'La configuration a été créée avec succès', context);
}
}

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:manager_app/Components/message_notification.dart';
import 'package:manager_app/Components/multi_select_container.dart';
import 'package:manager_app/Components/rounded_button.dart';
import 'package:manager_app/Components/string_input_container.dart';
@ -6,7 +7,6 @@ import 'package:manager_app/Models/managerContext.dart';
import 'package:manager_app/app_context.dart';
import 'package:manager_app/constants.dart';
import 'package:managerapi/api.dart';
import 'package:overlay_support/overlay_support.dart';
void showNewSection(ConfigurationDTO configurationDTO, AppContext appContext, BuildContext context) {
SectionDTO sectionDTO = new SectionDTO();
@ -100,7 +100,6 @@ void create(SectionDTO sectionDTO, AppContext appContext, BuildContext context)
managerAppContext.selectedConfiguration.sectionIds.add(newSection.id);
appContext.setContext(managerAppContext);
// popup a toast.
toast('La section a été créée avec succès');
showNotification(Colors.green, kWhite, 'La section a été créée avec succès !', context);
}
}

View File

@ -1,13 +1,10 @@
import 'package:manager_app/Models/managerContext.dart';
import 'package:manager_app/Screens/Main/main_screen.dart';
import 'package:managerapi/api.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'Screens/login_screen.dart';
import 'app_context.dart';
import 'client.dart';
import 'constants.dart';
import 'package:overlay_support/overlay_support.dart';
void main() {
String initialRoute;
@ -37,27 +34,25 @@ class _MyAppState extends State<MyApp> {
Widget build(BuildContext context) {
return ChangeNotifierProvider<AppContext>(
create: (_) => AppContext(widget.managerAppContext),
child: OverlaySupport(
child: MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Manager App Demo',
initialRoute: widget.initialRoute,
/*supportedLocales: [
const Locale('en', 'US'),
//const Locale('fr', 'FR'),
],*/
theme: ThemeData(
primarySwatch: Colors.blue,
scaffoldBackgroundColor: kBackgroundColor,
//fontFamily: "Vollkorn",
textTheme: TextTheme(bodyText1: TextStyle(color: kBodyTextColor)),
visualDensity: VisualDensity.adaptivePlatformDensity,
),
routes: {
'/welcome': (context) => LoginScreen(),
'/main': (context) => MainScreen()
}
),
child: MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Manager App Demo',
initialRoute: widget.initialRoute,
/*supportedLocales: [
const Locale('en', 'US'),
//const Locale('fr', 'FR'),
],*/
theme: ThemeData(
primarySwatch: Colors.blue,
scaffoldBackgroundColor: kBackgroundColor,
//fontFamily: "Vollkorn",
textTheme: TextTheme(bodyText1: TextStyle(color: kBodyTextColor)),
visualDensity: VisualDensity.adaptivePlatformDensity,
),
routes: {
'/welcome': (context) => LoginScreen(),
'/main': (context) => MainScreen()
}
),
);
}

View File

@ -56,7 +56,7 @@ packages:
name: cupertino_icons
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
version: "1.0.3"
fake_async:
dependency: transitive
description:
@ -116,6 +116,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10"
material_segmented_control:
dependency: "direct main"
description:
name: material_segmented_control
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.2"
meta:
dependency: transitive
description:
@ -137,13 +144,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
overlay_support:
dependency: "direct main"
description:
name: overlay_support
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5-hotfix1"
path:
dependency: transitive
description:

View File

@ -26,10 +26,10 @@ dependencies:
rxdart: 0.22.0
provider: ^5.0.0
overlay_support: 1.0.5-hotfix1
auto_size_text: ^2.1.0
flutter_colorpicker: ^0.4.0
multiselect_formfield: ^0.1.6
material_segmented_control: ^3.1.2
managerapi:
path: manager_api