-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from ProximaEPFL/post-page
Post page UI foundation
- Loading branch information
Showing
15 changed files
with
638 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import "package:flutter/foundation.dart"; | ||
|
||
@immutable | ||
class CommentPost { | ||
final String content; | ||
final String ownerDisplayName; | ||
|
||
const CommentPost({ | ||
required this.content, | ||
required this.ownerDisplayName, | ||
}); | ||
|
||
@override | ||
bool operator ==(Object other) { | ||
if (identical(this, other)) return true; | ||
|
||
return other is CommentPost && | ||
other.content == content && | ||
other.ownerDisplayName == ownerDisplayName; | ||
} | ||
|
||
@override | ||
int get hashCode { | ||
return Object.hash( | ||
content, | ||
ownerDisplayName, | ||
); | ||
} | ||
} |
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,7 @@ | ||
import "package:hooks_riverpod/hooks_riverpod.dart"; | ||
import "package:proxima/models/ui/comment_post.dart"; | ||
|
||
// This provider is used to store the list of comments that are displayed in the post page. | ||
final commentListProvider = Provider<List<CommentPost>>((ref) { | ||
return List.empty(); | ||
}); |
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,83 @@ | ||
import "package:flutter/material.dart"; | ||
import "package:hooks_riverpod/hooks_riverpod.dart"; | ||
import "package:proxima/models/ui/post_overview.dart"; | ||
import "package:proxima/viewmodels/post_view_model.dart"; | ||
import "package:proxima/views/navigation/leading_back_button/leading_back_button.dart"; | ||
import "package:proxima/views/pages/post/post_page_widget/bottom_bar_add_comment.dart"; | ||
import "package:proxima/views/pages/post/post_page_widget/comment_list.dart"; | ||
import "package:proxima/views/pages/post/post_page_widget/complete_post_widget.dart"; | ||
|
||
class PostPage extends HookConsumerWidget { | ||
static const postDistanceKey = Key("postDistance"); | ||
static const completePostWidgetKey = Key("completePostWidget"); | ||
static const commentListWidgetKey = Key("commentListWidget"); | ||
static const bottomBarAddCommentKey = Key("bottomBarAddComment"); | ||
|
||
static const _appBarTitle = "Post"; | ||
|
||
const PostPage({ | ||
super.key, | ||
required this.postOverview, | ||
}); | ||
|
||
final PostOverview postOverview; | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
ThemeData themeData = Theme.of(context); | ||
|
||
final comments = ref.watch(commentListProvider); | ||
|
||
List<Widget> appBarContent = [ | ||
const Text(_appBarTitle), | ||
Text( | ||
key: postDistanceKey, | ||
//TODO: Add distance to post | ||
"50m away", | ||
style: themeData.textTheme.titleSmall, | ||
), | ||
]; | ||
|
||
List<Widget> bodyChildren = [ | ||
CompletePostWidget( | ||
key: completePostWidgetKey, | ||
post: postOverview, | ||
), | ||
const SizedBox(height: 10), | ||
CommentList( | ||
key: commentListWidgetKey, | ||
comments: comments, | ||
), | ||
]; | ||
|
||
return Scaffold( | ||
appBar: AppBar( | ||
leading: const LeadingBackButton(), | ||
title: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: appBarContent, | ||
), | ||
), | ||
body: Padding( | ||
padding: const EdgeInsets.only(top: 8, bottom: 8, left: 8, right: 8), | ||
child: Center( | ||
child: ListView( | ||
children: bodyChildren, | ||
), | ||
), | ||
), | ||
persistentFooterButtons: [ | ||
Padding( | ||
padding: | ||
// This is necessary to prevent the keyboard from covering the bottom bar | ||
EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), | ||
child: const BottomBarAddComment( | ||
key: bottomBarAddCommentKey, | ||
//TODO: Replace with actual username | ||
currentDisplayName: "Username", | ||
), | ||
), | ||
], | ||
); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
lib/views/pages/post/post_page_widget/bottom_bar_add_comment.dart
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,58 @@ | ||
import "package:flutter/material.dart"; | ||
|
||
class BottomBarAddComment extends StatelessWidget { | ||
static const commentUserAvatarKey = Key("commentUserAvatar"); | ||
static const addCommentTextFieldKey = Key("addCommentTextField"); | ||
static const postCommentButtonKey = Key("postCommentButton"); | ||
|
||
static const _textFieldHintAddComment = "Add a comment"; | ||
|
||
final String currentDisplayName; | ||
|
||
const BottomBarAddComment({ | ||
super.key, | ||
required this.currentDisplayName, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Row( | ||
// Align items to the start of the cross axis | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Padding( | ||
padding: const EdgeInsets.only(right: 8), | ||
child: CircleAvatar( | ||
key: commentUserAvatarKey, | ||
radius: 22, | ||
child: Text(currentDisplayName.substring(0, 1)), | ||
), | ||
), | ||
const Expanded( | ||
child: TextField( | ||
key: addCommentTextFieldKey, | ||
minLines: 1, | ||
maxLines: 5, | ||
decoration: InputDecoration( | ||
contentPadding: EdgeInsets.all(8), | ||
border: OutlineInputBorder(), | ||
hintText: _textFieldHintAddComment, | ||
), | ||
), | ||
), | ||
Align( | ||
// Keeps the IconButton centered in the cross axis | ||
alignment: Alignment.center, | ||
child: IconButton( | ||
key: postCommentButtonKey, | ||
icon: const Icon(Icons.send), | ||
onPressed: () { | ||
//TODO: handle add comment | ||
FocusManager.instance.primaryFocus?.unfocus(); | ||
}, | ||
), | ||
), | ||
], | ||
); | ||
} | ||
} |
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,25 @@ | ||
import "package:flutter/material.dart"; | ||
import "package:proxima/models/ui/comment_post.dart"; | ||
import "package:proxima/views/pages/post/post_page_widget/comment_post_widget.dart"; | ||
|
||
class CommentList extends StatelessWidget { | ||
const CommentList({ | ||
super.key, | ||
required this.comments, | ||
}); | ||
|
||
final List<CommentPost> comments; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Padding( | ||
padding: const EdgeInsets.only(left: 16, right: 16), | ||
child: Wrap( | ||
runSpacing: 15, | ||
children: comments | ||
.map((comment) => CommentPostWidget(commentPost: comment)) | ||
.toList(), | ||
), | ||
); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
lib/views/pages/post/post_page_widget/comment_post_widget.dart
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,38 @@ | ||
import "package:flutter/material.dart"; | ||
import "package:proxima/models/ui/comment_post.dart"; | ||
|
||
import "package:proxima/views/home_content/feed/post_card/user_bar_widget.dart"; | ||
|
||
class CommentPostWidget extends StatelessWidget { | ||
static const commentWidgetKey = Key("commentWidget"); | ||
static const commentUserWidgetKey = Key("commentUserWidget"); | ||
static const commentContentKey = Key("commentContent"); | ||
|
||
final CommentPost commentPost; | ||
|
||
const CommentPostWidget({ | ||
super.key, | ||
required this.commentPost, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
key: commentWidgetKey, | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
UserBarWidget( | ||
key: commentUserWidgetKey, | ||
posterUsername: commentPost.ownerDisplayName, | ||
), | ||
Padding( | ||
padding: const EdgeInsets.only(left: 32, top: 8), | ||
child: Text( | ||
key: commentContentKey, | ||
commentPost.content, | ||
), | ||
), | ||
], | ||
); | ||
} | ||
} |
Oops, something went wrong.