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 support for arbitrary forDesignTime method #18

Closed
wants to merge 1 commit into from

Conversation

Projects
None yet
2 participants
@vmaraccini
Copy link
Contributor

vmaraccini commented Apr 9, 2019

This adds support for custom forDesignTime methods that produce either a single or a List of widgets for rendering.

Example:

@Showcased(width: 104.0, height: 104.0)
class ActionButton extends StatelessWidget {
  const ActionButton({Key key, this.params}) : super(key: key);

  static List<Widget> forDesignTime() {
    return [
      ActionButton(params: oneSample),
      ActionButton(params: otherSample),
      ActionButton(params: yetAnotherSample)
    ];
  }
...

This would produce 3 separate screenshots under the same showcase

@Igor1201
Copy link
Owner

Igor1201 left a comment

I'll try to take a look at it asap, thanks!

(ConstructorElement c) => c.name == 'forDesignTime',
orElse: () => null,
);
final MethodElement forDesignTime = element.getMethod('forDesignTime');

This comment has been minimized.

Copy link
@Igor1201

Igor1201 Apr 9, 2019

Owner

Does this work for factories? 🆒

This comment has been minimized.

Copy link
@Igor1201

Igor1201 Apr 14, 2019

Owner

I didn't have lucky on using either getMethod or getNamedConstructor for factories :(

@@ -86,6 +83,10 @@ See https://github.com/flutter/flutter-intellij/wiki/Using-live-preview
final double boundaryHeight =
annotatedElement.annotation.peek('height').doubleValue;

final showcase = forDesignTime.returnType.name.contains("List")

This comment has been minimized.

Copy link
@Igor1201

Igor1201 Apr 9, 2019

Owner

There's probably a way to check this type consistently (and guarantee it's a List),

Also, forDesignTime can be null, as it's not required for a Widget to implement it.

This comment has been minimized.

Copy link
@Igor1201

Igor1201 Apr 14, 2019

Owner

There's another problem here: forDesignTime is a class factory, so it's not possible for it to return a List, it must return an instance of the widget it's declared. I've tried to create mixins for it, but you can't have mixins for static methods, nor factories.

@Igor1201

This comment has been minimized.

Copy link
Owner

Igor1201 commented Apr 14, 2019

Closing in favor of #19

@Igor1201 Igor1201 closed this Apr 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.