无法在flutter中选择文本,没有找到MediaQuery小工具。

问题描述 投票:0回答:1

无法在flutter中选择文本。

我想在文本字段中选择一个文本,但一直得到一个红色的屏幕,并出现以下错误。

代码:异常:无法选择文本

@override
  Widget build(BuildContext context) {

    return Scaffold(
        floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
        floatingActionButton: UtilUI.getFabExtended(constants.sDone, Icons.check, true, constants, () {
          doneNote(context);
        }),
        appBar: AppBar(
            iconTheme: IconThemeData(
              color: util.getTheme(context).primaryColorDark,
            ),
            leading: UtilUI.getIconButton(
                context, constants, Icons.arrow_back_ios, util.getTheme(context).primaryColorDark, util.getTheme(context).primaryColor, () => {done(context)},
                isElevated: false, iconSize: constants.d24),
            title: UtilUI.getTextField(_headerController, constants.fHeader16, util.getTheme(context).accentColor, constants.sAddNoteHint,
                fontWeight: constants.fWeight8, textAlign: TextAlign.start)),
        body: Container(
            padding: EdgeInsets.all(constants.d24),
            child: Column(mainAxisAlignment: MainAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.center, children: [
              Row(crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.end, children: [
                UtilUI.getIcon(Icons.alarm, util.getTheme(context).primaryColorLight, constants.d24),
                SizedBox(width: constants.d4),
                Row(children: [UtilUI.getTextDescription(util.timeAgo(_note.time), constants)])
              ]),
              UtilUI.getTextField(_descriptionController, constants.fHeader12, util.getTheme(context).primaryColorLight, constants.sAddNoteHint,
                  maxLines: constants.i200,
                  fontWeight: constants.fWeight6,
                  textAlign: TextAlign.start,
                  selectionEnabled: true,
                  copy: true,
                  cut: true,
                  paste: true,
                  selectAll: true)
            ])));
  }

异常:

 ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following assertion was thrown building
flutter: _OverlayEntryWidget-[LabeledGlobalKey<_OverlayEntryWidgetState>#ef011](dirty, state:
flutter: _OverlayEntryWidgetState#8dbc7):
flutter: No MediaQuery widget found.
flutter: _OverlayEntryWidget widgets require a MediaQuery widget ancestor.
flutter: The specific widget that could not find a MediaQuery ancestor was:
flutter:   _OverlayEntryWidget-[LabeledGlobalKey<_OverlayEntryWidgetState>#ef011]
flutter: The ownership chain for the affected widget is:
flutter:   "_OverlayEntryWidget-[LabeledGlobalKey<_OverlayEntryWidgetState>#ef011] ← _Theatre ← Overlay ←
flutter:   Directionality ← FlutterEasyLoading ← MyApp ← [root]"
flutter: Typically, the MediaQuery widget is introduced by the MaterialApp or WidgetsApp widget at the top of
flutter: your application widget tree.
flutter:
flutter: The relevant error-causing widget was:
flutter:   Overlay
flutter:   file:///Users/xx/Library/Flutter/sdk/.pub-cache/hosted/pub.dartlang.org/flutter_easyloading-1.1.4/lib/src/widgets/loading.dart:35:14
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0      debugCheckHasMediaQuery.<anonymous closure> (package:flutter/src/widgets/debug.dart:215:7)
flutter: #1      debugCheckHasMediaQuery (package:flutter/src/widgets/debug.dart:227:4)
flutter: #2      _CupertinoTextSelectionControls.buildToolbar (package:flutter/src/cupertino/text_selection.dart:308:12)
flutter: #3      TextSelectionOverlay._buildToolbar (package:flutter/src/widgets/text_selection.dart:556:34)
flutter: #4      _OverlayEntryWidgetState.build (package:flutter/src/widgets/overlay.dart:177:34)
flutter: #5      StatefulElement.build (package:flutter/src/widgets/framework.dart:4619:28)
flutter: #6      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4502:15)
flutter: #7      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4675:11)
flutter: #8      Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
flutter: #9      StatefulElement.update (package:flutter/src/widgets/framework.dart:4707:5)
flutter: #10     Element.updateChild (package:flutter/src/widgets/framework.dart:3201:15)
flutter: #11     RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5522:32)
flutter: #12     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5957:17)
flutter: #13     Element.updateChild (package:flutter/src/widgets/framework.dart:3201:15)
flutter: #14     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4527:16)
flutter: #15     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4675:11)
flutter: #16     Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
flutter: #17     StatefulElement.update (package:flutter/src/widgets/framework.dart:4707:5)
flutter: #18     Element.updateChild (package:flutter/src/widgets/framework.dart:3201:15)
flutter: #19     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4527:16)
flutter: #20     Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
flutter: #21     ProxyElement.update (package:flutter/src/widgets/framework.dart:4862:5)
flutter: #22     Element.updateChild (package:flutter/src/widgets/framework.dart:3201:15)
flutter: #23     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4527:16)
flutter: #24     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4675:11)
flutter: #25     Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
flutter: #26     StatefulElement.update (package:flutter/src/widgets/framework.dart:4707:5)
flutter: #27     Element.updateChild (package:flutter/src/widgets/framework.dart:3201:15)
flutter: #28     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4527:16)
flutter: #29     Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
flutter: #30     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2627:33)
flutter: #31     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:883:20)
flutter: #32     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:284:5)
flutter: #33     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1113:15)
       ⣟flutter: #34     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1052:9)
flutter: #35     SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:861:7)
flutter: (elided 4 frames from class _RawReceivePortImpl, class _Timer, and dart:async-patch)
flutter:
flutter flutter-layout
1个回答
2
投票

你需要有一个 MaterialAppWidgetsApp 在您的当前小组件之上。确保你有 MaterialApp 作为你的应用程序或页面小部件的根。

© www.soinside.com 2019 - 2024. All rights reserved.