В дереве виджетов обнаружен дубликат GlobalKey при использовании GridView.builder - PullRequest
0 голосов
/ 06 мая 2020

Моя таблица загружается нормально. Но когда я прокручиваю его, только часть экрана с сеткой вылетает из-за данного журнала консоли.

Мое дерево виджетов приведено ниже.

Scaffold(
  body: Column(
    children: <Widget>[
      Container(child: Text('Explore Nearby')),
      Container(
        child: RefreshIndicator(
          onRefresh: () => _bloc.fetchSubscriberList(),
          child: StreamBuilder<ApiResponse<List<Subscriber>>>(
            stream: _bloc.subscriberListStream,
            builder: (context, snapshot) {
              if (snapshot.hasData) {
                switch (snapshot.data.status) {
                  case Status.LOADING:
                    return Loading(loadingMessage: snapshot.data.message);
                    break;
                  case Status.COMPLETED:
                    return SubscriberList(
                        subscriberList: snapshot.data.data);
                    break;
                  case Status.ERROR:
                    return Error(
                      errorMessage: snapshot.data.message,
                      onRetryPressed: () => _bloc.fetchSubscriberList(),
                    );
                    break;
                }
              } else {
                log('no Snapshot data');
              }
              return Container();
            },
          ),
        ),
      ),
    ],
  ),
);

SubscriberList widget:

class SubscriberList extends StatelessWidget {
  final List<Subscriber> subscriberList;
  const SubscriberList({this.subscriberList});
  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: Container(
        child: GridView.builder(
          itemCount: subscriberList.length,
          gridDelegate:
              SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
          itemBuilder: (context, index) =>
              SubscriberGridTile(data: subscriberList[index], index: index),
        ),
      ),
    );
  }
}
class SubscriberGridTile extends StatelessWidget {
  final Subscriber data;
  final int index;
  SubscriberGridTile({this.data, this.index});
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(
          left: index % 2 == 0 ? 10 : 5,
          right: index % 2 != 0 ? 10 : 5,
          top: 5,
          bottom: 5),
      child: GestureDetector(
        onTap: () {
          Navigator.pushNamed(context, BookingScreen.id,
              arguments: {'id': data.id});
        },
        child: Stack(
          children: <Widget>[
            Container(
              height: double.infinity,
              width: double.infinity,
              decoration: BoxDecoration(
                  color: Colors.blue,
                  borderRadius: BorderRadius.all(Radius.circular(10))),
            ),
            Container(
              padding: EdgeInsets.all(8),
//              height: 200,
//              width: 150,
              child: Column(
                children: <Widget>[
                  // New
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Container(
                        padding:
                            EdgeInsets.symmetric(vertical: 8, horizontal: 8),
                        decoration: BoxDecoration(
                            color: Colors.black12,
                            borderRadius: BorderRadius.circular(8)),
                        child:
                            Text("New", style: TextStyle(color: Colors.white)),
                      ),
                    ],
                  ),
                  Spacer(),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Expanded(
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: <Widget>[
                            Container(
                              child: Text(
                                data.name,
                                style: TextStyle(
                                  color: Colors.white,
                                  fontWeight: FontWeight.w600,
                                  fontSize: 20,
                                ),
                              ),
                            ),
                            SizedBox(height: 8),
                            Text(
                              data.owner,
                              style: TextStyle(
                                color: Colors.white,
                                fontWeight: FontWeight.w400,
                                fontSize: 16,
                              ),
                            ),
                            SizedBox(height: 8),
                          ],
                        ),
                      ),
                    ],
                  ),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}

Журнал ошибок консоли:

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following assertion was thrown building RefreshIndicator(dependencies: [_InheritedTheme, _LocalizationsScope-[GlobalKey#397b9]], state: RefreshIndicatorState#d802f(tickers: tracking 2 tickers)):
'package:flutter/src/widgets/basic.dart': Failed assertion: line 4386 pos 12: 'renderObject.parentData is FlexParentData': is not true.


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=BUG.md

The relevant error-causing widget was: 
  RefreshIndicator file:///media/pi/Pi/Code/android/q/lib/views/nearby.dart:701:22
When the exception was thrown, this was the stack: 
#2      Flexible.applyParentData (package:flutter/src/widgets/basic.dart:4386:12)
#3      RenderObjectElement._updateParentData (package:flutter/src/widgets/framework.dart:5279:16)
#4      RenderObjectElement.attachRenderObject (package:flutter/src/widgets/framework.dart:5298:7)
#5      Element.attachRenderObject.<anonymous closure> (package:flutter/src/widgets/framework.dart:3108:13)
#6      ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4272:14)
...
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/widgets/basic.dart': Failed assertion: line 4386 pos 12: 'renderObject.parentData is FlexParentData': is not true.
The relevant error-causing widget was: 
  SubscriberList file:///media/pi/Pi/Code/android/q/lib/views/nearby.dart:714:34
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by rendering library ═════════════════════════════════════════════════════
Vertical viewport was given unbounded height.
The relevant error-causing widget was: 
  GridView file:///media/pi/Pi/Code/android/q/lib/views/nearby.dart:746:25
════════════════════════════════════════════════════════════════════════════════════════════════════
E/AccessibilityBridge( 3427): VirtualView node must not be the root node.

════════ Exception caught by rendering library ═════════════════════════════════════════════════════
A RenderFlex overflowed by 199374 pixels on the bottom.
The relevant error-causing widget was: 
  Column file:///media/pi/Pi/Code/android/q/lib/views/nearby.dart:691:15
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following assertion was thrown building RefreshIndicator(dependencies: [_InheritedTheme, _LocalizationsScope-[GlobalKey#397b9]], state: RefreshIndicatorState#d802f(tickers: tracking 2 tickers)):
'package:flutter/src/widgets/framework.dart': Failed assertion: line 5540 pos 12: '_children.contains(child)': is not true.


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=BUG.md

The relevant error-causing widget was: 
  RefreshIndicator file:///media/pi/Pi/Code/android/q/lib/views/nearby.dart:701:22
When the exception was thrown, this was the stack: 
#2      MultiChildRenderObjectElement.forgetChild (package:flutter/src/widgets/framework.dart:5540:12)
#3      Element._retakeInactiveElement (package:flutter/src/widgets/framework.dart:3149:14)
#4      Element.inflateWidget (package:flutter/src/widgets/framework.dart:3176:32)
#5      MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5551:32)
#6      Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
...
════════════════════════════════════════════════════════════════════════════════════════════════════
E/flutter ( 3427): [ERROR:flutter/flow/layers/transform_layer.cc(22)] TransformLayer is constructed with an invalid matrix.
E/flutter ( 3427): [ERROR:flutter/flow/layers/transform_layer.cc(22)] TransformLayer is constructed with an invalid matrix.
E/flutter ( 3427): [ERROR:flutter/flow/layers/transform_layer.cc(22)] TransformLayer is constructed with an invalid matrix.

════════ Exception caught by rendering library ═════════════════════════════════════════════════════
RenderStack object was given an infinite size during layout.
The relevant error-causing widget was: 
  RefreshIndicator file:///media/pi/Pi/Code/android/q/lib/views/nearby.dart:701:22
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by scheduler library ═════════════════════════════════════════════════════
SemanticsNode#18(STALE, owner: null, Rect.fromLTRB(0.0, 159.0, 392.7, 785.5)) (with null) tried to set a non-finite rect.
'package:flutter/src/semantics/semantics.dart':
Failed assertion: line 1245 pos 12: 'value.isFinite'
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following assertion was thrown while finalizing the widget tree:
Duplicate GlobalKey detected in widget tree.

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#ae3e0]
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:
- Stack(alignment: AlignmentDirectional.topStart, fit: loose, overflow: clip, dependencies: [Directionality], renderObject: RenderStack#ead04 relayoutBoundary=up2)
A GlobalKey can only be specified on one widget at a time in the widget tree.
When the exception was thrown, this was the stack: 
#0      BuildOwner.finalizeTree.<anonymous closure> (package:flutter/src/widgets/framework.dart:2578:15)
#1      BuildOwner.finalizeTree (package:flutter/src/widgets/framework.dart:2603:8)
#2      WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:775:18)
#3      RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:283:5)
#4      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1102:15)
...
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 5540 pos 12: '_children.contains(child)': is not true.
The relevant error-causing widget was: 
  RefreshIndicator file:///media/pi/Pi/Code/android/q/lib/views/nearby.dart:701:22
════════════════════════════════════════════════════════════════════════════════════════════════════
E/flutter ( 3427): [ERROR:flutter/flow/layers/transform_layer.cc(22)] TransformLayer is constructed with an invalid matrix.
E/flutter ( 3427): [ERROR:flutter/flow/layers/transform_layer.cc(22)] TransformLayer is constructed with an invalid matrix.

════════ Exception caught by rendering library ═════════════════════════════════════════════════════
RenderStack object was given an infinite size during layout.
The relevant error-causing widget was: 
  Column file:///media/pi/Pi/Code/android/q/lib/views/nearby.dart:691:15
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by scheduler library ═════════════════════════════════════════════════════
SemanticsNode#18(STALE, owner: null, Rect.fromLTRB(0.0, 159.0, 392.7, 785.5)) (with null) tried to set a non-finite rect.
'package:flutter/src/semantics/semantics.dart':
Failed assertion: line 1245 pos 12: 'value.isFinite'
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following assertion was thrown while finalizing the widget tree:
Duplicate GlobalKey detected in widget tree.

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#ae3e0]
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:
- Stack(alignment: AlignmentDirectional.topStart, fit: loose, overflow: clip, dependencies: [Directionality], renderObject: RenderStack#ead04 relayoutBoundary=up2)
A GlobalKey can only be specified on one widget at a time in the widget tree.
When the exception was thrown, this was the stack: 
#0      BuildOwner.finalizeTree.<anonymous closure> (package:flutter/src/widgets/framework.dart:2578:15)
#1      BuildOwner.finalizeTree (package:flutter/src/widgets/framework.dart:2603:8)
#2      WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:775:18)
#3      RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:283:5)
#4      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1102:15)
...
════════════════════════════════════════════════════════════════════════════════════════════════════
E/flutter ( 3427): [ERROR:flutter/flow/layers/transform_layer.cc(22)] TransformLayer is constructed with an invalid matrix.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...