Flutter開發(fā)iOS上TextField長(zhǎng)按或反復(fù)點(diǎn)擊報(bào)錯(cuò)No CupertinoLocalizations found.

錯(cuò)誤內(nèi)容如下:

======== Exception caught by widgets library =======================================================

The following assertion was thrown building _CupertinoTextSelectionControlsToolbar(dirty, dependencies: [MediaQuery, _LocalizationsScope-[GlobalKey#1fa5b]], state: _CupertinoTextSelectionControlsToolbarState#23a43):

No CupertinoLocalizations found.

_CupertinoTextSelectionControlsToolbar widgets require CupertinoLocalizations to be provided by a Localizations widget ancestor.

The cupertino library uses Localizations to generate messages, labels, and abbreviations.

To introduce a CupertinoLocalizations, either use a CupertinoApp at the root of your application to include them automatically, or add a Localization widget with a CupertinoLocalizations delegate.

The specific widget that could not find a CupertinoLocalizations ancestor was: _CupertinoTextSelectionControlsToolbar

? dirty

? dependencies: [MediaQuery, _LocalizationsScope-[GlobalKey#1fa5b]]

? state: _CupertinoTextSelectionControlsToolbarState#23a43

The ancestors of this widget were:

? : CupertinoApp

? ? state: _CupertinoAppState#5e387

? : MyApp

? : ChangeNotifierProvider<KitUser>

? ? value: <not yet loaded>

? : MultiProvider

? ...

The relevant error-causing widget was:

? CupertinoApp CupertinoApp:file:///Users/jarvis/Desktop/Flutter-workspace/flutter_oa/code/oa/lib/main.dart:70:14

When the exception was thrown, this was the stack:

#0? ? ? debugCheckHasCupertinoLocalizations.<anonymous closure> (package:flutter/src/cupertino/debug.dart:23:7)

#1? ? ? debugCheckHasCupertinoLocalizations (package:flutter/src/cupertino/debug.dart:43:4)

#2? ? ? CupertinoLocalizations.of (package:flutter/src/cupertino/localizations.dart:262:12)

#3? ? ? _CupertinoTextSelectionControlsToolbarState.build (package:flutter/src/cupertino/text_selection.dart:135:73)

#4? ? ? StatefulElement.build (package:flutter/src/widgets/framework.dart:4782:27)

#5? ? ? ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4665:15)

#6? ? ? StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)

#7? ? ? Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)

#8? ? ? ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4643:5)

#9? ? ? StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4831:11)

#10? ? ComponentElement.mount (package:flutter/src/widgets/framework.dart:4638:5)

...? ? Normal element mounting (39 frames)

#49? ? Element.inflateWidget (package:flutter/src/widgets/framework.dart:3673:14)

#50? ? MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6333:36)

#51? ? Element.updateChild (package:flutter/src/widgets/framework.dart:3425:18)

#52? ? RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5758:32)

#53? ? MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6356:17)

#54? ? Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)

#55? ? ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)

#56? ? StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)

#57? ? Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)

#58? ? BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2620:33)

#59? ? WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:882:21)

#60? ? RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:319:5)

#61? ? SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1143:15)

#62? ? SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1080:9)

#63? ? SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:996:5)

#67? ? _invoke (dart:ui/hooks.dart:166:10)

#68? ? PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:270:5)

#69? ? _drawFrame (dart:ui/hooks.dart:129:31)

(elided 3 frames from dart:async)

====================================================================================================

從上面的錯(cuò)誤信息中的一句:

To introduce a CupertinoLocalizations, either use a CupertinoApp at the root of your application to include them automatically, or add a Localization widget with a CupertinoLocalizations delegate.?

大致的意思是需要引用‘CupertinoLocalizations’這么個(gè)東西,然后用’CupertinoApp‘這個(gè)東西包裹,那么‘CupertinoLocalizations’需要放在那里呢,哎,就是放在語(yǔ)言代理的‘localizationsDelegates’位置下,

當(dāng)然,不能直接使用‘CupertinoLocalizations’,不然也是報(bào)錯(cuò),這里需要使用的是‘GlobalCupertinoLocalizations.delegate,’,這個(gè)代理,我這里是區(qū)分了iOS和android設(shè)備平臺(tái)。

具體可參考下圖:


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容