-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bounty): Support thread bounty state and best answer
This commit add support for parsing and showing the bounty state of thread (if any) and the related best answer content (if any).
- Loading branch information
Showing
7 changed files
with
295 additions
and
0 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
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,77 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:tsdm_client/constants/layout.dart'; | ||
import 'package:tsdm_client/constants/url.dart'; | ||
import 'package:tsdm_client/extensions/build_context.dart'; | ||
import 'package:tsdm_client/generated/i18n/strings.g.dart'; | ||
import 'package:tsdm_client/widgets/cached_image/cached_image_provider.dart'; | ||
|
||
/// Widget to show the answer of a bounty in thread. | ||
class BountyAnswerCard extends StatelessWidget { | ||
/// Constructor. | ||
const BountyAnswerCard({ | ||
required this.username, | ||
required this.userSpaceUrl, | ||
required this.userAvatarUrl, | ||
required this.answer, | ||
super.key, | ||
}); | ||
|
||
/// User name of the answer. | ||
final String username; | ||
|
||
/// Profile url of the answer's user. | ||
final String userSpaceUrl; | ||
|
||
/// Avatar url of the answer's user. | ||
final String userAvatarUrl; | ||
|
||
/// Answer content. | ||
final String answer; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final secondaryColor = Theme.of(context).colorScheme.secondary; | ||
return Card( | ||
margin: EdgeInsets.zero, | ||
child: Padding( | ||
padding: edgeInsetsL15T15R15B15, | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Row( | ||
children: [ | ||
Icon(Icons.verified, size: 28, color: secondaryColor), | ||
sizedBoxW10H10, | ||
Text( | ||
context.t.bountyAnswerCard.title, | ||
style: Theme.of(context).textTheme.titleLarge?.copyWith( | ||
color: secondaryColor, | ||
), | ||
), | ||
], | ||
), | ||
sizedBoxW10H10, | ||
ListTile( | ||
contentPadding: EdgeInsets.zero, | ||
leading: GestureDetector( | ||
onTap: () async => context.dispatchAsUrl(userSpaceUrl), | ||
child: CircleAvatar( | ||
backgroundImage: CachedImageProvider( | ||
userAvatarUrl, | ||
fallbackImageUrl: noAvatarUrl, | ||
context, | ||
), | ||
), | ||
), | ||
title: GestureDetector( | ||
onTap: () async => context.dispatchAsUrl(userSpaceUrl), | ||
child: Text(username), | ||
), | ||
), | ||
Text(answer), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
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,99 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; | ||
import 'package:tsdm_client/constants/layout.dart'; | ||
import 'package:tsdm_client/extensions/list.dart'; | ||
import 'package:tsdm_client/generated/i18n/strings.g.dart'; | ||
|
||
/// Widget showing a bounty info in thread. | ||
class BountyCard extends StatelessWidget { | ||
/// Constructor. | ||
const BountyCard({required this.resolved, required this.price, super.key}); | ||
|
||
/// Flag indicating the bounty state. | ||
/// | ||
/// Is resolved or not. | ||
final bool resolved; | ||
|
||
/// Price of this bounty. | ||
final String price; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final secondaryColor = Theme.of(context).colorScheme.secondary; | ||
final tertiaryColor = Theme.of(context).colorScheme.tertiary; | ||
final bountyStatusTextStyle = | ||
Theme.of(context).textTheme.bodyMedium?.copyWith( | ||
color: tertiaryColor, | ||
); | ||
final bountyStatusTextResolvedStyle = | ||
Theme.of(context).textTheme.bodyMedium?.copyWith( | ||
color: secondaryColor, | ||
); | ||
|
||
// Bounty status. | ||
late final Widget bountyStatusWidget; | ||
if (resolved) { | ||
bountyStatusWidget = Row( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Icon(Icons.done, color: secondaryColor), | ||
sizedBoxW5H5, | ||
Text( | ||
context.t.bountyCard.resolved, | ||
style: bountyStatusTextResolvedStyle, | ||
), | ||
], | ||
); | ||
} else { | ||
bountyStatusWidget = Row( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Icon(Icons.pending, color: tertiaryColor), | ||
sizedBoxW5H5, | ||
Text(context.t.bountyCard.processing, style: bountyStatusTextStyle), | ||
], | ||
); | ||
} | ||
|
||
return Card( | ||
margin: EdgeInsets.zero, | ||
child: Padding( | ||
padding: edgeInsetsL15T15R15B15, | ||
child: ConstrainedBox( | ||
constraints: const BoxConstraints(minWidth: 100), | ||
child: Column( | ||
children: <Widget>[ | ||
Row( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Text( | ||
context.t.bountyCard.title, | ||
style: Theme.of(context).textTheme.titleLarge?.copyWith( | ||
color: secondaryColor, | ||
), | ||
), | ||
sizedBoxW20H20, | ||
bountyStatusWidget, | ||
], | ||
), | ||
Row( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
const Icon( | ||
FontAwesomeIcons.coins, | ||
size: 20, | ||
), | ||
sizedBoxW5H5, | ||
Text( | ||
context.t.bountyCard.price(price: price), | ||
style: Theme.of(context).textTheme.bodyLarge, | ||
), | ||
], | ||
), | ||
].insertBetween(sizedBoxW10H10), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |