Skip to content

define ThemeExtension outside of material, with static .of and an InheritedWidget or InheritedModel #160597

Description

@Luckey-Elijah

Use case

I am building a design system outside of material. I don't desire to use MaterialApp or Theme widget to define the UI. I would like the ability to use ThemeExtensions without depending on material's Theme[Data].

Proposal

I would like

  • ThemeExtension to be defined and exported from package:flutter/widgets.dart
  • a new encapsulation of ThemeExtensions in an InheritedWidget or InheritedModel
  • a new .of static method that "feels" some where between ThemeData.extension and in a typical style of InheritedWidget.of
  • the ability to introduce ThemeExtensions in a WidgetsApp (and thus available in CupertinoApp) if not in it's own InheritedWidget

example:

import 'package:flutter/widgets.dart';

void main() {
  return runApp(
    // new: some inherited model or widget for ThemeExtensions
    ThemeExtensions(
      child: WidgetsApp(home: Home(), ...),
      extensions: const [
        MyColor(brandColor: Color(0xFFE53935)),
      ],
    ),
  );
}

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // new: lookup my extension MyColor with ".of"
    final myColor = ThemeExtension.of<MyColor>(context);
    return const ColoredBox(color: myColor.brandColor);
  }
}

some possibly related issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterf: themingStyling widgets with a themeteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions