# Flutter, null safety, learning past examples

**URL:** <https://forums.kodeco.com/t/flutter-null-safety-learning-past-examples/157901>\
**Category:** Flutter Apprentice\
**Created:** [November 18, 2021, 9:38am UTC](https://forums.kodeco.com/t/flutter-null-safety-learning-past-examples/157901 "2021-11-18T09:38:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![paristocode](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/paristocode/32/81494_2.png) [@paristocode](https://forums.kodeco.com/u/paristocode)\
**Post date:** [November 18, 2021, 9:38am UTC](https://forums.kodeco.com/t/flutter-null-safety-learning-past-examples/157901/1 "2021-11-18T09:38:30Z")

</div>

Hi, I am trying to learn from looking at past examples but I noticed such past examples always get flagged with null safety issues. Some are obvious fixes, but others are much harder. For example, with key and controllers, like ScrollController. Are there any materials available you can recommend to understand ways to fix null safety problems, for variables that are not obvious?

---

<div class="post-metadata">

**Author:** ![jomoka](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jomoka/32/109828_2.png) [@jomoka](https://forums.kodeco.com/u/jomoka)\
**Post date:** [November 18, 2021, 10:29am UTC](https://forums.kodeco.com/t/flutter-null-safety-learning-past-examples/157901/2 "2021-11-18T10:29:32Z")

</div>

@paristocode check out:

Really in depth reading on null safety:

> **[Understanding null safety](https://dart.dev/null-safety/understanding-null-safety)**
>
> A deep dive into Dart language and library changes related to null safety.

As for scroll controller, it really depends on how you initialize it.

```auto
class _MyHomeState extends State<MyHome> {
  ScrollController controller;
  List<String> items = List.generate(100, (index) => 'Hello $index');

  @override
  void initState() {
    super.initState();
    controller = ScrollController()..addListener(_scrollListener);
  }

  @override
  void dispose() {
    controller.removeListener(_scrollListener);
    super.dispose();
  }

}

```

Null safety in this case will say that Hi`ScrollController` is not initialized yet! However since you know that you instantiate your scrollController in initState().

You can place the keyword `lazy` in front of your scrollController property. This let’s dart know that it will be initialized somewhere down the road.

---

<div class="post-metadata">

**Author:** ![olivaxa](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/olivaxa/32/81494_2.png) [@olivaxa](https://forums.kodeco.com/u/olivaxa)\
**Post date:** [November 18, 2021, 12:15pm UTC](https://forums.kodeco.com/t/flutter-null-safety-learning-past-examples/157901/3 "2021-11-18T12:15:24Z")

</div>

Hi.

If you are following a step by step training, it should be great to create 2 projects.

1. with null safety and recent changes (text buttons…)

2. without null safety and with deprecated widgets

Step by step corrections instead of global migration is easier for me.
