mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-03 19:54:12 +00:00 
			
		
		
		
	Display posts text and images
This commit is contained in:
		@@ -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,
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user