-
Notifications
You must be signed in to change notification settings - Fork 38
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
Create StyledImage #185
Merged
Merged
Create StyledImage #185
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
21f03ca
Create StyledImage
tilucasoli c6e8d70
create documentation
tilucasoli fd257dc
support to inherit
tilucasoli 4abb5fc
solve comment about lerp
tilucasoli 747fa1b
solve comments
tilucasoli e2824e9
Update image_util.dart
tilucasoli 9b570cc
add a call method in ImageRepeatUtility
tilucasoli 1dd0a17
Update scalar_util_test.dart
tilucasoli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../../core/styled_widget.dart'; | ||
import '../../factory/mix_provider.dart'; | ||
import '../../factory/mix_provider_data.dart'; | ||
import '../../utils/helper_util.dart'; | ||
import 'image_spec.dart'; | ||
|
||
class StyledImage extends StyledWidget { | ||
final ImageProvider<Object> image; | ||
final ImageFrameBuilder? frameBuilder; | ||
final ImageLoadingBuilder? loadingBuilder; | ||
final ImageErrorWidgetBuilder? errorBuilder; | ||
final String? semanticLabel; | ||
final bool excludeFromSemantics; | ||
|
||
const StyledImage({ | ||
super.key, | ||
super.style, | ||
super.inherit = true, | ||
this.frameBuilder, | ||
this.loadingBuilder, | ||
this.errorBuilder, | ||
this.semanticLabel, | ||
this.excludeFromSemantics = false, | ||
required this.image, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return withMix(context, (mix) { | ||
return MixedImage( | ||
image: image, | ||
errorBuilder: errorBuilder, | ||
excludeFromSemantics: excludeFromSemantics, | ||
frameBuilder: frameBuilder, | ||
loadingBuilder: loadingBuilder, | ||
semanticLabel: semanticLabel, | ||
); | ||
}); | ||
} | ||
} | ||
|
||
class MixedImage extends StatelessWidget { | ||
const MixedImage({ | ||
super.key, | ||
this.decoratorOrder = const [], | ||
this.mix, | ||
required this.image, | ||
this.frameBuilder, | ||
this.loadingBuilder, | ||
this.errorBuilder, | ||
this.semanticLabel, | ||
this.excludeFromSemantics = false, | ||
}); | ||
|
||
final MixData? mix; | ||
final ImageProvider<Object> image; | ||
final ImageFrameBuilder? frameBuilder; | ||
final ImageLoadingBuilder? loadingBuilder; | ||
final ImageErrorWidgetBuilder? errorBuilder; | ||
final String? semanticLabel; | ||
final bool excludeFromSemantics; | ||
final List<Type> decoratorOrder; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final mix = this.mix ?? MixProvider.of(context); | ||
final spec = ImageSpec.of(mix); | ||
|
||
final current = Image( | ||
image: image, | ||
frameBuilder: frameBuilder, | ||
loadingBuilder: loadingBuilder, | ||
errorBuilder: errorBuilder, | ||
semanticLabel: semanticLabel, | ||
excludeFromSemantics: excludeFromSemantics, | ||
width: spec.width, | ||
height: spec.height, | ||
color: spec.color, | ||
repeat: spec.repeat ?? ImageRepeat.noRepeat, | ||
fit: spec.fit, | ||
alignment: spec.alignment ?? Alignment.center, | ||
centerSlice: spec.centerSlice, | ||
filterQuality: spec.filterQuality ?? FilterQuality.none, | ||
colorBlendMode: spec.colorBlendMode ?? BlendMode.clear, | ||
); | ||
|
||
return shouldApplyDecorators( | ||
mix: mix, | ||
orderOfDecorators: decoratorOrder, | ||
child: current, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -529,4 +529,4 @@ packages: | |
source: hosted | ||
version: "3.1.2" | ||
sdks: | ||
dart: ">=3.2.0 <4.0.0" | ||
dart: ">=3.2.0-194.0.dev <4.0.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,6 @@ dev_dependencies: | |
mockito: ^5.4.2 | ||
meta: ^1.9.1 | ||
|
||
flutter: | ||
assets: | ||
- test_resources/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also add a
call()
method. One to keep in mind, though, is the call() method takes the actual Flutter core classes, not Dtos, if they exist.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will
call()
become the same as_only()
In this case?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One convention that I have been falling is called (), which is similar to _only or only, but it does not replace. call() has the Flutter core classes, and only has things like DTOs and etc.