Refactoring
This commit is contained in:
@@ -1,90 +1,156 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:resume/services/breakpoints.dart';
|
||||
import 'package:resume/constants.dart' show ContentType;
|
||||
|
||||
import '../services/tools.dart';
|
||||
|
||||
class ContentListTile extends StatelessWidget {
|
||||
const ContentListTile(
|
||||
const ContentListTile.education(
|
||||
{super.key,
|
||||
this.name,
|
||||
this.location,
|
||||
this.title,
|
||||
this.description,
|
||||
this.startDate,
|
||||
this.endDate});
|
||||
required this.name,
|
||||
required this.location,
|
||||
required this.title,
|
||||
required this.startDate,
|
||||
required this.endDate})
|
||||
: description = '',
|
||||
percentage = '',
|
||||
_contentType = ContentType.education;
|
||||
|
||||
final String? name;
|
||||
final String? location;
|
||||
final String? title;
|
||||
final String? description;
|
||||
final String? startDate;
|
||||
final String? endDate;
|
||||
const ContentListTile.experience(
|
||||
{super.key,
|
||||
required this.name,
|
||||
required this.location,
|
||||
required this.title,
|
||||
required this.description,
|
||||
required this.startDate,
|
||||
required this.endDate})
|
||||
: percentage = '',
|
||||
_contentType = ContentType.experience;
|
||||
|
||||
const ContentListTile.skills(
|
||||
{super.key, required this.name, required this.percentage})
|
||||
: description = '',
|
||||
title = ',',
|
||||
location = '',
|
||||
startDate = '',
|
||||
endDate = '',
|
||||
_contentType = ContentType.skills;
|
||||
|
||||
final String description;
|
||||
final String endDate;
|
||||
final String location;
|
||||
final String name;
|
||||
final String percentage;
|
||||
final String startDate;
|
||||
final String title;
|
||||
|
||||
final ContentType _contentType;
|
||||
|
||||
Widget get _skillsListTile => ListTile(
|
||||
contentPadding: const EdgeInsets.all(0),
|
||||
title: Row(
|
||||
children: [
|
||||
Expanded(flex: 2, child: Text(name)),
|
||||
const Padding(padding: EdgeInsets.only(bottom: 8)),
|
||||
Expanded(
|
||||
flex: 5,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: LinearProgressIndicator(
|
||||
value: double.tryParse(percentage) ?? 1 / 100,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Widget _getEducationListTile(BuildContext context, double screenWidth) =>
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.all(0),
|
||||
title: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
name,
|
||||
),
|
||||
Text(', $location'),
|
||||
if (Breakpoints.xl < screenWidth) Text(' - $title'),
|
||||
],
|
||||
),
|
||||
if (Breakpoints.xl >= screenWidth) Text(title),
|
||||
],
|
||||
),
|
||||
titleAlignment: ListTileTitleAlignment.titleHeight,
|
||||
subtitle: Breakpoints.sm >= screenWidth
|
||||
? Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Text(
|
||||
Tools.buildTimeString(startDate, endDate),
|
||||
style: Theme.of(context).textTheme.labelSmall,
|
||||
),
|
||||
)
|
||||
: null,
|
||||
trailing: Breakpoints.sm < screenWidth
|
||||
? Text(Tools.buildTimeString(startDate, endDate))
|
||||
: null,
|
||||
);
|
||||
|
||||
Widget _getExperienceListTile(BuildContext context, double screenWidth) =>
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.all(0),
|
||||
title: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
name,
|
||||
),
|
||||
Text(', $location'),
|
||||
if (Breakpoints.xl < screenWidth) Text(' - $title'),
|
||||
],
|
||||
),
|
||||
if (Breakpoints.xl >= screenWidth) Text(title),
|
||||
],
|
||||
),
|
||||
titleAlignment: ListTileTitleAlignment.titleHeight,
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Padding(padding: EdgeInsets.only(top: 8)),
|
||||
if (Breakpoints.sm >= screenWidth)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Text(
|
||||
Tools.buildTimeString(startDate, endDate),
|
||||
style: Theme.of(context).textTheme.labelSmall,
|
||||
),
|
||||
),
|
||||
Text(description),
|
||||
],
|
||||
),
|
||||
trailing: Breakpoints.sm < screenWidth
|
||||
? Text(Tools.buildTimeString(startDate, endDate))
|
||||
: null,
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final width = MediaQuery.of(context).size.width;
|
||||
|
||||
return ListTile(
|
||||
contentPadding: const EdgeInsets.all(0),
|
||||
title: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
if (name != null)
|
||||
Text(
|
||||
name!,
|
||||
),
|
||||
if (location != null) Text(', $location'),
|
||||
if (title != null && Breakpoints.xl < width) Text(' - $title'),
|
||||
],
|
||||
),
|
||||
if (title != null && Breakpoints.xl >= width) Text('$title'),
|
||||
],
|
||||
),
|
||||
titleAlignment: ListTileTitleAlignment.titleHeight,
|
||||
subtitle: description != null
|
||||
? Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Padding(padding: EdgeInsets.only(top: 8)),
|
||||
if (startDate != null &&
|
||||
endDate != null &&
|
||||
Breakpoints.sm >= width)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Text(
|
||||
_getTimeString(startDate!, endDate!),
|
||||
style: Theme.of(context).textTheme.labelSmall,
|
||||
),
|
||||
),
|
||||
Text(description!),
|
||||
],
|
||||
)
|
||||
: null,
|
||||
trailing: startDate != null && endDate != null && Breakpoints.sm < width
|
||||
? Text(_getTimeString(startDate!, endDate!))
|
||||
: null,
|
||||
);
|
||||
if (_contentType == ContentType.skills) {
|
||||
return _skillsListTile;
|
||||
} else if (_contentType == ContentType.education) {
|
||||
return _getEducationListTile(context, width);
|
||||
} else if (_contentType == ContentType.experience) {
|
||||
return _getExperienceListTile(context, width);
|
||||
} else {
|
||||
return const Placeholder();
|
||||
}
|
||||
}
|
||||
|
||||
String _getTimeString(String startDate, String endDate) {
|
||||
final firstDate = DateTime.parse('$startDate-01');
|
||||
final secondDate = DateTime.parse('$endDate-01');
|
||||
return '${months[firstDate.month - 1]} ${firstDate.year} - ${months[secondDate.month - 1]} ${secondDate.year}';
|
||||
}
|
||||
|
||||
static const months = [
|
||||
'Januar',
|
||||
'Februar',
|
||||
'März',
|
||||
'April',
|
||||
'Mai',
|
||||
'Juni',
|
||||
'July',
|
||||
'August',
|
||||
'September',
|
||||
'Oktober',
|
||||
'November',
|
||||
'Dezember'
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user