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.
122 lines
4.4 KiB
Dart
122 lines
4.4 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 'package:diplomaticquarterapp/extensions/string_extensions.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) {
|
|
String _mainTitle = (widget.title ?? TranslationBase.of(context).details);
|
|
String _title = _mainTitle.split(" ")[0];
|
|
String _subTitle = _mainTitle.replaceAll(_title, "").trim();
|
|
|
|
if (_subTitle.length < 1) {
|
|
_subTitle = _title.toLowerCase().capitalizeFirstofEach;
|
|
_title = "";
|
|
} else {
|
|
_subTitle = _subTitle.toLowerCase().capitalizeFirstofEach;
|
|
_title = _title.toLowerCase().capitalizeFirstofEach;
|
|
}
|
|
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: Padding(
|
|
padding: const EdgeInsets.only(top: 12, bottom: 12, left: 21, right: 21),
|
|
child: InkWell(
|
|
onTap: (){
|
|
setState(() {
|
|
widget.expandFlag = !widget.expandFlag;
|
|
widget.controller.expanded = widget.expandFlag;
|
|
});
|
|
},
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
if (_mainTitle.isNotEmpty)
|
|
Text(
|
|
_mainTitle,
|
|
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w600, color: Color(0xff2E303A), letterSpacing: -0.72, height: 1),
|
|
),
|
|
// Text(
|
|
// _subTitle,
|
|
// maxLines: 1,
|
|
// style: TextStyle(fontSize: 24, fontWeight: FontWeight.w700, color: Color(0xff2E303A), letterSpacing: -1.44, height: 25 / 24),
|
|
// ),
|
|
],
|
|
),
|
|
),
|
|
Icon(
|
|
widget.expandFlag ? Icons.keyboard_arrow_up : Icons.keyboard_arrow_down,
|
|
color: Color(0xff2E303A),
|
|
// size: 30.0,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
collapsed: widget.collapsed ?? Container(),
|
|
expanded: widget.bodyWidget,
|
|
builder: (_, collapsed, expanded) {
|
|
return Expandable(
|
|
controller: widget.controller,
|
|
collapsed: collapsed,
|
|
expanded: expanded,
|
|
theme: const ExpandableThemeData(crossFadePoint: 0),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|