flutterdartoopflutter-lints

"AVOID using library private types in public APIs" - lint warning, even in in cookbook examples?


I noticed the style error warning https://dart-lang.github.io/linter/lints/library_private_types_in_public_api.html pop up in some of my code but also in the some of the official Flutter/Dart documentation/cookbook examples; e.g. at https://docs.flutter.dev/cookbook/animation/animated-container for

...
class AnimatedContainerApp extends StatefulWidget {
  const AnimatedContainerApp({super.key});

  @override
  _AnimatedContainerAppState createState() => _AnimatedContainerAppState();
}

class _AnimatedContainerAppState extends State<AnimatedContainerApp> {
...
 

example of warning

My understanding of OOP and its nomenclature is sketchy at best and I don't quite understand the warning, but my actual question is, are the examples with this warning wrong, or sub-ideal - or does that style issue only apply in certain contexts that is perhaps not relevant to the examples and or I should ignore it, or is it an result of flutter/dart versions or some such or other?


Solution

  • From the latest docs:

    Subclasses should override this method to return a newly created
    instance of their associated [State] subclass:
    
    @override
    State<MyWidget> createState() => _MyWidgetState();
    

    So you should replace

    @override
    _AnimatedContainerAppState createState() => _AnimatedContainerAppState();
    

    with

    @override
    State<AnimatedContainerApp> createState() => _AnimatedContainerAppState();