Skip to content

"Duplicate GlobalKey detected in widget tree" when used with flutter_html #89

Description

@MikesDevCorner

Steps to recreate:

import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:liquid_swipe/liquid_swipe.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: Scaffold(
        appBar: AppBar(
          backgroundColor: Theme.of(context).colorScheme.inversePrimary,
          title: const Text('Test Title'),
        ),
        body: LiquidSwipe(
          pages: [
            Container(
              color: Colors.purple,
              width: double.infinity,
              height: double.infinity,
              child: const Center(
                child: Text('Test'),
              ),
            ),
            Container(
              color: Colors.amber,
              width: double.infinity,
              height: double.infinity,
              child: Center(
                child: Html(
                  data: '<div class="center">TEST ABC</div>',
                  style: {
                    ".center": Style(
                      textAlign: TextAlign.center,
                    ),
                  },
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}

Look at this example and tap or drag on the rendered html, the following exception occurs:

The following GlobalKey was specified multiple times in the widget tree. This will lead to parts of the widget tree being truncated unexpectedly, because the second time a key is seen, the previous instance is moved to the new location. The key was:
- [GlobalKey#25af9]
This was determined by noticing that after the widget with the above global key was moved out of its previous parent, that previous parent never updated during this frame, meaning that it either did not update at all or updated before the widget was moved, in either case implying that it still thinks that it should have a child with that global key.
The specific parent that did not update after having one or more children forcibly removed due to GlobalKey reparenting is:
- Html(state: _HtmlState#279ad)
A GlobalKey can only be specified on one widget at a time in the widget tree.

Would be very cool if these two widgets work together :)
Thanks, M

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