mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 04:49:21 +00:00
Display posts text and images
This commit is contained in:
parent
35e9c30ba2
commit
315c61a212
@ -61,4 +61,6 @@ class Post {
|
||||
assert(likes != null),
|
||||
assert(userLikes != null),
|
||||
assert(access != null);
|
||||
|
||||
bool get hasContent => content != null;
|
||||
}
|
||||
|
@ -1,11 +1,22 @@
|
||||
import 'package:comunic/enums/post_kind.dart';
|
||||
import 'package:comunic/lists/users_list.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';
|
||||
|
||||
/// Single posts tile
|
||||
///
|
||||
/// @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 {
|
||||
final Post post;
|
||||
final UsersList usersInfo;
|
||||
@ -18,10 +29,83 @@ class PostTile extends StatelessWidget {
|
||||
assert(usersInfo != null),
|
||||
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
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
leading: Text("a post"),
|
||||
return Card(
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import 'package:flutter/material.dart';
|
||||
class NetworkImageWidget extends StatelessWidget {
|
||||
final String url;
|
||||
final bool allowFullScreen;
|
||||
final bool roundedEdges;
|
||||
final double width;
|
||||
final double height;
|
||||
|
||||
@ -20,6 +21,7 @@ class NetworkImageWidget extends StatelessWidget {
|
||||
this.allowFullScreen = false,
|
||||
this.width,
|
||||
this.height,
|
||||
this.roundedEdges = true,
|
||||
}) : assert(url != null),
|
||||
assert(allowFullScreen != null),
|
||||
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,
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user