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

Remove local definition of mapIndexed and forEachIndexed in example #452

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ class _RenderCorePalette extends StatelessWidget {
corePalette.neutralVariant.asList,
];
return Column(
children: colors.mapIndexed(
(List<int> tones, int i) {
return Row(
children: [
for (final (int i, List<int> tones) in colors.indexed)
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
Expand All @@ -172,42 +172,28 @@ class _RenderCorePalette extends StatelessWidget {
),
),
const SizedBox(width: 16),
...tones.mapIndexed((int color, int i) {
final toneValue = TonalPalette.commonTones[i];
return Container(
for (final (int i, int color) in tones.indexed)
Container(
constraints: const BoxConstraints.tightFor(
height: 80,
width: 60,
),
color: Color(color),
child: Center(
child: Text(
toneValue.toString(),
TonalPalette.commonTones[i].toString(),
style: captionStyle!.copyWith(
// For contrast
color: toneValue > 50 ? Colors.black : Colors.white,
color: TonalPalette.commonTones[i] > 50
? Colors.black
: Colors.white,
),
),
),
);
}),
),
],
);
},
).toList(),
),
],
);
}
}

extension ExtendedIterable<E> on Iterable<E> {
/// Like Iterable<T>.map but the callback has index as second argument.
Iterable<T> mapIndexed<T>(T Function(E e, int i) f) {
var i = 0;
return map((e) => f(e, i++));
}

void forEachIndexed(void Function(E e, int i) f) {
var i = 0;
forEach((e) => f(e, i++));
}
}
20 changes: 10 additions & 10 deletions packages/dynamic_color/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.6.5"
version: "1.6.6"
fake_async:
dependency: transitive
description:
Expand All @@ -82,14 +82,6 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
js:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.7"
lints:
dependency: transitive
description:
Expand Down Expand Up @@ -191,6 +183,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
web:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
sdks:
dart: ">=3.0.0-0 <4.0.0"
dart: ">=3.1.0-185.0.dev <4.0.0"
flutter: ">=3.4.0-17.0.pre"
2 changes: 1 addition & 1 deletion packages/dynamic_color/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: Demonstrates how to use the dynamic_color package.
publish_to: "none" # Remove this line if you wish to publish to pub.dev

environment:
sdk: ">=2.17.0-0 <4.0.0"
sdk: ">=3.0.0 <4.0.0"
Copy link
Contributor Author

@ebraminio ebraminio Aug 18, 2023

Choose a reason for hiding this comment

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

I had to do this in order to have access to record destructing syntax.


# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
Expand Down
18 changes: 9 additions & 9 deletions packages/dynamic_color/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.18.1"
js:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.7"
json_annotation:
dependency: transitive
description:
Expand Down Expand Up @@ -272,6 +264,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.1.1"
web:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
yaml:
dependency: transitive
description:
Expand All @@ -281,5 +281,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.0.0 <4.0.0"
dart: ">=3.1.0-185.0.dev <4.0.0"
flutter: ">=3.4.0-17.0.pre"