BrianTV98 / slider_captcha

MIT License
34 stars 16 forks source link

Error: RangeError: max must be in range 0 < max ≤ 2^32, was -20 #22

Closed nemr0 closed 8 months ago

nemr0 commented 1 year ago

I get this error in console on widget create (when shown on screen). my guess that it is related with me loading the image from network this is how I use the widget:

class SliderCaptchaDialog extends HookWidget {
  const SliderCaptchaDialog(this.date, {Key? key}) : super(key: key);
  final String date;

  @override
  Widget build(BuildContext context) {
    final controller = useState(SliderController());
    final isLoading = useState(true);
    useEffect(() {
      if (isLoading.value == false) {
        controller.value.create.call();
      }
      return null;
    }, [isLoading.value]);
    changeLoadingState() async {
      await Future.delayed(const Duration(seconds: 1));
      isLoading.value = false;
    }

    return CupertinoAlertDialog(
      content: DefaultTextStyle(
        style: kTSAgreement,
        child: SliderCaptcha(
          controller: controller.value,
          space: 20,
          title: 'Are You A Robot? :\\',
          colorBar: kPrimaryColor,
          colorCaptChar: kPrimaryColor,
          image: Image.network('kURL$date',
              fit: BoxFit.fitWidth,
              //     frameBuilder: (_, image, loadingBuilder, __) {
              //   if (loadingBuilder == null) {
              //     return const Center(
              //       child: CupertinoActivityIndicator(),
              //     );
              //   } else {
              //     return image;
              //   }
              // },
              loadingBuilder: (BuildContext context, Widget child,
                  ImageChunkEvent? loadingProgress) {
            if (loadingProgress == null) {
              changeLoadingState();

              return child;
            }
            return const Center(
              child: CupertinoActivityIndicator(),
            );
          }),
          onConfirm: (bool value) async {
            if (value) {
              Navigator.pop<bool>(context, value);
            } else {
              controller.value.create.call();
            }
          },
        ),
      ),
    );
  }
}
BrianTV98 commented 1 year ago

@nemr0 Thank you for contributing an issue to this library. This library has not been tested with Image.network. You can handle it in another way. That is to download this image and save it to local storage. Then use Image.file to read it.

nemr0 commented 1 year ago

@nemr0 Thank you for contributing an issue to this library. This library has not been tested with Image.network. You can handle it in another way. That is to download this image and save it to local storage. Then use Image.file to read it.

Thank you for your fast reply, but Image.file() is not supported by flutter web

BrianTV98 commented 1 year ago

Dear @nemr0!

Through the code you presented. I see you need to handle builder, placeholder, eror,..v...etc. So I decided to update the library to allow widgets instead of just images. By that change. You can use libraries available on pub.dev such as cacheNetwork,..v.v. to handle .

I updated this in version 0.1.10. Please check and feedback.

If you find my library useful please like it on pubdev, github repo or donate to me via paypall. It will give me extra motivation to continue to develop and maintain the library throught paypall