Created
April 21, 2025 17:15
-
-
Save arxdeus/585eb6dedc646ea46982b826b0456ab7 to your computer and use it in GitHub Desktop.
unsafe_variance lint on `builder`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/widgets.dart'; | |
class SomeBuilder<T> extends StatefulWidget { | |
const SomeBuilder({ | |
required this.initialValue, | |
required this.builder, | |
this.child, | |
super.key, // ignore: unused_element | |
}); | |
final T initialValue; | |
final ValueWidgetBuilder<T> builder; // LINT - This type is unsafe: a type parameter occurs in a non-covariant position | |
final Widget? child; | |
@override | |
State<SomeBuilder<T>> createState() => _SomeBuilderState<T>(); | |
} | |
/// State for widget SomeBuilder. | |
class _SomeBuilderState<T> extends State<SomeBuilder<T>> { | |
late final ValueNotifier<T> _notifier = ValueNotifier(widget.initialValue); | |
@override | |
Widget build(BuildContext context) => ValueListenableBuilder( | |
valueListenable: _notifier, | |
builder: (context, value, child) => widget.builder(context, value, child), | |
child: widget.child, | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment