Repository: flutter
Issue: Problems with scrolling to the end of the list using maxScrollExtent
Labels: framework,f: scrolling,has reproducible steps,P2,found in release: 3.10,found in release: 3.12,team-framework,triaged-framework

### Is there an existing issue for this?

- [X] I have searched the [existing issues](https://github.com/flutter/flutter/issues)
- [X] I have read the [guide to filing a bug](https://flutter.dev/docs/resources/bug-reports)

### Steps to reproduce

Hello! I am running into an issue with a `ListView.builder` (or anything scrollable that builds widgets on demand). I try to scroll to the `_scrollController.position.maxScrollExtent` and it will not scroll to the end of the list, if your current scroll offset is not the `maxScrollExtent` - i.e. if I don't scroll the list at all, and only add items, everything scrolls correctly, but as soon as I scroll the list manually to the very top, or middle of the larger list, and add an item - it will not scroll to the very end. 

Interesting observation, if I manually scroll the list and scroll animation is still in progress after I release the finger, and I add the item - it will also scroll correctly, so it stops working only when scroll finishes, and you try to add an item (will be visible on a video).

Another observation, if the height of the items is the same, the list will not scroll to the exactly last item (newly added). However, if the height is dynamic, the list will not scroll to the random amount of offset, sometimes a couple of items, that were already there before + newly added item (will be visible on a video).

### Expected results

I would expect the list to scroll to the very end when I call scroll to `_scrollController.position.maxScrollExtent`, no matter whether I start from the start, middle or end of the list, and whether scroll animation is running or not.

### Actual results

List scrolls to the very end of the list, if I call the scroll when I am already at the current end of the list, or when I manually scroll the list, while scroll animation is running, it will also scroll to the very end of the list.

### Code sample

<details><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final _list = List.generate(2, (index) => 'Item $index');
  final _scrollController = ScrollController();

  void _addItem() {
    setState(() {
      _list.add('Item ${_list.length}');
    });

    SchedulerBinding.instance.addPostFrameCallback((_) {
      _scrollController.animateTo(
        _scrollController.position.maxScrollExtent,
        duration: const Duration(milliseconds: 250),
        curve: Curves.easeOut,
      );
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: ListView.builder(
          controller: _scrollController,
          itemCount: _list.length,
          itemBuilder: (context, index) => ListTile(
            title: Text(_list[index]),
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _addItem,
        child: const Icon(Icons.add),
      ),
    );
  }
}
```

In a video I also show example with different item heights, the same code, I just change string I add to the list to some lorem, adding `flutter_lorem` dependency to pubspec. Example with lorem:

```dart
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_lorem/flutter_lorem.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final _list = List.generate(
    2,
    (index) => lorem(paragraphs: 1, words: Random().nextInt(30) + 1),
  );
  final _scrollController = ScrollController();

  void _addItem() {
    setState(() {
      _list.add(lorem(paragraphs: 1, words: Random().nextInt(30) + 1));
    });

    SchedulerBinding.instance.addPostFrameCallback((_) {
      _scrollController.animateTo(
        _scrollController.position.maxScrollExtent,
        duration: const Duration(milliseconds: 250),
        curve: Curves.easeOut,
      );
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: ListView.builder(
          controller: _scrollController,
          itemCount: _list.length,
          itemBuilder: (context, index) => ListTile(
            title: Text(_list[index]),
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _addItem,
        child: const Icon(Icons.add),
      ),
    );
  }
}
``` 

</details>


### Screenshots or Video

<details>
<summary>[CORRECT] behaviour if I don't touch the list and only add items</summary>
<video src='https://github.com/flutter/flutter/assets/14123304/444d19bc-5b96-4051-a40e-dabcdc1e1b51' width=180 />
</details>
<details>
<summary>[CORRECT] behaviour if I add an item while scroll animation is running</summary>
<video src='https://github.com/flutter/flutter/assets/14123304/d5e36db8-e5e8-445b-894f-fcb63f0333bc' width=180 />
</details>
<details>
<summary>[NOT CORRECT] behaviour if I add an item and I am in the middle or beginning of the list and animation is not running</summary>
<video src='https://github.com/flutter/flutter/assets/14123304/875edcb8-a7f8-43c3-abb0-e322461a0601' width=180 />
</details>
<details>
<summary>[NOT CORRECT] behaviour as above, but different with different item heights</summary>
<video src='https://github.com/flutter/flutter/assets/14123304/81491f3d-66c9-4188-8052-bacbe5b73b06' width=180 />
</details>

### Logs

<details><summary>Logs</summary>

I just ran `flutter create bug`, verbose logs contained apple certificates and file was enormous to edit, so I will not paste it here. Let me know if this will be helpful to include, however as I am saying, I just created an empty project using `Flutter 3.10.5` and created minimum reproducible example in `main.dart`. 

</details>


### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.10.5, on macOS 13.4.1 22F82 darwin-arm64, locale
    en-GB)
    • Flutter version 3.10.5 on channel stable at /Users/alex/Developer/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 796c8ef792 (2 weeks ago), 2023-06-13 15:51:02 -0700
    • Engine revision 45f6e00911
    • Dart version 3.0.5
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/alex/Library/Android/sdk
    • Platform android-33, build-tools 31.0.0
    • ANDROID_HOME = /Users/alex/Library/Android/sdk
    • Java binary at: /Applications/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      17.0.6+0-17.0.6b802.4-9586694)

[✓] VS Code (version 1.79.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.66.0

[✓] VS Code (version 1.80.0-insider)
    • VS Code at /Applications/Visual Studio Code - Insiders.app/Contents
    • Flutter extension version 3.67.20230601

[✓] Connected device (3 available)
    • iPhone 14 Pro Max (mobile) • 8E99FC05-DB38-4653-A841-882EB500BA7B • ios
      • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
    • macOS (desktop)            • macos                                •
      darwin-arm64   • macOS 13.4.1 22F82 darwin-arm64
    • Chrome (web)               • chrome                               •
      web-javascript • Google Chrome 114.0.5735.198

[✓] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>