Refactoring
This commit is contained in:
83
lib/widgets/content_block.dart
Normal file
83
lib/widgets/content_block.dart
Normal file
@@ -0,0 +1,83 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:resume/widgets/content_list_tile.dart';
|
||||
import 'package:resume/widgets/language_widget.dart';
|
||||
import 'package:resume/constants.dart' show ContentType;
|
||||
|
||||
import '../services/content_provider.dart';
|
||||
|
||||
class ContentBlock extends StatelessWidget {
|
||||
const ContentBlock({
|
||||
super.key,
|
||||
required this.blockTitle,
|
||||
required this.contentType,
|
||||
});
|
||||
|
||||
final String blockTitle;
|
||||
final ContentType contentType;
|
||||
|
||||
Widget get _getContentWidget {
|
||||
if (contentType == ContentType.language) {
|
||||
return const LanguageWidget();
|
||||
} else if (contentType == ContentType.text) {
|
||||
final content = ContentProvider.getContent<String>(ContentType.text);
|
||||
return Text(content);
|
||||
}
|
||||
// List-based content-blocks
|
||||
List<dynamic> content =
|
||||
ContentProvider.getContent<List<dynamic>>(contentType);
|
||||
List<Widget> widgets = [];
|
||||
for (var item in content) {
|
||||
widgets.add(_buildListTile(item));
|
||||
}
|
||||
return Column(
|
||||
children: widgets,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
blockTitle,
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
),
|
||||
const Padding(padding: EdgeInsets.only(bottom: 8)),
|
||||
_getContentWidget,
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildListTile(Map data) {
|
||||
if (contentType == ContentType.experience) {
|
||||
return ContentListTile.experience(
|
||||
name: data['name'],
|
||||
location: data['location'],
|
||||
title: data['title'],
|
||||
description: data['description'],
|
||||
startDate: data['startDate'],
|
||||
endDate: data['endDate'],
|
||||
);
|
||||
} else if (contentType == ContentType.education) {
|
||||
return ContentListTile.education(
|
||||
name: data['name'],
|
||||
location: data['location'],
|
||||
title: data['title'],
|
||||
startDate: data['startDate'],
|
||||
endDate: data['endDate'],
|
||||
);
|
||||
} else {
|
||||
return ContentListTile.skills(
|
||||
name: data['name'],
|
||||
percentage: data['percentage'],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user