Open FrenkyDema opened 1 year ago
I need to know what code you are referring to so I can provide more specific assistance. Can you please give me more information about the code you are working on and what you are trying to accomplish? Additionally, if you have an error message that you need help with, please provide that as well so I can assist you more effectively.
When I call the function to create a toast several times, only the first one is shown and after it is closed, the previously created toasts are shown.
https://github.com/bataa07/animated_toast_list/assets/67586090/c1d3f2b7-5811-4f18-92bd-79674a7ae7c1
To test I created a GestureDetector
which generates a confirmation toast when touched:
GestureDetector(
onTap: () {
debugPrint("test message");
context.showToast(
MyToastModel(
message: ToastType.success.name,
type: ToastType.success,
),
);
},
child: const SizedBox(
height: 20,
width: 50,
child: ColoredBox(color: Colors.blue)),
),
The problem only occurs with the GestureDetector
, I tried with a normal button and it seems to work.
If you want, I'll also show you all the various codes implemented (e.g. MyToastModel
)
I don't think the error will occur when only GestureDetector
is used. Please show your code in more detail. If possible, it would be great if you could show the pubspec.yaml
file.
Okay, sorry for the wait. Here is the code that causes the problems described before:
main.dart
import 'package:flutter/material.dart';
import 'package:test_project/popup_widget.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async => false,
child: Scaffold(
body: Center(
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
GestureDetector(
onTap: () {
debugPrint("test messaggio");
PopupWidget.show(
context,
"Errore",
type: PopupType.error,
errorDetails: "Errore dettagliato",
);
},
child: const ColoredBox(
color: Colors.blue,
child: Padding(
padding: EdgeInsets.all(20),
child: Text(
"Click me!",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
),
),
),
],
),
),
),
);
}
}
popup_widget.dart
import 'package:flutter/material.dart';
import 'error_page.dart';
enum PopupType { info, error, confirmation }
class PopupWidget {
static void show(
BuildContext context,
String message, {
PopupType type = PopupType.info,
String? errorDetails, // parametro opzionale per le informazioni dettagliate
}) {
Color backgroundColor = Colors.blue;
IconData iconData = Icons.info;
switch (type) {
case PopupType.info:
backgroundColor = Colors.blue;
iconData = Icons.info;
break;
case PopupType.error:
backgroundColor = Colors.red;
iconData = Icons.error;
break;
case PopupType.confirmation:
backgroundColor = Colors.green;
iconData = Icons.check_circle;
break;
}
final snackBar = SnackBar(
duration: const Duration(seconds: 10),
backgroundColor: Colors.transparent,
elevation: 0,
behavior: SnackBarBehavior.floating,
content: Align(
alignment: Alignment.bottomRight,
child: Container(
margin: const EdgeInsets.only(bottom: 16, right: 16),
decoration: BoxDecoration(
color: backgroundColor,
borderRadius: BorderRadius.circular(10),
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(
iconData,
color: Colors.white,
),
),
Text(
message,
style: const TextStyle(
color: Colors.white,
fontSize: 16.0,
),
),
if (errorDetails != null)
GestureDetector(
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'Show Details',
style: TextStyle(
color: Colors.white,
decoration: TextDecoration.underline,
),
),
),
onTap: () {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) =>
ErrorPage(error: errorDetails),
),
);
},
),
Align(
alignment: Alignment.topRight,
child: IconButton(
icon: const Icon(Icons.close),
color: Colors.white,
onPressed: () {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
},
),
),
],
),
],
),
),
),
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
}
error_page.dart
import 'package:flutter/material.dart';
class ErrorPage extends StatelessWidget {
static String pageRoot = "/error_page";
const ErrorPage({
Key? key,
this.error,
}) : super(key: key);
final Object? error;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Error page'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"ERROR during ${error?.toString()}.",
style: const TextStyle(color: Colors.red),
),
],
),
),
);
}
Future<void> waitAndHome() async {}
}
pubspec.yaml
name: test_project
description: A new Flutter project.
publish_to: 'none'
version: 1.0.0+1
environment:
sdk: ">=2.17.6 <3.0.0"
dependencies:
flutter:
sdk: flutter
animated_toast_list: ^1.0.2
cupertino_icons: ^1.0.5
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.2
flutter:
uses-material-design: true
I implemented the library, but after showing the first toast, the addition of other toasts does not lead to the update of the toast list and their display The code is practically the same as that found in the documentation