Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add InheritedWidget macro example and fix up FunctionalWidget #3256

Merged
merged 3 commits into from
Jan 5, 2024

Conversation

jakemac53
Copy link
Contributor

This would reduce the "Scoped Data Propagation" example here to the following (when used with FunctionalWidget):

@InheritedWidget()
class CustomInheritedWidget {
  final String data;
}

@FunctionalWidget()
Parent _parent(BuildContext context, String data) => CustomInheritedWidget(
      data: data,
      child: Intermediate(),
    );

@FunctionalWidget()
Intermediate _intermediate(BuildContext context) => Child();

@FunctionalWidget()
Child _child(BuildContext context) {
  final data = CustomInheritedWidget.of(context).data;
  return Text("Received data: $data");
}

// Usage
Parent(data: "Some data")

I also cleaned up FunctinalWidget a bit while I was at it.

cc @goderbauer wdyt about a macro like this?

@jakemac53 jakemac53 requested a review from munificent August 4, 2023 18:40
@jakemac53
Copy link
Contributor Author

also cc @mit-mit

builder.declareInType(DeclarationCode.fromParts([
'const ${clazz.identifier.name}(',
'{',
for (var field in fields)...[
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Looks like this hasn't been run through dart format?

(I noticed the lack of space before .... This is what working on the formatter has done to me. :) )

...Oh, I just realized you can't because of the macro keywords. :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah because dart format doesn't allow the macro keyword so its a pain to use it lol.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fwiw, we should have a larger discussion, but the current way the formatter works with experiments is causing other problems with deprecating old experiments. We should re-evaluate the whole thing and come up with a way to explicitly enable any experiments imo.

@jakemac53 jakemac53 merged commit daf5cbd into main Jan 5, 2024
3 checks passed
@jakemac53 jakemac53 deleted the inherited-widget branch January 5, 2024 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants