Skip to content

[decoupling] Using flutter_localizations with material_ui/cupertino_ui #188757

Closed
flutter/packages
#12119

Description

@elliette

Currently both material_ui and cupertino_ui implement their own localization interfaces, and look up localizations by matching against those exact types:

However, if an app (see demo below) is configured to provide localizations with flutter_localizations, then cupertino_ui/material_ui are not able to reconcile the localizations, failing with the debugCheckHas[Cupertino/Material]Localizations assert in debug-mode, or a runtime error in profile/release mode.

flutter_localizations must wait for material_ui/cupertino_ui to be published before it can be updated to depend on material_ui and cupertino_ui instead of flutter/material and flutter/cupertino. A potential long-term solution here is to move flutter_localizations into flutter/packages along with the Material and Cupertino libraries.

For now, we are splitting test cases that depend on flutter_localization out of material_ui and cupertino_ui and moving them to https://github.com/flutter/flutter/tree/master/packages/flutter_localizations

demo app
import 'package:flutter_localizations/flutter_localizations.dart';
// import 'package:flutter/material.dart'; // WORKS
import 'package:material_ui/material_ui.dart'; // DOES NOT WORK

void main() {
  runApp(const DemoApp());
}

class DemoApp extends StatelessWidget {
  const DemoApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      locale: const Locale('es'), // Spanish
      supportedLocales: const <Locale>[Locale('en'), Locale('es')],
      localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
      home: const HomeScreen(),
    );
  }
}

class HomeScreen extends StatelessWidget {
  const HomeScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('material_ui Localization Demo')),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            showTimePicker(context: context, initialTime: TimeOfDay.now());
          },
          child: const Text('Show Time Picker'),
        ),
      ),
    );
  }
}

Activity

  1. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    p: cupertino_uicupertino_ui package in flutter/packages
    on Jun 30, 2026
  2. added
    P1High-priority issues at the top of the work list
    on Jun 30, 2026
  3. justinmc commented on Jun 30, 2026

    @justinmc
    Contributor

    Thanks for creating an issue for this!

  4. elliette commented on Jul 1, 2026

    @elliette
    MemberAuthor

    Adding this as well so it doesn't get lost:

    I was curious what re-exporting Material/CupertinoLocalizations in the material_ui/cupertino_ui would look like in practice (see code diffs below).

    Unfortunately if we want to import Material/CupertinoLocalizations from flutter_localizations and re-export them in material/cupertino_ui, we will also need to import all the classes used as type signatures in Material/CupertinoLocalizations, which include those defined in the design language packages (like ScriptCategory). This approach effectively breaks decoupling, since it introduces dependencies on the SDK's Material/Cupertino libraries in material/cupertino_ui. However, doing so does unblock apps using flutter_localizations to migrate to material/cupertino_ui.

  5. self-assigned this
    on Jul 6, 2026
  6. github-actions commented on Jul 29, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  7. locked as resolved and limited conversation to collaborators on Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listframeworkflutter/packages/flutter repository. See also f: labels.p: cupertino_uicupertino_ui package in flutter/packagesp: material_uimaterial_ui package in flutter/packagesteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions