caduandrade / multi_split_view

Provides horizontal or vertical multiple split view for Flutter.
https://caduandrade.github.io/multi_split_view/
MIT License
129 stars 24 forks source link

MultiSplitView children can't use globalKey #47

Closed boostmerlin closed 8 months ago

boostmerlin commented 8 months ago

FlutterError (Multiple widgets used the same GlobalKey. The key [GlobalObjectKey String#a3a86] was used by 2 widgets: Positioned-[GlobalObjectKey String#a3a86] SceneView-[GlobalObjectKey String#a3a86] A GlobalKey can only be specified on one widget at a time in the widget tree.)

caduandrade commented 8 months ago

Hi @boostmerlin!

You can't reuse GlobalKey in Flutter. It must be unique.

I believe you are doing something like this:

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyWidget(),
    );
  }
}

class MyWidget extends StatelessWidget {
  const MyWidget({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // don't do that
    GlobalKey sameGlobalKey = GlobalKey();
    return Scaffold(
        body: Center(
            key: sameGlobalKey,
            child: Container(
                key: sameGlobalKey,
                color: Colors.blue,
                width: 100,
                height: 100)));
  }
}