payam-zahedi / toastification

Toastification is a Flutter package for displaying customizable toast messages. It provides predefined widgets for success, error, warning, and info messages, as well as a custom widget for flexibility. With Toastification, you can add and manage multiple toast messages at the same time with ease.
https://payamzahedi.com/toastification/
BSD 3-Clause "New" or "Revised" License
587 stars 45 forks source link

should also be able to set the width of an toast item through showCustom function #93

Closed prashant-singh-maersk closed 7 months ago

prashant-singh-maersk commented 8 months ago

Describe the solution you'd like Currently we can set the width of toast item only through ToastificationConfigProvider, can we also have width argument in the show and showCustom function which would set the width of the item

Additional context I am trying to make a reusable flutter toast widget, I don't want to ask user to wrap in a ToastificationConfigProvider

payam-zahedi commented 8 months ago

Hey @prashant-singh-maersk Can you provide a simple code for better understanding?

payam-zahedi commented 8 months ago

If you want to set width to your toast via showCustom

Why you are not using SizedBox ?

prashant-singh-maersk commented 8 months ago

Hey @prashant-singh-maersk Can you provide a simple code for better understanding?

something like

toastification.showCustom(
      context: context,
      alignment: position,
      width: 500,
      .....
);
prashant-singh-maersk commented 8 months ago

If you want to set width to your toast via showCustom

Why you are not using SizedBox?

We can not set the width using the sized box, because the package is setting the width of the overlay entry through ToastificationConfigProvider or ToastificationConfig by default, so no matter what width we set through widgets, it will never be more than the constraint set at the parent level.

image

check line 196-200

payam-zahedi commented 7 months ago

you want something like this right?

image

example code:

 toastification.showCustom(
    builder: (BuildContext context, ToastificationItem holder) {
      return Align(
        alignment: Alignment.centerRight,
        child: Container(
          color: Colors.blue,
          height: 100,
          width: 300,
          margin: const EdgeInsets.all(8),
        ),
      );
    },
  );
prashant-singh-maersk commented 7 months ago

you want something like this right?

image

example code:

 toastification.showCustom(
    builder: (BuildContext context, ToastificationItem holder) {
      return Align(
        alignment: Alignment.centerRight,
        child: Container(
          color: Colors.blue,
          height: 100,
          width: 300,
          margin: const EdgeInsets.all(8),
        ),
      );
    },
  );

I understand, this would work if your width is less than 400. (The above example has a width 300) but I'll not be able to set the width to more than 400, try to give 600 width

payam-zahedi commented 7 months ago

Did you use config provider?

With the config provider, you can set the width of the whole overlay

I think this is the thing that you want

https://github.com/payam-zahedi/toastification?tab=readme-ov-file#globaldefault-configuration

payam-zahedi commented 7 months ago

@prashant-singh-maersk Maybe I need to rename itemWidth in the config Provider to make it more readable.

prashant-singh-maersk commented 7 months ago

@payam-zahedi I appreciate your patience. I am aware of the config provider, yes we can set the width using config provider. but wanted to know if we can give a width option in the showCustom function itself,

eg: alignment can be given in config provider and showCustom function, showCustom property one takes the priority

same way can we have a width option in showCustom function ?

payam-zahedi commented 7 months ago

I guess there is a miss understanding here

we have itemWidth in the config file that we use to set the width of the animated list that we have in our overlay

and you can use show custom and set some width to your toast

these are different

we can not change the width of the animated list every time that you want to build a toast

imagine if you could set some width in the show custom method it would change all the width of the toasts

payam-zahedi commented 7 months ago

I guess we can close this issue for now

but, feel free to ask any question about it