Skip to content

Commit

Permalink
Tidy up CONTRIBUTING.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Pante committed May 22, 2024
1 parent a4f93c6 commit c898b77
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .idea/runConfigurations/Forui_Example___run.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions .idea/runConfigurations/samples___run.xml

This file was deleted.

71 changes: 61 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,72 @@ Lastly, types from 3rd party packages should not be publicly exported by Forui.

### Widget Styles

Widget styles, i.e. `CardStyle`, should mix-in [Diagnosticable](https://api.flutter.dev/flutter/foundation/Diagnosticable-mixin.html).
```dart
class FooStyle with Diagnosticable { // ---- (1)
final Color color;
FooStyle({required this.color}); // ---- (2)
FooStyle.inherit({FFont font, FColorScheme scheme}): color = scheme.primary; // ---- (2)
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) { // ---- (3)
super.debugFillProperties(properties);
properties.add(ColorProperty<BorderRadius>('color', color));
}
They should provide:
* a primary constructor
* a named constructor, `inherit(...)` , that configures itself based on an ancestor `FTheme`.
@override
bool operator ==(Object other) => identical(this, other) || other is FStyle && color == other.color; // ---- (4)
They should override:
* [debugFillProperties](https://api.flutter.dev/flutter/foundation/Diagnosticable/debugFillProperties.html)
to include all fields.
* `operator ==`
* `hashCode`
@override
int get hashCode => color.hashCode; // ---- (4)
}
```

1. They should mix-in [Diagnosticable](https://api.flutter.dev/flutter/foundation/Diagnosticable-mixin.html).
2. They should provide a primary constructor, and a named constructor, `inherit(...)` , that configures itself based on
an ancestor `FTheme`.
3. They should override [debugFillProperties](https://api.flutter.dev/flutter/foundation/Diagnosticable/debugFillProperties.html).
4. They should implement `operator ==` and `hashCode`.

They should not scale `TextStyle`S during initialization. `TextStyle`s should be scaled in a widget's build method instead.

Widget should not scale `TextStyle`S during initialization. `TextStyle`s should be scaled in a widget's build method instead.
This avoids confusion about whether `TextStyle`s are automatically scaled inside widget styles.

✅ Prefer this:
```dart
class FooStyle {
final TextStyle text;
FooStyle.inherit({FFont font, FColorScheme scheme}): text = const TextStyle(size: 1);
}
class Foo extends StatelessWidget {
final FooStyle style;
@overrride
Widget build(BuildContext context) => Text('Hi', style: style.text.withFont(context.theme.font));
}
```

❌ Instead of:
```dart
class FooStyle {
final TextStyle text;
FooStyle.inherit({FFont font, FColorScheme scheme}): text = const TextStyle(size: 1).withFont(font);
}
class Foo extends StatelessWidget {
final FooStyle style;
@overrride
Widget build(BuildContext context) => Text('Hi', style: style.text);
}
```


## Conventions

Expand Down

0 comments on commit c898b77

Please sign in to comment.