You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HMG_Patient_App/lib/widgets/others/app_expandable_notifier.dart

98 lines
3.2 KiB
Dart

import 'package:diplomaticquarterapp/config/size_config.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:expandable/expandable.dart';
import 'package:flutter/material.dart';
import '../../Constants.dart';
/// App Expandable Notifier with animation
/// [headerWidget] widget want to show in the header
/// [bodyWidget] widget want to show in the body
/// [title] the widget title
/// [collapsed] The widget shown in the collapsed state
class AppExpandableNotifier extends StatefulWidget {
final Widget headerWidget;
final Widget bodyWidget;
final String title;
final Widget collapsed;
final bool isExpand;
bool expandFlag = false;
var controller = new ExpandableController();
AppExpandableNotifier({this.headerWidget, this.bodyWidget, this.title, this.collapsed, this.isExpand = false});
_AppExpandableNotifier createState() => _AppExpandableNotifier();
}
class _AppExpandableNotifier extends State<AppExpandableNotifier> {
@override
void initState() {
setState(() {
if (widget.isExpand) {
widget.expandFlag = widget.isExpand;
widget.controller.expanded = true;
}
});
super.initState();
}
@override
Widget build(BuildContext context) {
return ExpandableNotifier(
child: Column(
children: <Widget>[
SizedBox(
child: widget.headerWidget,
),
ScrollOnExpand(
scrollOnExpand: true,
scrollOnCollapse: false,
child: ExpandablePanel(
hasIcon: false,
theme: const ExpandableThemeData(
headerAlignment: ExpandablePanelHeaderAlignment.center,
tapBodyToCollapse: true,
),
header: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
Expanded(
child: Padding(
padding: EdgeInsets.all(10),
child: Text(
widget.title ?? TranslationBase.of(context).details,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: SizeConfig.textMultiplier * 2,
),
),
),
),
IconButton(
icon: Icon(
widget.expandFlag ? Icons.remove : Icons.add,
color: Color(0xff2E303A),
// size: 30.0,
),
onPressed: () {
setState(() {
widget.expandFlag = !widget.expandFlag;
widget.controller.expanded = widget.expandFlag;
});
}),
]),
collapsed: widget.collapsed ?? Container(),
expanded: widget.bodyWidget,
builder: (_, collapsed, expanded) {
return Expandable(
controller: widget.controller,
collapsed: collapsed,
expanded: expanded,
theme: const ExpandableThemeData(crossFadePoint: 0),
);
},
),
),
],
),
);
}
}