1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 12:59:21 +00:00

Display posts text and images

This commit is contained in:
Pierre HUBERT 2019-05-11 09:48:01 +02:00
parent 35e9c30ba2
commit 315c61a212
3 changed files with 92 additions and 3 deletions

View File

@ -61,4 +61,6 @@ class Post {
assert(likes != null), assert(likes != null),
assert(userLikes != null), assert(userLikes != null),
assert(access != null); assert(access != null);
bool get hasContent => content != null;
} }

View File

@ -1,11 +1,22 @@
import 'package:comunic/enums/post_kind.dart';
import 'package:comunic/lists/users_list.dart'; import 'package:comunic/lists/users_list.dart';
import 'package:comunic/models/post.dart'; import 'package:comunic/models/post.dart';
import 'package:comunic/models/user.dart';
import 'package:comunic/ui/widgets/account_image_widget.dart';
import 'package:comunic/ui/widgets/network_image_widget.dart';
import 'package:comunic/utils/date_utils.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
/// Single posts tile /// Single posts tile
/// ///
/// @author Pierre HUBERT /// @author Pierre HUBERT
/// User style
const TextStyle _userNameStyle = TextStyle(
color: Color.fromRGBO(0x72, 0xaf, 0xd2, 1.0), //#72afd2
fontWeight: FontWeight.w600,
fontSize: 16.0);
class PostTile extends StatelessWidget { class PostTile extends StatelessWidget {
final Post post; final Post post;
final UsersList usersInfo; final UsersList usersInfo;
@ -18,10 +29,83 @@ class PostTile extends StatelessWidget {
assert(usersInfo != null), assert(usersInfo != null),
super(key: key); super(key: key);
User get _user => usersInfo.getUser(post.userID);
Widget _buildHeaderRow() {
// Header row
return Row(
children: <Widget>[
// User account image
Padding(
padding: const EdgeInsets.only(right: 8.0, left: 8.0),
child: AccountImageWidget(user: _user),
),
// Column with user name + post target
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
_user.displayName,
style: _userNameStyle,
),
Text(diffTimeFromNowToStr(post.timeSent)),
],
),
),
PopupMenuButton(
itemBuilder: (c) => [],
)
],
);
}
Widget _buildContentRow() {
Widget postContent;
switch (post.kind) {
case PostKind.IMAGE:
postContent = _buildPostImage();
break;
default:
}
return Column(
children: <Widget>[
// Post "rich" content
Container(child: postContent),
// Post text
Container(child: post.hasContent ? Text(post.content) : null),
],
);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ListTile( return Card(
leading: Text("a post"), elevation: 1.0,
child: Padding(
padding: const EdgeInsets.all(8.0),
// Main post column
child: Column(
children: <Widget>[
_buildHeaderRow(),
_buildContentRow(),
],
),
),
);
}
Widget _buildPostImage() {
return NetworkImageWidget(
url: post.fileURL,
allowFullScreen: true,
roundedEdges: false,
); );
} }
} }

View File

@ -11,6 +11,7 @@ import 'package:flutter/material.dart';
class NetworkImageWidget extends StatelessWidget { class NetworkImageWidget extends StatelessWidget {
final String url; final String url;
final bool allowFullScreen; final bool allowFullScreen;
final bool roundedEdges;
final double width; final double width;
final double height; final double height;
@ -20,6 +21,7 @@ class NetworkImageWidget extends StatelessWidget {
this.allowFullScreen = false, this.allowFullScreen = false,
this.width, this.width,
this.height, this.height,
this.roundedEdges = true,
}) : assert(url != null), }) : assert(url != null),
assert(allowFullScreen != null), assert(allowFullScreen != null),
super(key: key); super(key: key);
@ -59,7 +61,8 @@ class NetworkImageWidget extends StatelessWidget {
), ),
), ),
), ),
borderRadius: BorderRadius.all(Radius.circular(8.0)), borderRadius:
roundedEdges ? BorderRadius.all(Radius.circular(8.0)) : null,
clipBehavior: Clip.hardEdge, clipBehavior: Clip.hardEdge,
); );
} }