Skip to content

Commit

Permalink
Remove local definition of mapIndexed and forEachIndexed in example (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ebraminio authored Sep 4, 2023
1 parent c31d979 commit ed2b72a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 38 deletions.
38 changes: 12 additions & 26 deletions packages/dynamic_color/example/lib/core_palette_visualization.dart
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"

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
Expand Down
2 changes: 1 addition & 1 deletion packages/dynamic_color/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit ed2b72a

Please sign in to comment.