ResponsiveVisibility error
... pub.dev\responsive_framework-1.1.1\lib\responsive_value.dart
=> Throws error when screen exceeds size 600
- my code
@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: () {},
),
),
- code classe ResponsiveVisibility
...
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?')
- Suggestion
=>>> No need to "?" in [visibleValue] and this parameter cannot receive an int.
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: () {},
),
),
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!