Codelessly / ResponsiveFramework

Easily make Flutter apps responsive. Automatically adapt UI to different screen sizes. Responsiveness made simple. Demo: https://gallery.codelessly.com/flutterwebsites/minimal/
https://codelessly.com
MIT License
1.25k stars 150 forks source link

ResponsiveVisibility error #169

Closed MarceloRab closed 6 months ago

MarceloRab commented 7 months ago

... pub.dev\responsive_framework-1.1.1\lib\responsive_value.dart

=> Throws error when screen exceeds size 600

@override
  Widget build(BuildContext context) {
    return AppBar(
      title: const Text('HomeView'),
      centerTitle: true,
      leading: ResponsiveVisibility(
        visible: false,
        hiddenConditions: [Condition.largerThan(name: TABLET, value: 600)],
        child: IconButton(
          icon: const Icon(Icons.menu),
          onPressed: () {},
        ),
      ),

...

bool? visibleValue = visible; ...

@override
  Widget build(BuildContext context) {
    List<Condition> conditions = [];
    bool? visibleValue = visible;  //=>🚩 Here he received a boolean

...

In the bottom line it throws an error  //🔻
    visibleValue = ResponsiveValue(context,
            defaultValue: visibleValue, conditionalValues: conditions)
        .value;

= > Exception has occurred. _TypeError (type 'int' is not a subtype of type 'bool?')

MarceloRab commented 7 months ago

This made it even more elegant

return AppBar(
      title: const Text('HomeView'),
      centerTitle: true,
      leading: Visibility(
        visible: !ResponsiveBreakpoints.of(context).largerThan(TABLET),
        child: IconButton(
          icon: const Icon(Icons.menu),
          onPressed: () {},
        ),
      ),
rayliverified commented 6 months ago

Thank you for reporting.

The issue was a Dart language limitation that did not support generic type nullability. With the latest Flutter v3.19, nullable generic types now flow through correctly and the awkwardness can be removed.

We're back to the original API where a constant condition can be passed without forcibly attaching a value!

image