-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
510 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,169 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:fyx/components/post/PostAvatar.dart'; | ||
import 'package:fyx/components/post/PostHeroAttachment.dart'; | ||
import 'package:fyx/components/post/PostHtml.dart'; | ||
import 'package:fyx/model/UserReferences.dart'; | ||
import 'package:fyx/model/enums/AdEnums.dart'; | ||
import 'package:fyx/model/post/Image.dart' as i; | ||
import 'package:fyx/model/post/content/Advertisement.dart'; | ||
import 'package:fyx/theme/Helpers.dart'; | ||
import 'package:fyx/theme/T.dart'; | ||
|
||
class Advertisement extends StatelessWidget { | ||
final ContentAdvertisement content; | ||
final String title; // Ad title can be overwritten. Helpful in discussion page where content.fullName is null. | ||
final String username; | ||
|
||
const Advertisement(this.content, {this.title}); | ||
// If this widget needs to be displayed within PostListItem (in discussion) or as a standalone widget (pinned to pull-to-refresh) | ||
bool get isStandaloneWidget => this.username is String && this.username.isNotEmpty; | ||
|
||
String get heading => this.title ?? (content.fullName ?? ''); | ||
|
||
const Advertisement(this.content, {this.title, this.username}); | ||
|
||
Widget buildPriceWidget(BuildContext context) { | ||
return Container( | ||
padding: const EdgeInsets.all(6), | ||
child: Text('${content.price.toString()} ${content.currency}', | ||
style: DefaultTextStyle | ||
.of(context) | ||
.style | ||
.copyWith(fontSize: 16, fontWeight: FontWeight.bold, color: T.COLOR_PRIMARY)), | ||
decoration: BoxDecoration(color: Color(0xffa9ccd3), borderRadius: BorderRadius.circular(6))); | ||
} | ||
|
||
Widget buildTitleWidget(BuildContext context) { | ||
return Text(heading, style: DefaultTextStyle | ||
.of(context) | ||
.style | ||
.copyWith(fontSize: 20, fontWeight: FontWeight.bold)); | ||
} | ||
|
||
Widget buildRefrencesWidget(BuildContext context) { | ||
if (content.references is UserReferences) { | ||
return RichText( | ||
text: TextSpan(children: [ | ||
TextSpan(text: 'Reference: ', style: TextStyle(color: Colors.black38, fontSize: 10)), | ||
if (content.references.positive > 0) TextSpan(text: '+${content.references.positive}', style: TextStyle(color: T.COLOR_PRIMARY, fontSize: 10)), | ||
if (content.references.positive > 0 && content.references.negative < 0) TextSpan(text: ' / ', style: TextStyle(color: Colors.black38, fontSize: 10)), | ||
if (content.references.negative < 0) TextSpan(text: '-${content.references.negative}', style: TextStyle(color: T.COLOR_ACCENT, fontSize: 10)) | ||
]), | ||
); | ||
} | ||
|
||
return Text(''); | ||
} | ||
|
||
Widget buildIconLabelWidget(IconData icon, String label, BuildContext context) { | ||
return Container( | ||
child: Row( | ||
children: [ | ||
Icon( | ||
icon, | ||
size: 14, | ||
), | ||
SizedBox(width: 6), | ||
Text( | ||
label, | ||
style: DefaultTextStyle | ||
.of(context) | ||
.style | ||
.copyWith(fontSize: 12), | ||
), | ||
], | ||
), | ||
//decoration: BoxDecoration(color: T.COLOR_LIGHT, borderRadius: BorderRadius.circular(6), border: Border.all(color: T.COLOR_PRIMARY)), | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
String heading = this.title ?? (content.fullName ?? ''); | ||
|
||
return Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Row( | ||
mainAxisSize: MainAxisSize.max, | ||
crossAxisAlignment: CrossAxisAlignment.baseline, | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
children: [ | ||
if (heading.isNotEmpty) Flexible(child: Text(heading, style: DefaultTextStyle.of(context).style.copyWith(fontSize: 20, fontWeight: FontWeight.bold))), | ||
if (content.price > 0) Container( | ||
padding: const EdgeInsets.all(6), | ||
child: Text('${content.price.toString()} ${content.currency}', style: DefaultTextStyle.of(context).style.copyWith(fontSize: 16, fontWeight: FontWeight.bold, color: T.COLOR_PRIMARY)), | ||
decoration: BoxDecoration(color: Color(0xffa9ccd3), borderRadius: BorderRadius.circular(6)) | ||
if (this.isStandaloneWidget) | ||
Padding( | ||
padding: const EdgeInsets.only(bottom: 8.0), | ||
child: Row( | ||
mainAxisSize: MainAxisSize.max, | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
children: [PostAvatar(this.username, descriptionWidget: buildRefrencesWidget(context)), buildPriceWidget(context)], | ||
), | ||
], | ||
), | ||
), | ||
if (this.isStandaloneWidget) | ||
buildTitleWidget(context) | ||
else | ||
Row( | ||
mainAxisSize: MainAxisSize.max, | ||
crossAxisAlignment: CrossAxisAlignment.baseline, | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
children: [ | ||
if (heading.isNotEmpty) Flexible(child: buildTitleWidget(context)), | ||
if (content.price > 0) buildPriceWidget(context), | ||
], | ||
), | ||
SizedBox( | ||
height: 6, | ||
height: 8, | ||
), | ||
Row( | ||
children: [ | ||
Container( | ||
padding: const EdgeInsets.all(4), | ||
child: Text( | ||
content.type == AdTypeEnum.offer ? 'Nabízím' : 'Hledám', | ||
style: DefaultTextStyle.of(context).style.copyWith(fontSize: 12, color: Colors.white), | ||
style: DefaultTextStyle | ||
.of(context) | ||
.style | ||
.copyWith(fontSize: 12, color: Colors.white), | ||
), | ||
decoration: BoxDecoration(color: content.type == AdTypeEnum.offer ? T.COLOR_SECONDARY : Color(0xff00B99D), borderRadius: BorderRadius.circular(6)), | ||
), | ||
if (content.location.isNotEmpty) | ||
Padding( | ||
padding: const EdgeInsets.only(left: 8.0), | ||
child: Container( | ||
padding: const EdgeInsets.all(4), | ||
child: Row( | ||
children: [ | ||
Icon( | ||
Icons.location_on_outlined, | ||
size: 14, | ||
), | ||
Text( | ||
content.location, | ||
style: DefaultTextStyle.of(context).style.copyWith(fontSize: 12), | ||
), | ||
], | ||
), | ||
//decoration: BoxDecoration(color: T.COLOR_LIGHT, borderRadius: BorderRadius.circular(6), border: Border.all(color: T.COLOR_PRIMARY)), | ||
), | ||
child: buildIconLabelWidget(Icons.location_on_outlined, content.location, context), | ||
), | ||
], | ||
), | ||
SizedBox( | ||
height: 8, | ||
), | ||
if (content.summary.isNotEmpty) Text(content.summary), | ||
if (content.photoIds.length > 0) Padding( | ||
if (content.insertedAt > 0) | ||
Padding( | ||
padding: const EdgeInsets.only(bottom: 8.0), | ||
child: buildIconLabelWidget(Icons.calendar_today, Helpers.absoluteTime(content.insertedAt), context), | ||
), | ||
if (content.shipping.isNotEmpty) | ||
Padding( | ||
padding: const EdgeInsets.only(bottom: 8.0), | ||
child: buildIconLabelWidget(Icons.local_shipping_outlined, content.shipping, context), | ||
), | ||
if (content.summary.isNotEmpty) | ||
Padding( | ||
padding: const EdgeInsets.only(bottom: 8.0), | ||
child: Text(content.summary), | ||
), | ||
if (content.description.isNotEmpty) PostHtml(content.description), | ||
if (content.photoIds.length > 0) | ||
Padding( | ||
padding: const EdgeInsets.only(top: 8.0), | ||
child: galleryWidget(context), | ||
) | ||
child: galleryWidget(context), | ||
) | ||
], | ||
); | ||
} | ||
|
||
Widget galleryWidget(context) { | ||
List<i.Image> images = content.photoIds.map((String thumb) { | ||
String small = 'https://nyx.cz/$thumb'; | ||
String large = small.replaceAllMapped(RegExp(r'(square)(\.[a-z]{3,4})$'), (match) =>'original${match[2]}'); | ||
String large = small.replaceAllMapped(RegExp(r'(square)(\.[a-z]{3,4})$'), (match) => 'original${match[2]}'); | ||
|
||
return i.Image(large, small); | ||
}).toList(); | ||
return Wrap(children: images.map((image) => PostHeroAttachment(image, images: images)).toList(), spacing: 8, runSpacing: 8,); | ||
return Wrap( | ||
children: images.map((image) => PostHeroAttachment(image, images: images)).toList(), | ||
spacing: 8, | ||
runSpacing: 8, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
class AccessRights { | ||
int _discussionId; | ||
bool _arRead; | ||
bool _arWrite; | ||
bool _arDelete; | ||
bool _arEdit; | ||
bool _arRights; | ||
int _daysLeft; | ||
|
||
AccessRights({int discussionId, bool arRead, bool arWrite, bool arDelete, bool arEdit, bool arRights, int daysLeft}) { | ||
this._discussionId = discussionId; | ||
this._arRead = arRead; | ||
this._arWrite = arWrite; | ||
this._arDelete = arDelete; | ||
this._arEdit = arEdit; | ||
this._arRights = arRights; | ||
this._daysLeft = daysLeft; | ||
} | ||
|
||
int get discussionId => _discussionId; | ||
|
||
bool get canRead => _arRead; | ||
|
||
bool get canWrite => _arWrite; | ||
|
||
bool get canDelete => _arDelete; | ||
|
||
bool get canEdit => _arEdit; | ||
|
||
bool get canRights => _arRights; | ||
|
||
int get daysLeft => _daysLeft; | ||
|
||
AccessRights.fromJson(Map<String, dynamic> json) { | ||
_discussionId = json['discussion_id']; | ||
_arRead = json['ar_read'] ?? false; | ||
_arWrite = json['ar_write'] ?? false; | ||
_arDelete = json['ar_delete'] ?? false; | ||
_arEdit = json['ar_edit'] ?? false; | ||
_arRights = json['ar_rights'] ?? false; | ||
_daysLeft = json['days_left'] ?? -1; | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
final Map<String, dynamic> data = new Map<String, dynamic>(); | ||
data['discussion_id'] = this._discussionId; | ||
data['ar_read'] = this._arRead; | ||
data['ar_write'] = this._arWrite; | ||
data['ar_delete'] = this._arDelete; | ||
data['ar_edit'] = this._arEdit; | ||
data['ar_rights'] = this._arRights; | ||
data['days_left'] = this._daysLeft; | ||
return data; | ||
} | ||
} |
Oops, something went wrong.