Skip to content

Commit

Permalink
Fix about page ordering being reversed (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsRefsgaard authored Aug 3, 2023
1 parent 93d5b1c commit 29dabd9
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 140 deletions.
2 changes: 1 addition & 1 deletion lib/ui/carp_study_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,4 @@ TextStyle timerStyle =
const TextStyle(fontSize: 36, fontWeight: FontWeight.w600);

TextStyle studyNameStyle =
const TextStyle(fontSize: 16.0, fontWeight: FontWeight.w800);
const TextStyle(fontSize: 30.0, fontWeight: FontWeight.w800);
55 changes: 26 additions & 29 deletions lib/ui/pages/message_details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ class MessageDetailsPage extends StatelessWidget {
});

return Scaffold(
body: Container(
color: Theme.of(context).colorScheme.secondary,
child: Padding(
padding: const EdgeInsets.only(top: 35),
body: SafeArea(
child: Container(
color: Theme.of(context).colorScheme.secondary,
child: Column(
children: [
Row(mainAxisAlignment: MainAxisAlignment.end, children: [
Expand All @@ -42,32 +41,30 @@ class MessageDetailsPage extends StatelessWidget {
icon: const Icon(Icons.close_rounded))
]),
Flexible(
child: CustomScrollView(
slivers: [
DetailsBanner(message.title!, message.image),
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 30),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
child: ListView(
children: [
DetailsBanner(message.title ?? '', message.image),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${locale.translate(message.type.toString().split('.').last.toLowerCase())} - ${timeago.format(DateTime.now().copyWithAdditional(years: -DateTime.now().year + message.timestamp.year, months: -DateTime.now().month + message.timestamp.month, days: -DateTime.now().day + message.timestamp.day, hours: -DateTime.now().hour + message.timestamp.hour, minutes: -DateTime.now().minute + message.timestamp.minute), locale: Localizations.localeOf(context).languageCode)}',
style: aboutCardSubtitleStyle.copyWith(
color: Theme.of(context).primaryColor)),
message.subTitle != null
? Text(locale.translate(message.subTitle!),
style: aboutCardContentStyle.copyWith(
color: Theme.of(context).primaryColor))
: const SizedBox.shrink(),
if (message.message != null)
Text(
'${locale.translate(message.type.toString().split('.').last.toLowerCase())} - ${timeago.format(DateTime.now().copyWithAdditional(years: -DateTime.now().year + message.timestamp.year, months: -DateTime.now().month + message.timestamp.month, days: -DateTime.now().day + message.timestamp.day, hours: -DateTime.now().hour + message.timestamp.hour, minutes: -DateTime.now().minute + message.timestamp.minute), locale: Localizations.localeOf(context).languageCode)}',
style: aboutCardSubtitleStyle.copyWith(
color: Theme.of(context).primaryColor)),
message.subTitle != null
? Text(locale.translate(message.subTitle!),
style: aboutCardContentStyle.copyWith(
color: Theme.of(context).primaryColor))
: const SizedBox.shrink(),
if (message.message != null)
Text(
locale.translate(message.message!),
style: aboutCardContentStyle,
textAlign: TextAlign.justify,
)
],
),
locale.translate(message.message!),
style: aboutCardContentStyle,
textAlign: TextAlign.justify,
)
],
),
),
],
Expand Down
35 changes: 15 additions & 20 deletions lib/ui/pages/study_details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,23 @@ class StudyDetailsPage extends StatelessWidget {
icon: const Icon(Icons.close))
]),
Flexible(
child: CustomScrollView(
slivers: [
//CarpBanner(),
child: ListView(
children: [
DetailsBanner(
studyPageModel.title, './assets/images/kids.png'),
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.all(30),
child: Column(
children: [
Text(locale.translate(studyPageModel.piAffiliation),
style: aboutCardSubtitleStyle.copyWith(
color: Theme.of(context).primaryColor)),
const SizedBox(height: 5),
Text(
studyDescription(),
style: aboutCardContentStyle,
textAlign: TextAlign.justify,
),
const SizedBox(height: 50),
],
),
Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: [
Text(locale.translate(studyPageModel.piAffiliation),
style: aboutCardSubtitleStyle.copyWith(
color: Theme.of(context).primaryColor)),
Text(
studyDescription(),
style: aboutCardContentStyle,
textAlign: TextAlign.justify,
),
],
),
),
],
Expand Down
73 changes: 45 additions & 28 deletions lib/ui/pages/study_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ class StudyPage extends StatefulWidget {
class StudyPageState extends State<StudyPage> {
@override
Widget build(BuildContext context) {
final Message studyDescription = Message(
id: '00000000-0000-0000-0000-000000000000',
title: widget.model.title,
message: widget.model.description,
type: MessageType.announcement,
timestamp: DateTime.now(),
image: 'assets/images/kids.png',
);

return Scaffold(
backgroundColor: Theme.of(context).colorScheme.secondary,
floatingActionButton: FloatingActionButton(
onPressed: () {
bloc.refreshMessages();
},
child: const Icon(Icons.refresh),
),
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
Expand All @@ -29,20 +32,27 @@ class StudyPageState extends State<StudyPage> {
child: StreamBuilder<int>(
stream: widget.model.messageStream,
builder: (context, AsyncSnapshot<int> snapshot) {
return CustomScrollView(
slivers: [
DetailsBanner(
widget.model.title, './assets/images/kids.png',
isCarpBanner: true),
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) =>
_aboutStudyCard(
context, widget.model.messages[index]),
childCount: widget.model.messages.length,
),
),
],
return RefreshIndicator(
onRefresh: () async {
await bloc.refreshMessages();
},
child: ListView.builder(
itemCount: bloc.messages.length + 1,
itemBuilder: (context, index) {
if (index == 0) {
return _aboutStudyCard(
context,
studyDescription,
onTap: () {
context.push('/studyDetails');
},
);
}

return _aboutStudyCard(
context, widget.model.messages[index - 1]);
},
),
);
}),
),
Expand All @@ -52,7 +62,8 @@ class StudyPageState extends State<StudyPage> {
);
}

Widget _aboutStudyCard(BuildContext context, Message message) {
Widget _aboutStudyCard(BuildContext context, Message message,
{Function? onTap}) {
RPLocalizations locale = RPLocalizations.of(context)!;

// Initialization the language of the tiemago package
Expand All @@ -69,7 +80,11 @@ class StudyPageState extends State<StudyPage> {
margin: const EdgeInsets.all(5),
child: InkWell(
onTap: () {
context.push('/message/${message.id}');
if (onTap != null) {
onTap();
} else {
context.push('/message/${message.id}');
}
},
child: Padding(
padding: const EdgeInsets.all(8.0),
Expand Down Expand Up @@ -110,22 +125,24 @@ class StudyPageState extends State<StudyPage> {
style: aboutCardSubtitleStyle.copyWith(
color: Theme.of(context).primaryColor)),
),
Row(children: [
if (message.subTitle!.isNotEmpty)
if (message.subTitle != null && message.subTitle!.isNotEmpty)
Row(children: [
Expanded(
child: Text(locale.translate(message.subTitle!),
style: aboutCardContentStyle.copyWith(
color: Theme.of(context).primaryColor))),
]),
Row(children: [
if (message.message != null && message.message!.isNotEmpty)
]),
if (message.message != null &&
message.message != null &&
message.message!.isNotEmpty)
Row(children: [
Expanded(
child: Text(
"${locale.translate(message.message!).substring(0, (message.message!.length > 150) ? 150 : null)}...",
style: aboutCardContentStyle,
textAlign: TextAlign.justify,
)),
]),
]),
],
),
),
Expand Down
88 changes: 27 additions & 61 deletions lib/ui/widgets/details_banner.dart
Original file line number Diff line number Diff line change
@@ -1,77 +1,43 @@
part of carp_study_app;

class DetailsBanner extends StatelessWidget {
const DetailsBanner(this.title, this.imagePath,
{super.key, this.isCarpBanner = false});
const DetailsBanner(this.title, this.imagePath, {super.key});
final String title;
final String? imagePath;
final bool isCarpBanner;

@override
Widget build(
BuildContext context,
) {
RPLocalizations locale = RPLocalizations.of(context)!;
return SliverAppBar(
expandedHeight: 150.0,
backgroundColor: Theme.of(context).colorScheme.secondary,
floating: false,
pinned: false,
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
titlePadding: const EdgeInsets.only(top: 15),
background: imagePath != null && imagePath!.isNotEmpty
? ClipRRect(
child: ImageFiltered(
imageFilter: ui.ImageFilter.blur(sigmaX: 1, sigmaY: 1),
child: bloc.data.studyPageViewModel
.getMessageImage(imagePath)),
)
: const SizedBox.shrink(),
title: InkWell(
onTap: () {
if (isCarpBanner) {
context.push('/studyDetails');
}
},
child: Padding(
padding: const EdgeInsets.all(10),
child: Stack(
alignment: AlignmentDirectional.bottomEnd,
children: [
Stack(
children: [
Text(
locale.translate(title),
style: studyNameStyle.copyWith(
// color: Theme.of(context).primaryColor,
foreground: Paint()
..style = PaintingStyle.stroke
..strokeWidth = 1
..color = Theme.of(context).colorScheme.secondary),
),
Text(
locale.translate(title),
style: studyNameStyle.copyWith(
color: Theme.of(context).primaryColor),
),
],
),
isCarpBanner
? Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Icon(Icons.touch_app,
color: Theme.of(context).primaryColor, size: 15),
],
)
: const SizedBox.shrink(),
],
),
return Column(
// crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
// only show this widget if there is an image = imagePath is not null and not empty
if (imagePath != null && imagePath!.isNotEmpty)
SizedBox(
height: 300,
child: bloc.data.studyPageViewModel.getMessageImage(imagePath),
),
Padding(
padding: const EdgeInsets.all(16),
child: Stack(
alignment: AlignmentDirectional.bottomEnd,
children: [
Stack(
children: [
Text(
locale.translate(title),
style: studyNameStyle.copyWith(
fontSize: 30, color: Theme.of(context).primaryColor),
),
],
),
],
),
),
),
],
);
}
}
2 changes: 1 addition & 1 deletion lib/view_models/study_page_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class StudyPageViewModel extends ViewModel {
Stream<int> get messageStream => bloc.messageStream;

/// The list of messages to be displayed.
List<Message> get messages => bloc.messages;
List<Message> get messages => bloc.messages.reversed.toList();

/// The icon for a type of message
Icon getMessageTypeIcon(MessageType type) {
Expand Down

0 comments on commit 29dabd9

Please sign in to comment.