Skip to content

Commit 411fa53

Browse files
WIP - refactored custom expansion tile, added server endpoint for updating kindergarden info
1 parent abf5567 commit 411fa53

38 files changed

Lines changed: 1272 additions & 2146 deletions

File tree

school_data_hub_client/lib/src/protocol/client.dart

Lines changed: 197 additions & 182 deletions
Large diffs are not rendered by default.

school_data_hub_flutter/lib/common/widgets/custom_expansion_tile/custom_expansion_tile.dart

Lines changed: 0 additions & 829 deletions
This file was deleted.

school_data_hub_flutter/lib/common/widgets/custom_expansion_tile/custom_expansion_tile_content.dart

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,65 @@
11
import 'package:flutter/material.dart';
2-
import 'package:school_data_hub_flutter/common/widgets/custom_expansion_tile/custom_expansion_tile.dart';
2+
import 'package:flutter_it/flutter_it.dart';
3+
import 'package:school_data_hub_flutter/common/widgets/custom_expansion_tile/custom_expansion_tile_controller.dart';
34

4-
class CustomExpansionTileContent extends StatelessWidget {
5-
final List<Widget> widgetList;
6-
final CustomExpansionTileController? tileController;
5+
class CustomExpansionTileContent extends WatchingStatefulWidget {
76
final Widget? title;
7+
final List<Widget> widgetList;
8+
final CustomExpansionTileController tileController;
9+
10+
const CustomExpansionTileContent({
11+
super.key,
12+
required this.widgetList,
13+
this.title,
14+
required this.tileController,
15+
});
16+
17+
@override
18+
State<CustomExpansionTileContent> createState() =>
19+
_CustomExpansionTileContentState();
20+
}
21+
22+
// Use TickerProviderStateMixin to provide 'vsync'
23+
class _CustomExpansionTileContentState extends State<CustomExpansionTileContent>
24+
with TickerProviderStateMixin {
25+
late AnimationController _animController;
26+
27+
@override
28+
void initState() {
29+
super.initState();
30+
_animController = AnimationController(
31+
vsync: this, // 'this' works because of the Mixin
32+
duration: const Duration(milliseconds: 200),
33+
);
34+
}
835

9-
const CustomExpansionTileContent(
10-
{super.key, required this.widgetList, this.tileController, this.title});
36+
@override
37+
void dispose() {
38+
_animController.dispose();
39+
super.dispose();
40+
}
1141

1242
@override
1343
Widget build(BuildContext context) {
14-
return ListTileTheme(
15-
contentPadding: const EdgeInsets.all(0),
16-
dense: true,
17-
horizontalTitleGap: 0.0,
18-
minLeadingWidth: 0,
19-
minVerticalPadding: 0,
20-
tileColor: Colors.transparent,
21-
child: Theme(
22-
data: Theme.of(context).copyWith(dividerColor: Colors.transparent),
23-
child: Padding(
24-
padding: const EdgeInsets.only(bottom: 2.0),
25-
child: CustomExpansionTile(
26-
collapsedBackgroundColor: Colors.transparent,
27-
tilePadding: const EdgeInsets.all(0),
28-
title: title ?? const SizedBox.shrink(),
29-
controller: tileController,
30-
children: [...widgetList]),
31-
),
44+
// Access 'watch' via the watch_it mixin functionality in WatchingStatefulWidget
45+
final isExpanded = watch(widget.tileController.isExpanded).value;
46+
47+
// Drive the animation
48+
if (isExpanded) {
49+
_animController.forward();
50+
} else {
51+
_animController.reverse();
52+
}
53+
54+
return SizeTransition(
55+
sizeFactor: CurvedAnimation(
56+
parent: _animController,
57+
curve: Curves.easeIn,
58+
),
59+
axisAlignment: -1.0,
60+
child: Column(
61+
crossAxisAlignment: CrossAxisAlignment.stretch,
62+
children: widget.widgetList,
3263
),
3364
);
3465
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import 'package:flutter/foundation.dart';
2+
3+
class CustomExpansionTileController {
4+
CustomExpansionTileController({bool initiallyExpanded = false})
5+
: isExpanded = ValueNotifier<bool>(initiallyExpanded);
6+
7+
final ValueNotifier<bool> isExpanded;
8+
9+
void expand() => isExpanded.value = true;
10+
void collapse() => isExpanded.value = false;
11+
void toggle() => isExpanded.value = !isExpanded.value;
12+
13+
void dispose() => isExpanded.dispose();
14+
}

school_data_hub_flutter/lib/common/widgets/custom_expansion_tile/custom_expansion_tile_switch.dart

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter_it/flutter_it.dart';
23
import 'package:gap/gap.dart';
3-
import 'package:school_data_hub_flutter/common/widgets/custom_expansion_tile/custom_expansion_tile.dart';
4+
import 'package:school_data_hub_flutter/common/widgets/custom_expansion_tile/custom_expansion_tile_controller.dart';
45

5-
class CustomExpansionTileSwitch extends StatefulWidget {
6+
class CustomExpansionTileSwitch extends WatchingWidget {
67
final Widget? expansionSwitchWidget;
78
final bool? includeSwitch;
89
final Color? switchColor;
910
final CustomExpansionTileController customExpansionTileController;
1011
final ValueChanged<bool>? onChanged;
12+
1113
const CustomExpansionTileSwitch({
1214
this.expansionSwitchWidget,
1315
this.includeSwitch,
@@ -17,59 +19,37 @@ class CustomExpansionTileSwitch extends StatefulWidget {
1719
super.key,
1820
});
1921

20-
@override
21-
CustomExpansionTileSwitchState createState() =>
22-
CustomExpansionTileSwitchState();
23-
}
24-
25-
class CustomExpansionTileSwitchState extends State<CustomExpansionTileSwitch> {
26-
late final CustomExpansionTileController _tileController;
27-
bool isExpanded = false;
28-
@override
29-
void initState() {
30-
_tileController = widget.customExpansionTileController;
31-
super.initState();
32-
}
33-
3422
@override
3523
Widget build(BuildContext context) {
24+
final isExpanded = watch(customExpansionTileController.isExpanded).value;
25+
3626
return InkWell(
3727
onTap: () {
38-
if (_tileController.isExpanded) {
39-
_tileController.collapse();
40-
setState(() {
41-
isExpanded = false;
42-
});
43-
} else {
44-
_tileController.expand();
45-
setState(() {
46-
isExpanded = true;
47-
});
48-
}
49-
widget.onChanged?.call(isExpanded);
28+
customExpansionTileController.toggle();
29+
onChanged?.call(customExpansionTileController.isExpanded.value);
5030
},
5131
child:
52-
widget.expansionSwitchWidget != null &&
53-
widget.includeSwitch != null &&
54-
widget.includeSwitch == true
32+
expansionSwitchWidget != null &&
33+
includeSwitch != null &&
34+
includeSwitch == true
5535
? Row(
5636
mainAxisAlignment: MainAxisAlignment.end,
5737
children: [
58-
widget.expansionSwitchWidget!,
38+
expansionSwitchWidget!,
5939
const Gap(10),
6040
Icon(
6141
isExpanded
6242
? Icons.keyboard_arrow_up
6343
: Icons.keyboard_arrow_down,
64-
color: widget.switchColor!,
44+
color: switchColor!,
6545
),
6646
],
6747
)
68-
: widget.expansionSwitchWidget != null && widget.includeSwitch != true
69-
? widget.expansionSwitchWidget
48+
: expansionSwitchWidget != null && includeSwitch != true
49+
? expansionSwitchWidget
7050
: Icon(
7151
isExpanded ? Icons.keyboard_arrow_up : Icons.keyboard_arrow_down,
72-
color: widget.switchColor ?? Colors.white,
52+
color: switchColor ?? Colors.white,
7353
),
7454
);
7555
}

school_data_hub_flutter/lib/common/widgets/custom_expansion_tile/custom_expasion_tile_hook.dart

Lines changed: 0 additions & 32 deletions
This file was deleted.

school_data_hub_flutter/lib/common/widgets/custom_expansion_tile/hub_expansion_tile.dart

Lines changed: 0 additions & 159 deletions
This file was deleted.

0 commit comments

Comments
 (0)