Skip to content
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

Addition of dismiss all toasts at once. #7

Closed
dzzirima opened this issue Apr 26, 2023 · 7 comments
Closed

Addition of dismiss all toasts at once. #7

dzzirima opened this issue Apr 26, 2023 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@dzzirima
Copy link

I suggests that we add a Toastification().dissmissAll() method , actually this package is cool I really enjoy using it. Or is it there but i cant seem to be finding it from the documentation .

@payam-zahedi payam-zahedi added the enhancement New feature or request label Apr 26, 2023
@payam-zahedi
Copy link
Owner

@dzzirima Thanks for adding this issue

you're right, we don't have dismiss all function for now

I'll try to add it ASAP in the next releases.

@payam-zahedi payam-zahedi self-assigned this Apr 26, 2023
@dzzirima
Copy link
Author

cool thanks , i will keep an eye on your updates

@payam-zahedi
Copy link
Owner

Hi @dzzirima,

I wanted to let you know that I've added the dismissAll function to the core #9. However, due to the numerous changes I've made, we'll need a major version to reflect the updates and prevent any conflicts with existing code.

Let me know if you have any questions or concerns.

@payam-zahedi
Copy link
Owner

@dzzirima

If you have any other useful ideas like this, please make sure to share them with me by creating an issue.

@dzzirima
Copy link
Author

dzzirima commented May 8, 2023

import 'package:famba_driver/common/custome_button.dart';
import 'package:famba_driver/constants/global_variables.dart';
import 'package:famba_driver/features/sidebar/widgets/profile_pic.dart';
import 'package:famba_driver/features/inTrip/screens/preview_trip.dart';
import 'package:famba_driver/features/trips/widgets/client_name.dart';
import 'package:famba_driver/models/trip_history.dart';
import 'package:flutter/material.dart';
// import 'package:linear_timer/linear_timer.dart';
import 'package:toastification/toastification.dart';

/// testing  code
///
class ToastManager {
  List<ToastificationItem> allToasts = [];
  void removeToast(ToastificationItem notification) {
    Toastification().dismiss(notification);
  }

  void removeAllToasts() {
    // print(allToasts.length);
    // for (var toast in allToasts) {
    //   removeToast(toast);
    // }
  }

  Trip trip = Trip(
    source: "Robert Mugabe RoadHarare, Zimbabwe",
    riderName: "D Zirima",
    destination: "3456 Julius Nyerere Way Harare, Zimbabwe",
    distance: 74,
    travellingTime: "30 min",
    tripDate: "2020-09-08",
    tripId: "410",
    isCompleted: false,
    tripAmount: 344,
    rating: 0,
    driverId: "123333",
    isArrived: false,
    readyForTrip: true,
    isPaymentDone: true,
  );

//function to remove a nofication

  void showRideRequestToast(BuildContext context) {
    late ToastificationItem notification;
    //add this toast to the list

    notification = toastification.showCustom(
      context: context,
      builder: (BuildContext context, ToastificationItem holder) {
        return Material(
          child: Container(
            height: 220,
            margin: const EdgeInsets.all(5),
            padding: const EdgeInsets.all(5),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(5),
              border: Border.all(
                color: Colors.green,
                width: 1,
              ),
              color: GlobalVariables.backgroundColor,
            ),
            child: Center(
              child: Column(
                children: [
                  Row(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      const Expanded(
                        flex: 1,
                        child: SizedBox(
                          // color: Colors.blue,
                          height: 110,
                          child: Column(children: [
                            ClientProfilePic(),
                            Spacer(),
                            ClientName(),
                          ]),
                        ),
                      ),
                      Expanded(
                        flex: 3,
                        child: SizedBox(
                          // color: Colors.white,
                          height: 150,
                          child: Column(
                            // mainAxisAlignment: MainAxisAlignment.start,
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              MyLocation(
                                address: trip.source,
                                icon: Icons.location_on,
                              ),
                              Container(
                                // margin: const EdgeInsets.only(top: 8, bottom: 15),
                                padding: const EdgeInsets.only(
                                  left: 32,
                                  right: 20,
                                ),
                                child: const Text(
                                  '.\n.\n',
                                  style: TextStyle(
                                    fontSize: 8,
                                    fontWeight: FontWeight.w900,
                                  ),
                                ),
                              ),
                              MyLocation(
                                address: trip.destination,
                                icon: Icons.location_searching,
                              ),
                              Container(
                                padding: const EdgeInsets.only(
                                    left: 32, right: 20, top: 10),
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.start,
                                  children: [
                                    const Text(
                                      "Estimated Amount:",
                                      style: TextStyle(
                                          fontSize: 15,
                                          fontWeight: FontWeight.w100),
                                    ),
                                    const Spacer(),
                                    const Icon(
                                      Icons.monetization_on,
                                      color: Colors.green,
                                    ),
                                    Text(
                                      '${trip.tripAmount}',
                                      style: const TextStyle(
                                        color: Colors.green,
                                        fontSize: 25,
                                        fontWeight: FontWeight.w800,
                                      ),
                                    )
                                  ],
                                ),
                              ),
                              Container(
                                padding: const EdgeInsets.only(
                                    left: 32, right: 20, top: 5),
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.start,
                                  children: [
                                    const Text(
                                      "Trip Distance",
                                      style: TextStyle(
                                          fontSize: 15,
                                          fontWeight: FontWeight.w100),
                                    ),
                                    const Spacer(),
                                    Text('${trip.distance} Km',
                                        style: const TextStyle(
                                          fontSize: 22,
                                          fontWeight: FontWeight.w800,
                                        ))
                                  ],
                                ),
                              ),
                            ],
                          ),
                        ),
                      ),
                    ],
                  ),
                  const Spacer(),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      CustomButton(
                          text: "Decline",
                          backgroundColor: GlobalVariables.whiteColor,
                          color: GlobalVariables.redColor,
                          onTap: () {
                            removeToast(notification);
                          }),
                      CustomButton(
                          text: "Accept",
                          onTap: () {
                            //once someone has accepted the trip we need to dismiss other toasts
                            // and navigate to new page
                            // Navigator.restorablePushNamed(
                            //   context,
                            //   TripReviewPage.routeName,
                            // );

                            removeAllToasts();
                          }),
                    ],
                  ),
                  const SizedBox(
                    height: 2,
                  ),
                  ToastTimerAnimationBuilder(
                    item: holder,
                    builder: (context, value, child) {
                      return Directionality(
                        textDirection:
                            Directionality.of(context) == TextDirection.ltr
                                ? TextDirection.rtl
                                : TextDirection.ltr,
                        child: LinearProgressIndicator(
                          value: value,
                          backgroundColor: GlobalVariables.lightblueColor,
                          color: GlobalVariables.backgroundColor,
                          minHeight: 6,
                        ),
                      );
                    },
                  ),
                ],
              ),
            ),
          ),
        );
      },
      autoCloseDuration: const Duration(seconds: 10),
      animationDuration: const Duration(milliseconds: 300),
      animationBuilder: (context, animation, child) {
        //return child;
        return FadeTransition(
          opacity: animation,
          child: child,
        );
      },
    );

    allToasts.add(notification);
  }
}
well am now trying to use the function how can I use it . here is my code

@payam-zahedi
Copy link
Owner

If you intend to use the dismissAll function in your app, please note that you need to obtain the package from GitHub instead of pub.dev. This is due to the fact that I have not released a new version, as there are some breaking changes to the package. Therefore, your pubspec.yaml file should look something like this:

dependencies:
  flutter:
    sdk: flutter

  toastification:
    git:
      url: https://github.com/payam-zahedi/toastification.git
      ref: main # branch name

@payam-zahedi
Copy link
Owner

I'm going to create a new release for next two weeks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Status: Done
Development

No branches or pull requests

2 participants