Skip to content

Commit

Permalink
display number of items in tree cards (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansen4857 authored Oct 6, 2023
1 parent 5f04e22 commit c86ac9b
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/widgets/editor/tree_widgets/constraint_zones_tree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:pathplanner/path/constraints_zone.dart';
import 'package:pathplanner/path/pathplanner_path.dart';
import 'package:pathplanner/path/waypoint.dart';
import 'package:pathplanner/widgets/editor/tree_widgets/item_count.dart';
import 'package:pathplanner/widgets/editor/tree_widgets/tree_card_node.dart';
import 'package:pathplanner/widgets/number_text_field.dart';
import 'package:pathplanner/widgets/renamable_title.dart';
Expand Down Expand Up @@ -56,6 +57,7 @@ class _ConstraintZonesTreeState extends State<ConstraintZonesTree> {
Widget build(BuildContext context) {
return TreeCardNode(
title: const Text('Constraint Zones'),
trailing: ItemCount(count: widget.path.constraintZones.length),
initiallyExpanded: widget.path.constraintZonesExpanded,
onExpansionChanged: (value) {
if (value != null) {
Expand Down
2 changes: 2 additions & 0 deletions lib/widgets/editor/tree_widgets/event_markers_tree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:pathplanner/path/event_marker.dart';
import 'package:pathplanner/path/pathplanner_path.dart';
import 'package:pathplanner/path/waypoint.dart';
import 'package:pathplanner/widgets/editor/tree_widgets/commands/command_group_widget.dart';
import 'package:pathplanner/widgets/editor/tree_widgets/item_count.dart';
import 'package:pathplanner/widgets/editor/tree_widgets/tree_card_node.dart';
import 'package:pathplanner/widgets/renamable_title.dart';
import 'package:undo/undo.dart';
Expand Down Expand Up @@ -54,6 +55,7 @@ class _EventMarkersTreeState extends State<EventMarkersTree> {
Widget build(BuildContext context) {
return TreeCardNode(
title: const Text('Event Markers'),
trailing: ItemCount(count: widget.path.eventMarkers.length),
initiallyExpanded: widget.path.eventMarkersExpanded,
onExpansionChanged: (value) {
if (value != null) {
Expand Down
34 changes: 34 additions & 0 deletions lib/widgets/editor/tree_widgets/item_count.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:flutter/material.dart';

class ItemCount extends StatelessWidget {
final int count;

const ItemCount({
super.key,
required this.count,
});

@override
Widget build(BuildContext context) {
ColorScheme colorScheme = Theme.of(context).colorScheme;

return Container(
width: 28,
height: 28,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(14),
border: Border.all(width: 2, color: colorScheme.surfaceVariant),
),
child: FittedBox(
fit: BoxFit.scaleDown,
child: Text(
'$count',
style: TextStyle(
fontSize: 24,
color: colorScheme.surfaceVariant,
),
),
),
);
}
}
2 changes: 2 additions & 0 deletions lib/widgets/editor/tree_widgets/rotation_targets_tree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:pathplanner/path/pathplanner_path.dart';
import 'package:pathplanner/path/rotation_target.dart';
import 'package:pathplanner/path/waypoint.dart';
import 'package:pathplanner/widgets/editor/tree_widgets/item_count.dart';
import 'package:pathplanner/widgets/editor/tree_widgets/tree_card_node.dart';
import 'package:pathplanner/widgets/number_text_field.dart';
import 'package:undo/undo.dart';
Expand Down Expand Up @@ -53,6 +54,7 @@ class _RotationTargetsTreeState extends State<RotationTargetsTree> {
Widget build(BuildContext context) {
return TreeCardNode(
title: const Text('Rotation Targets'),
trailing: ItemCount(count: widget.path.rotationTargets.length),
initiallyExpanded: widget.path.rotationTargetsExpanded,
onExpansionChanged: (value) {
if (value != null) {
Expand Down
3 changes: 3 additions & 0 deletions lib/widgets/editor/tree_widgets/tree_card_node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class TreeCardNode extends StatelessWidget {
final bool initiallyExpanded;
final ExpansionTileController? controller;
final ValueChanged<bool?>? onExpansionChanged;
final Widget? trailing;

const TreeCardNode({
super.key,
Expand All @@ -22,6 +23,7 @@ class TreeCardNode extends StatelessWidget {
this.initiallyExpanded = false,
this.controller,
this.onExpansionChanged,
this.trailing,
});

@override
Expand All @@ -36,6 +38,7 @@ class TreeCardNode extends StatelessWidget {
onExit: (event) => onHoverEnd?.call(),
child: ExpansionTile(
title: title,
trailing: trailing,
controller: controller,
maintainState: false,
onExpansionChanged: onExpansionChanged,
Expand Down
2 changes: 2 additions & 0 deletions lib/widgets/editor/tree_widgets/waypoints_tree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:pathplanner/path/event_marker.dart';
import 'package:pathplanner/path/pathplanner_path.dart';
import 'package:pathplanner/path/rotation_target.dart';
import 'package:pathplanner/path/waypoint.dart';
import 'package:pathplanner/widgets/editor/tree_widgets/item_count.dart';
import 'package:pathplanner/widgets/editor/tree_widgets/tree_card_node.dart';
import 'package:pathplanner/widgets/number_text_field.dart';
import 'package:undo/undo.dart';
Expand Down Expand Up @@ -61,6 +62,7 @@ class _WaypointsTreeState extends State<WaypointsTree> {
Widget build(BuildContext context) {
return TreeCardNode(
title: const Text('Waypoints'),
trailing: ItemCount(count: widget.path.waypoints.length),
initiallyExpanded: widget.path.waypointsExpanded,
controller: _expansionController,
onExpansionChanged: (value) {
Expand Down
29 changes: 29 additions & 0 deletions test/widgets/editor/tree_widgets/item_count_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pathplanner/widgets/editor/tree_widgets/item_count.dart';

void main() {
testWidgets('item count', (widgetTester) async {
await widgetTester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: ItemCount(count: 5),
),
),
);

expect(find.byType(Text), findsOneWidget);
expect(find.text('5'), findsOneWidget);

await widgetTester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: ItemCount(count: 7),
),
),
);

expect(find.byType(Text), findsOneWidget);
expect(find.text('7'), findsOneWidget);
});
}

0 comments on commit c86ac9b

Please sign in to comment.