Skip to content
This repository has been archived by the owner on Sep 22, 2024. It is now read-only.

Commit

Permalink
Refactored heading and section widget into separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
MASTERAMARJEET committed Mar 8, 2021
1 parent e9e832f commit b68eeb6
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 72 deletions.
83 changes: 11 additions & 72 deletions lib/details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,14 @@ import 'package:flutter/material.dart';

import './event/event_model.dart';
import './widgets/contact.dart';
import './widgets/heading.dart';
import './widgets/section.dart';

class DetailsPage extends StatelessWidget {
final EventDetail eventDetail;
DetailsPage(this.eventDetail);
@override
Widget build(BuildContext context) {
Widget sectionWidget(String title, List<String> list) {
if (list.length == 0) {
return Container();
}
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
alignment: Alignment.topLeft,
child: Text(
title,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
),
),
),
Padding(
padding: const EdgeInsets.only(
left: 20.0,
top: 8.0,
),
child: RichText(
text: TextSpan(
style: TextStyle(
color: Colors.black,
fontSize: 14,
fontWeight: FontWeight.w400,
),
children: list.map((e) => TextSpan(text: e + '\n\n')).toList(),
),
),
),
],
);
}

Widget headingWidget(String name, String desc) {
return Column(
children: [
Text(
name,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
Text(
desc,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18,
),
),
SizedBox(
height: 20.0,
),
],
);
}

return Scaffold(
appBar: AppBar(
title: Center(
Expand Down Expand Up @@ -138,19 +77,19 @@ class DetailsPage extends StatelessWidget {
),
child: ListView(
children: <Widget>[
headingWidget(
HeadingWidget(
eventDetail.name ?? "", eventDetail.shortDesc ?? ""),
sectionWidget("About:", eventDetail.about ?? []),
sectionWidget("Event Details:", eventDetail.details ?? []),
sectionWidget("Prizes:", eventDetail.prize ?? []),
sectionWidget("Judging Criteria:", eventDetail.judge ?? []),
sectionWidget("Eligibility Criteria:",
SectionWidget("About:", eventDetail.about ?? []),
SectionWidget("Event Details:", eventDetail.details ?? []),
SectionWidget("Prizes:", eventDetail.prize ?? []),
SectionWidget("Judging Criteria:", eventDetail.judge ?? []),
SectionWidget("Eligibility Criteria:",
eventDetail.rules?.eligible ?? []),
sectionWidget("Participant’s Guidelines:",
SectionWidget("Participant’s Guidelines:",
eventDetail.rules?.guide ?? []),
sectionWidget(
SectionWidget(
"Submission details:", eventDetail.submission ?? []),
sectionWidget("Event timeline:", eventDetail.timeline ?? []),
SectionWidget("Event timeline:", eventDetail.timeline ?? []),
ContactWidget("Contact Details", eventDetail.contact ?? []),
],
)),
Expand Down
32 changes: 32 additions & 0 deletions lib/widgets/heading.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:flutter/material.dart';

class HeadingWidget extends StatelessWidget {
final String name;
final String desc;
HeadingWidget(this.name, this.desc);
@override
Widget build(BuildContext context) {
return Column(
children: [
Text(
name,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
Text(
desc,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18,
),
),
SizedBox(
height: 20.0,
),
],
);
}
}
45 changes: 45 additions & 0 deletions lib/widgets/section.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'package:flutter/material.dart';

class SectionWidget extends StatelessWidget {
final String title;
final List<String> list;
SectionWidget(this.title, this.list);
@override
Widget build(BuildContext context) {
if (list.length == 0) {
return Container();
}
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
alignment: Alignment.topLeft,
child: Text(
title,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
),
),
),
Padding(
padding: const EdgeInsets.only(
left: 20.0,
top: 8.0,
),
child: RichText(
text: TextSpan(
style: TextStyle(
color: Colors.black,
fontSize: 14,
fontWeight: FontWeight.w400,
),
children: list.map((e) => TextSpan(text: e + '\n\n')).toList(),
),
),
),
],
);
}
}

0 comments on commit b68eeb6

Please sign in to comment.