Skip to content

refactor!: migrate to material_ui/cupertino_ui design-system packages (Flutter 3.47+) - #145

Open
pento wants to merge 1 commit into
berkaycatak:mainfrom
pento:material-ui-migration
Open

pento wants to merge 1 commit into
berkaycatak:mainfrom
pento:material-ui-migration

Conversation

@pento

@pento pento commented Aug 16, 2026 •

Copy link
Copy Markdown

Description

Flutter 3.47 decoupled the Material and Cupertino design systems from the SDK into the standalone material_ui and cupertino_ui packages. The SDK's bundled copies are frozen and scheduled for formal deprecation in the November stable release. This migrates the package onto the standalone packages.

material_ui and cupertino_ui are full source forks of the SDK design libraries, so their ThemeData, ThemeMode, CupertinoThemeData and InputDecoration are distinct Dart types from the identically-named SDK ones, despite being structurally identical. An app that's migrated can't use a package still typed against the SDK types, passing a modern ThemeData to AdaptiveApp.materialLightTheme fails with The argument type 'ThemeData' can't be assigned to the parameter type 'ThemeData?'.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring
  • Performance improvement

Related Issues

Overlaps with #146.

Changes Made

  • Rewrote every package:flutter/material.dart and package:flutter/cupertino.dart import in lib/, test/ and example/lib/ to the standalone packages, including the 1.0 toolbar-host and iPhone Duo files. Only import lines change in those directories, apart from the example's localization setup below.
  • Added material_ui: ^1.0.0 and cupertino_ui: ^1.0.0 to pubspec.yaml and example/pubspec.yaml, alongside 1.0's foldable dependency.
  • Raised the floor to Flutter >=3.47.0 and Dart ^3.12.0.
  • Replaced the example's manual localization delegate list with GlobalMaterialLocalizations.delegates and dropped its flutter_localizations dependency. material_ui ships that constant and it already bundles the material, cupertino and widgets delegates — this is the pattern material_ui's README recommends.
  • Bumped CI and release workflows from Flutter 3.35.6 to 3.47.0.
  • Brought the example's Android toolchain up to what flutter create generates on 3.47 (Gradle 8.12→9.3.1, AGP 8.9.1→9.1.0, Kotlin 2.1.0→2.4.0, Java 11→17) and migrated app/build.gradle.kts off the kotlinOptions block to the kotlin { compilerOptions { … } } DSL that AGP 9 requires.
  • Merged the README's requirements into the single existing Requirements section (Flutter >=3.47.0, Dart ^3.12.0, iOS 15.0), added a "Migrating to material_ui / cupertino_ui" guide next to "Migrating to 1.0.0", and updated CLAUDE.md's CI version and import convention.

No native code changes — nothing under ios/ or android/ needed touching.

Testing

Automated Tests

  • I have added unit/widget tests for my changes — no new tests. This is a mechanical migration with no behavioural change.
  • All new and existing tests pass locally (flutter test)
  • Code analysis passes with no errors (flutter analyze --fatal-infos, package root and example).
  • CI green on Flutter 3.47.0 (analyze, test, release APK build)
  • Code formatting is correct (dart format) — the lines this PR adds are formatted, but I didn't run dart format over the files it touches.
  • Test coverage is adequate (>80% for new code)

Manual Testing

  • iOS 26+ tested — iOS 26.5
  • iOS <26 tested
  • Android tested — Android 17 (API 37)
  • Web tested (if applicable)
  • Tested in both light and dark mode
  • Tested with different screen sizes
  • Tested with accessibility features (large fonts, screen readers, etc.)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have checked that my code does not introduce any accessibility issues
  • I have updated the CHANGELOG.md file (if applicable)
  • I have updated version number in pubspec.yaml (if applicable)
  • I have added examples to the example app (if adding new widgets)

Breaking Changes

Consumers must migrate to the standalone design-system packages in the same step. There is no mixed mode: any file that constructs a value passed to this package's API must import from material_ui/cupertino_ui rather than the SDK.

Migration guide for consumers:

  1. Add the packages and raise the Flutter floor:

    environment:
      flutter: ">=3.47.0"
    dependencies:
      cupertino_ui: ^1.0.0
      material_ui: ^1.0.0
  2. Replace imports throughout the app:

    package:flutter/material.dart   ->  package:material_ui/material_ui.dart
    package:flutter/cupertino.dart  ->  package:cupertino_ui/cupertino_ui.dart
  3. If the app depends on other packages that still build legacy Material widgets internally, wrap the app's content in MaterialUiCompatibilityBridge / CupertinoUiCompatibilityBridge. AdaptiveApp.builder is a natural place:

    AdaptiveApp(
      builder: (BuildContext context, Widget? child) =>
          MaterialUiCompatibilityBridge(
            child: CupertinoUiCompatibilityBridge(child: child!),
          ),
      // ...
    )

Additional Notes

Releasing this. Flutter's guidance for package authors is to "treat this migration as a major version bump". Releasing it as the next major lets apps still on Flutter < 3.47 stay on 1.x. When you release it, the README's install snippet should name that major; I've left version, CHANGELOG.md and the install snippet alone, since releases are your call. Other packages have already done the same: go_router 18, animations 3, dynamic_color 2 and flex_color_scheme 9 each shipped the migration as a new major. The SDK copies have been frozen since April 2026, and their formal deprecation (flutter/flutter#192957) is targeted at the November stable.

The Flutter 3.35 TickerMode.of shim in adaptive_scaffold.dart is untouched. I left it exactly as it is so this PR stays mechanical. It can be dropped once the floor is 3.47.

#146 covers the same ground. I'm happy to consolidate the two PRs in whichever direction suits you.

The example's Android toolchain changes could be split out if you'd prefer that. They're the largest non-mechanical part of this PR, and they can be upgraded prior to the design-system migration: let me know if you'd prefer them in a separate PR.

Raising the Flutter floor also raises the example's Android floor. Flutter 3.47's stated minimum is Gradle 8.14, and the example does build at that version, but Flutter warns that it "will soon be dropped, please upgrade to at least 9.1.0", and on a newer JDK, the build fails outright.

Rather than track a minimum that's already deprecation-warned, the example now matches what flutter create generates on 3.47: Gradle 9.3.1, AGP 9.1.0, Kotlin 2.4.0, Java 17. AGP 9 additionally rejects the kotlinOptions block, so app/build.gradle.kts moves to the kotlin { compilerOptions { … } } DSL. The android.newDsl and android.builtInKotlin opt-outs that Flutter's migrator adds are what let AGP 9 work without a wider DSL rewrite.

If you'd rather stay closer to the current setup, Gradle 8.14 with AGP 8.11.1 and Kotlin 2.2.20 is the smaller change that satisfies Flutter 3.47 and keeps the existing kotlinOptions DSL.

Demo Code

The localization setup is the one public-facing usage change, since material_ui supplies the delegates that previously came from flutter_localizations:

import 'package:cupertino_ui/cupertino_ui.dart';
import 'package:material_ui/material_ui.dart';

AdaptiveApp(
  // Bundles the material, cupertino and widgets delegates.
  // No flutter_localizations import needed.
  localizationsDelegates: GlobalMaterialLocalizations.delegates,
  supportedLocales: const <Locale>[
    Locale('en', ''),
    Locale('de', ''),
    Locale('tr', ''),
  ],
  home: const MyHomePage(),
)

@pento
pento force-pushed the material-ui-migration branch from 9416b88 to c457514 Compare September 27, 2026 11:01
@pento

pento commented Sep 27, 2026

Copy link
Copy Markdown
Author

@berkaycatak: I've updated this PR to be based on the 1.0.1 release. Happy to adjust things if this is something you're interested in merging.

Flutter 3.47 decoupled the Material and Cupertino design systems from the
SDK into the standalone material_ui and cupertino_ui packages. The SDK's
bundled copies are scheduled for deprecation, so this migrates the package
onto the standalone ones.

Because material_ui and cupertino_ui are source forks of the SDK design
libraries, their ThemeData, ThemeMode, CupertinoThemeData and
InputDecoration are distinct Dart types from the identically-named SDK
ones. A package typed against the SDK types cannot be consumed by an app
that has migrated, and vice versa, so this is a breaking change for
consumers.

- Rewrite every package:flutter/material.dart and package:flutter/cupertino.dart
  import in lib/, test/ and example/lib/ to the standalone packages,
  including the 1.0 toolbar-host and iPhone Duo files.
- Add material_ui ^1.0.0 and cupertino_ui ^1.0.0 as dependencies.
- Raise the floor to Flutter >=3.47.0 and Dart ^3.12.0.
- Drop flutter_localizations from the example in favour of
  GlobalMaterialLocalizations.delegates, which material_ui ships and which
  already bundles the material, cupertino and widgets delegates.
- Bump CI and release workflows from Flutter 3.35.6 to 3.47.0.
- Consolidate the README Requirements section with upstream's, add a
  material_ui/cupertino_ui migration note, and update CLAUDE.md's CI
  version and import convention.

Raising the Flutter floor also raises the example's Android toolchain
floor. The example now matches what flutter create generates on 3.47 -
Gradle 9.3.1, Android Gradle Plugin 9.1.0 and Kotlin 2.4.0 - rather than
the older minimums Flutter still nominally accepts. Those minimums build
on CI but fail against the JDK current Android Studio ships, which needs
Gradle 9.1.0 or newer, so the example would not build for most developers.
The android.newDsl and android.builtInKotlin opt-outs the Flutter migrator
adds are what let AGP 9 work without a DSL rewrite.

The package version and CHANGELOG are deliberately left untouched, since
releases are the maintainer's call.

No native (Swift/Kotlin) source changes are required. flutter analyze
--fatal-infos and flutter test are clean in both the package root and the
example.

BREAKING CHANGE: this package is now typed against material_ui and
cupertino_ui rather than the SDK's bundled design libraries. Because those
are source forks, their ThemeData, ThemeMode, CupertinoThemeData and
InputDecoration are distinct Dart types from the SDK ones, so consumers
must migrate their own imports in the same step. The minimum Flutter
version is now 3.47.0.
@pento
pento force-pushed the material-ui-migration branch from c457514 to 558c214 Compare October 11, 2026 20:42
@pento

pento commented Oct 13, 2026

Copy link
Copy Markdown
Author

@berkaycatak: I've updated this PR to reflect main, I'll probably keep it updated sporadically, since I need it for my own use. Do you have a rough idea of when you're planning on returning to deferred issues?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants