Galirage Inc.
🤳

ダブルタップすると落ちるバグの解決方法【Flutter / Dart】

に公開
2026/05/05

はじめまして、ますみです!

株式会社Galirage(ガリレージ)というAIスタートアップで、代表をしております^^

その他にも、「AIとコミュニケーションする技術(インプレス出版)」という書籍を執筆させていただいたり、生成AIアカデミーというYouTubeチャンネルを運営したり、上智大学で非常勤講師をしたりしています!

自己紹介.png
最近、Flutterのアプリ上で、TextFieldのようなInputするUIをダブルタップすると、エラーが起きて、アプリが落ちるというバグに遭遇しました。

調査をしたところ、どうやら、localizationsDelegatesの設定の問題でした。

結構Criticalなバグであるため、同じ問題に遭遇している人たちに向けて、対処法を書き留めます。

エラー内容

コンソール上のエラー内容は以下の通りです。

════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown building _CupertinoTextSelectionControlsToolbar(dirty, dependencies: [MediaQuery, _LocalizationsScope-[GlobalKey#09699]], state: _CupertinoTextSelectionControlsToolbarState#62b54):
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.

エラーが起きた時のエラー箇所は以下の通りです。

bool debugCheckHasCupertinoLocalizations(BuildContext context) {
  assert(() {
    if (Localizations.of<CupertinoLocalizations>(context, CupertinoLocalizations) == null) {
      throw FlutterError.fromParts(<DiagnosticsNode>[
        ErrorSummary('No CupertinoLocalizations found.'),
        ErrorDescription(
          '${context.widget.runtimeType} widgets require CupertinoLocalizations '
          'to be provided by a Localizations widget ancestor.',
        ),
        ErrorDescription(
          'The cupertino library uses Localizations to generate messages, '
          'labels, and abbreviations.',
        ),
        ErrorHint(
          '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.',
        ),
        ...context.describeMissingAncestor(expectedAncestorType: CupertinoLocalizations),
      ]);
    }
    return true;
  }());
  return true;
}

どうやらCupertinoに関するエラーのようですね。

解決方法

解決方法としては、MaterialAppを定義している箇所で、以下のようにlocalizationsDelegatesの設定として、次の三つを追加すると直りました。

main.dart
return MaterialApp(
  ...
  localizationsDelegates: const [
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate,
    GlobalCupertinoLocalizations.delegate,
  ],
  supportedLocales: const [
    Locale('ja'),
  ],
);

最後に

最後まで読んでくださり、ありがとうございました!
この記事を通して、少しでもあなたの学びに役立てば幸いです✨

Galirage Inc.
Galirage Inc.

Discussion