Skip to content

Commit

Permalink
fix: [MDS-801] Bump moon_flutter_icons version (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kypsis authored Nov 13, 2023
1 parent 06df110 commit fa6b0c5
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 31 deletions.
15 changes: 11 additions & 4 deletions example/lib/src/storybook/common/widgets/segment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,24 @@ class IconsSegment extends StatelessWidget {
}

return SliverPadding(
padding: const EdgeInsets.symmetric(vertical: 64.0, horizontal: 16.0),
padding: const EdgeInsets.symmetric(horizontal: 16.0),
sliver: SliverMainAxisGroup(
slivers: [
SliverToBoxAdapter(
child: TextDivider(text: createSegmentTitle(segmentMap.keys.first)),
SliverPadding(
padding: const EdgeInsets.only(top: 32),
sliver: SliverToBoxAdapter(
child: TextDivider(
text: createSegmentTitle(segmentMap.keys.first),
paddingBottom: 0,
),
),
),
SliverGrid.builder(
itemCount: segmentMap.length,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
crossAxisSpacing: 8,
mainAxisSpacing: 8,
mainAxisExtent: 104,
),
itemBuilder: (BuildContext context, int index) {
Expand All @@ -41,7 +48,7 @@ class IconsSegment extends StatelessWidget {
Icon(segmentMap.values.toList()[index], size: 24)
else
Icon(segmentMap.values.toList()[index], size: 32),
const SizedBox(height: 20),
const SizedBox(height: 16),
Text(
segmentMap.keys.toList()[index],
style: TextStyle(
Expand Down
67 changes: 42 additions & 25 deletions example/lib/src/storybook/stories/icons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ class IconsStory extends StatelessWidget {

const IconsStory({super.key});

@override
Widget build(BuildContext context) {
final ScrollBehavior scrollBehaviour = ScrollConfiguration.of(context).copyWith(
scrollbars: false,
overscroll: false,
dragDevices: {
PointerDeviceKind.touch,
PointerDeviceKind.mouse,
},
);
// Helper function to group keys in trios
List<List<String>> _groupInTrios(List<String> keys) {
final List<List<String>> trios = [];
for (int i = 0; i < keys.length; i += 3) {
trios.add(keys.sublist(i, min(i + 3, keys.length)));
}
return trios;
}

Map<String, Map<String, IconData>> segments = {};
Iterable<Map<String, IconData>> _getSortedIcons(Map<String, IconData> iconsMap) {
final Map<String, Map<String, IconData>> lightSegments = {};
final Map<String, Map<String, IconData>> regularSegments = {};

Expand Down Expand Up @@ -56,29 +54,48 @@ class IconsStory extends StatelessWidget {
final List<String> lightKeys = lightSegments[segment]?.keys.toList() ?? [];
final List<String> regularKeys = regularSegments[segment]?.keys.toList() ?? [];

// Iterate in steps of 3 for trios
final int maxLightIndex = (lightKeys.length / 3).ceil() * 3;
final int maxRegularIndex = (regularKeys.length / 3).ceil() * 3;
// Group the keys in trios
final List<List<String>> lightTrios = _groupInTrios(lightKeys);
final List<List<String>> regularTrios = _groupInTrios(regularKeys);

// Maximum number of trios in either list
final int maxTrios = max(lightTrios.length, regularTrios.length);

for (int i = 0; i < max(maxLightIndex, maxRegularIndex); i += 3) {
// Add up to three light icons
for (int j = i; j < min(i + 3, lightKeys.length); j++) {
final String key = lightKeys[j];
combinedSegments[segment]![key] = lightSegments[segment]![key]!;
for (int i = 0; i < maxTrios; i++) {
// Add light trios if available
if (i < lightTrios.length) {
for (final String key in lightTrios[i]) {
combinedSegments[segment]![key] = lightSegments[segment]![key]!;
}
}
// Add up to three regular icons
for (int j = i; j < min(i + 3, regularKeys.length); j++) {
final String key = regularKeys[j];
combinedSegments[segment]![key] = regularSegments[segment]![key]!;
// Add regular trios if available
if (i < regularTrios.length) {
for (final String key in regularTrios[i]) {
combinedSegments[segment]![key] = regularSegments[segment]![key]!;
}
}
}
}

segments = combinedSegments;
return combinedSegments.values;
}

@override
Widget build(BuildContext context) {
final ScrollBehavior scrollBehaviour = ScrollConfiguration.of(context).copyWith(
scrollbars: false,
overscroll: false,
dragDevices: {
PointerDeviceKind.touch,
PointerDeviceKind.mouse,
},
);

final sortedIcons = _getSortedIcons(iconsMap);

return CustomScrollView(
scrollBehavior: scrollBehaviour,
slivers: segments.values.map((e) => IconsSegment(segmentMap: e)).toList(),
slivers: sortedIcons.map((e) => IconsSegment(segmentMap: e)).toList(),
);
}
}
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies:
go_router: ^12.0.1
moon_design:
path: ../
moon_icons: ^0.1.8
moon_icons: ^0.2.1
package_info_plus: ^3.0.2
storybook_flutter:
git:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ environment:
dependencies:
flutter:
sdk: flutter
moon_icons: ^0.1.8
moon_icons: ^0.2.1

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit fa6b0c5

Please sign in to comment.