Skip to content

Handle requires Scrollable being present in the widget tree after upgrade to Flutter 3.7 #3

@ukasz123

Description

@ukasz123

Flutter 3.7 introduced change to the behavior of Scrollable.of - it requires the Scrollable being present in the parent tree and returns non-nullable value.

This makes some uses of Handle widget to crash when accessing parent Scrollable (here). The simple solution is to replace Scrollable.of with Scrollable.maybeOf.

Minimal code reproducing the issue

import 'package:flutter/material.dart';
import 'package:implicitly_animated_reorderable_list_2/implicitly_animated_reorderable_list_2.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Flutter Demo',
      home: DemoPage(),
    );
  }
}

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

  @override
  State<DemoPage> createState() => _DemoPageState();
}

class _DemoPageState extends State<DemoPage> {
  var items = List.generate(15, (index) => "Index $index");

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ImplicitlyAnimatedReorderableList(
        items: items,
        itemBuilder: (context, animation, item, index) => Reorderable(
          key: ValueKey(item),
          builder: (context, _, __) => ListTile(
            leading: const Handle(
                child: Padding(
              padding: EdgeInsets.all(8),
              child: Icon(Icons.drag_handle_outlined),
            )),
            title: Text(item),
          ),
        ),
        areItemsTheSame: (l, r) => l == r,
        onReorderFinished:
            (String item, int from, int to, List<String> newItems) {
          setState(() {
            items = newItems;
          });
        },
      ),
    );
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions