Files
fcs/lib/pages/widgets/fcs_expansion_tile.dart

73 lines
2.1 KiB
Dart
Raw Permalink Normal View History

2020-10-07 02:33:06 +06:30
import 'package:fcs/helpers/theme.dart';
2020-09-15 07:13:41 +06:30
import 'package:flutter/material.dart';
2020-10-13 07:50:25 +06:30
import 'callbacks.dart';
2020-10-07 02:33:06 +06:30
2020-09-15 07:13:41 +06:30
class FcsExpansionTile extends StatefulWidget {
2021-09-10 14:25:37 +06:30
final ValueChanged<bool>? onExpansionChanged;
final CallBack? onEditPress;
final List<Widget>? children;
final Widget? title;
2020-09-15 07:13:41 +06:30
final bool isEdit;
const FcsExpansionTile(
{this.onExpansionChanged,
this.children,
this.title,
this.isEdit = false,
this.onEditPress});
@override
_FcsExpansionTileState createState() => _FcsExpansionTileState();
}
class _FcsExpansionTileState extends State<FcsExpansionTile> {
2021-09-10 14:25:37 +06:30
bool? expanded;
2020-09-15 07:13:41 +06:30
@override
void initState() {
this.expanded = false;
super.initState();
}
@override
Widget build(BuildContext context) {
return Theme(
data: ThemeData(
2024-01-09 13:11:22 +06:30
dividerColor: Colors.transparent,
colorScheme:
ColorScheme.fromSwatch().copyWith(secondary: primaryColor)),
2020-09-15 07:13:41 +06:30
child: ExpansionTile(
onExpansionChanged: (value) {
setState(() {
expanded = value;
});
if (widget.onExpansionChanged != null)
2021-09-10 14:25:37 +06:30
widget.onExpansionChanged!(value);
2020-09-15 07:13:41 +06:30
},
2021-09-10 14:25:37 +06:30
title: widget.title != null ? widget.title! : Container(),
children: widget.children != null ? widget.children! : [Container()],
2020-09-15 07:13:41 +06:30
trailing: widget.isEdit
? IconButton(
2020-09-18 21:33:41 +06:30
padding: EdgeInsets.all(0),
iconSize: 20,
2020-09-15 07:13:41 +06:30
onPressed: () =>
2021-09-10 14:25:37 +06:30
widget.onEditPress != null ? widget.onEditPress!() : {},
2020-09-15 07:13:41 +06:30
icon: Icon(
Icons.edit,
color: primaryColor,
))
: AnimatedSwitcher(
2021-09-10 14:25:37 +06:30
child: expanded!
2020-09-15 07:13:41 +06:30
? Icon(
Icons.remove,
color: primaryColor,
)
: Icon(
Icons.add,
color: primaryColor,
),
duration: Duration(seconds: 2)),
childrenPadding: EdgeInsets.all(18),
),
);
}
}