Skip to content

[decoupling] Using flutter_localizations with material_ui/cupertino_ui #188757

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'),
        ),
      ),
    );
  }
}

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listf: cupertinoflutter/packages/flutter/cupertino repositoryf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions