mirror of
https://github.com/Iconica-Development/flutter_availability.git
synced 2025-05-19 13:13:44 +02:00
fix: reduce complicated ternary operators to simpler conditional statements
This commit is contained in:
parent
7b54809f6e
commit
9efbcbf48b
2 changed files with 87 additions and 97 deletions
|
@ -35,12 +35,14 @@ class AvailabilityTemplateSelection extends StatelessWidget {
|
||||||
var options = availabilityScope.options;
|
var options = availabilityScope.options;
|
||||||
var translations = options.translations;
|
var translations = options.translations;
|
||||||
|
|
||||||
// TODO(Joey): Do not nest ternairy operators
|
var titleText = translations.availabilityAddTemplateTitle;
|
||||||
var titleText = selectedTemplates.isEmpty
|
if (selectedTemplates.isEmpty) {
|
||||||
? translations.availabilityAddTemplateTitle
|
if (selectedTemplates.length > 1) {
|
||||||
: selectedTemplates.length > 1
|
titleText = translations.availabilityUsedTemplates;
|
||||||
? translations.availabilityUsedTemplates
|
} else {
|
||||||
: translations.availabilityUsedTemplate;
|
titleText = translations.availabilityUsedTemplate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var addButton = options.bigTextButtonWrapperBuilder(
|
var addButton = options.bigTextButtonWrapperBuilder(
|
||||||
context,
|
context,
|
||||||
|
|
|
@ -45,6 +45,8 @@ class _TemplateLegendState extends State<TemplateLegend> {
|
||||||
?.any((element) => element.template == null) ??
|
?.any((element) => element.template == null) ??
|
||||||
false;
|
false;
|
||||||
|
|
||||||
|
var templatesVisible = templatesAvailable && _templateDrawerOpen;
|
||||||
|
|
||||||
void onDrawerHeaderClick() {
|
void onDrawerHeaderClick() {
|
||||||
if (!templatesAvailable && !_templateDrawerOpen) {
|
if (!templatesAvailable && !_templateDrawerOpen) {
|
||||||
return;
|
return;
|
||||||
|
@ -72,6 +74,77 @@ class _TemplateLegendState extends State<TemplateLegend> {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Widget body = const Divider(
|
||||||
|
height: 1,
|
||||||
|
thickness: 1,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (_templateDrawerOpen && !templatesLoading) {
|
||||||
|
body = SingleChildScrollView(
|
||||||
|
controller: _scrollController,
|
||||||
|
child: Container(
|
||||||
|
constraints: const BoxConstraints(maxHeight: 152),
|
||||||
|
child: Scrollbar(
|
||||||
|
controller: _scrollController,
|
||||||
|
thumbVisibility: true,
|
||||||
|
trackVisibility: true,
|
||||||
|
thickness: 2,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
for (final (index, template) in templates.indexed) ...[
|
||||||
|
if (index == 0) ...[
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
top: 10,
|
||||||
|
left: 12,
|
||||||
|
),
|
||||||
|
child: _TemplateLegendItem(
|
||||||
|
name: translations.templateSelectionLabel,
|
||||||
|
backgroundColor: colors.selectedDayColor ??
|
||||||
|
colorScheme.primaryFixedDim,
|
||||||
|
borderColor: colorScheme.primary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (existAvailabilitiesWithoutTemplate) ...[
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
top: 10,
|
||||||
|
left: 12,
|
||||||
|
),
|
||||||
|
child: _TemplateLegendItem(
|
||||||
|
name: translations.availabilityWithoutTemplateLabel,
|
||||||
|
backgroundColor: colors.customAvailabilityColor ??
|
||||||
|
colorScheme.secondary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
] else ...[
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
top: 10,
|
||||||
|
left: 12,
|
||||||
|
),
|
||||||
|
child: _TemplateLegendItem(
|
||||||
|
name: template.name,
|
||||||
|
backgroundColor: Color(template.color),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
top: 10,
|
||||||
|
bottom: 8,
|
||||||
|
),
|
||||||
|
child: createNewTemplateButton,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
// a button to open/close a drawer with all the templates
|
// a button to open/close a drawer with all the templates
|
||||||
|
@ -106,101 +179,16 @@ class _TemplateLegendState extends State<TemplateLegend> {
|
||||||
constraints: BoxConstraints(maxHeight: _templateDrawerOpen ? 150 : 0),
|
constraints: BoxConstraints(maxHeight: _templateDrawerOpen ? 150 : 0),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
border: _templateDrawerOpen
|
border: _templateDrawerOpen
|
||||||
? Border.all(color: theme.colorScheme.onSurface, width: 1)
|
? Border.all(
|
||||||
|
color: theme.colorScheme.onSurface,
|
||||||
|
width: 1,
|
||||||
|
)
|
||||||
: null,
|
: null,
|
||||||
),
|
),
|
||||||
padding: const EdgeInsets.only(right: 2),
|
padding: const EdgeInsets.only(right: 2),
|
||||||
child: _templateDrawerOpen && !templatesLoading
|
child: body,
|
||||||
// TODO(Joey): A listview inside a scrollview inside the
|
|
||||||
// scrollable that each page has seems like really strange UX
|
|
||||||
// TODO(Joey): No ternary operators in the layout
|
|
||||||
? SingleChildScrollView(
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
Container(
|
|
||||||
constraints: const BoxConstraints(
|
|
||||||
// TODO(Joey): Not divisible by 4
|
|
||||||
maxHeight: 150,
|
|
||||||
),
|
|
||||||
child: Scrollbar(
|
|
||||||
controller: _scrollController,
|
|
||||||
thumbVisibility: true,
|
|
||||||
trackVisibility: true,
|
|
||||||
thickness: 2,
|
|
||||||
child: ListView.builder(
|
|
||||||
controller: _scrollController,
|
|
||||||
shrinkWrap: true,
|
|
||||||
// TODO(Joey): This seems like an odd way to
|
|
||||||
// implement appending items
|
|
||||||
itemCount: templates.length + 2,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
if (index == 0) {
|
|
||||||
// TODO(Joey): Extract this as a widget
|
|
||||||
return Column(
|
|
||||||
children: [
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
top: 10,
|
|
||||||
left: 12,
|
|
||||||
),
|
|
||||||
child: _TemplateLegendItem(
|
|
||||||
name:
|
|
||||||
translations.templateSelectionLabel,
|
|
||||||
backgroundColor:
|
|
||||||
colors.selectedDayColor ??
|
|
||||||
colorScheme.primaryFixedDim,
|
|
||||||
borderColor: colorScheme.primary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (existAvailabilitiesWithoutTemplate) ...[
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
top: 10,
|
|
||||||
left: 12,
|
|
||||||
),
|
|
||||||
child: _TemplateLegendItem(
|
|
||||||
name: translations
|
|
||||||
.availabilityWithoutTemplateLabel,
|
|
||||||
backgroundColor:
|
|
||||||
colors.customAvailabilityColor ??
|
|
||||||
colorScheme.secondary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (index == templates.length + 1) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
top: 10,
|
|
||||||
bottom: 8,
|
|
||||||
),
|
|
||||||
child: createNewTemplateButton,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
var template = templates[index - 1];
|
|
||||||
return _TemplateLegendItem(
|
|
||||||
name: template.name,
|
|
||||||
backgroundColor: Color(template.color),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: const Divider(
|
|
||||||
height: 1,
|
|
||||||
thickness: 1,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
// TODO(Joey): This is too complex of a check to read the layout
|
if (!templatesVisible) ...[
|
||||||
// There are 8 different combinations parameters with 2 different
|
|
||||||
// outcomes
|
|
||||||
if (!templatesAvailable &&
|
|
||||||
(!_templateDrawerOpen || templatesLoading)) ...[
|
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
if (templatesLoading) ...[
|
if (templatesLoading) ...[
|
||||||
options.loadingIndicatorBuilder(context),
|
options.loadingIndicatorBuilder(context),
|
||||||
|
|
Loading…
Reference in a new issue