2

I know there are a lot of these errors on the Internet, but this one made me curious. I created a very simple design (MRE) to demonstrate it.

This issue seem to happen when I use the Shell Router from go_router to route child widgets. The design runs smoothly when I run it myself.

To demonstrate it, let me start by sharing some of the boilerplate code:

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

void main() => runApp(const MyApp());

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

  @override
  Widget build(BuildContext context) =>
      MaterialApp.router(title: "Flutter Demo", routerConfig: router);
}

My super simple design with a BaseWidget, that will be shared among a few widgets, and a BodyWidget with a big height:

class BaseWidget extends StatelessWidget {
  final Widget child;
  const BaseWidget({super.key, required this.child});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: ListView(children: [
      const FlutterLogo(size: 80),
      child,
    ]));
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Column(
      children: List.generate(100, (index) {
        return Text(
          "Any text ${index + 1}",
          style: Theme.of(context).textTheme.headlineSmall,
        );
      }),
    );
  }
}

If I just configure everything directly I don't have any problems. But when I use Shell Route to configure my BaseWidget to be shared across my routes, the configuration no longer works.

To demonstrate that I'll be sharing the last piece of code containing the router with two routes: the first can be accessed through the Direct button. This one works without any problem. The second uses Shell Route and will throw some errors:

final GoRouter router = GoRouter(
  routes: <RouteBase>[
    GoRoute(
      path: "/",
      builder: (context, state) => BaseWidget(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(
              onPressed: () => context.go("/full"),
              child: const Text("Direct"),
            ),
            const SizedBox(width: 16),
            ElevatedButton(
              onPressed: () => context.go("/shell"),
              child: const Text("Using Shell"),
            ),
          ],
        ),
      ),
    ),
    GoRoute(
      path: "/full",
      builder: (context, state) {
        return const BaseWidget(child: BodyWidget());
      },
    ),
    ShellRoute(
        builder: (context, state, child) {
          return BaseWidget(child: child);
        },
        routes: [
          GoRoute(
            path: "/shell",
            builder: (context, state) => const BodyWidget(),
          )
        ])
  ],
);

The errors shown are listed below:

══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during performResize():
Assertion failed: file:///.../flutter/packages/flutter/lib/src/widgets/overlay.dart:833:12
constraints.biggest.isFinite is not true
The relevant error-causing widget was: ListView

Another exception was thrown: BoxConstraints forces an infinite height.
Another exception was thrown: Assertion failed: box.dart:2009
Another exception was thrown: Assertion failed: sliver_multi_box_adaptor.dart:550
Another exception was thrown: Unexpected null value.
Another exception was thrown: Assertion failed: mouse_tracker.dart:205
Error: Unexpected null value.

So my question is, why does this work when I configure it directly but not work when I use Shell Route? Is it some bug with the library or am I missing something? Any tips to solve this problem?

Tested on:

Flutter 3.7.10 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 4b12645012 (2 days ago) • 2023-04-03 17:46:48 -0700
Engine • revision ec975089ac
Tools • Dart 2.19.6 • DevTools 2.20.1
go_router: ^6.5.3
Marcelo Barros
  • 930
  • 9
  • 16

0 Answers0