mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 04:04:18 +00:00 
			
		
		
		
	Create NetworkImage widget
This commit is contained in:
		@@ -1,11 +1,10 @@
 | 
				
			|||||||
import 'package:cached_network_image/cached_network_image.dart';
 | 
					 | 
				
			||||||
import 'package:comunic/models/conversation_message.dart';
 | 
					import 'package:comunic/models/conversation_message.dart';
 | 
				
			||||||
import 'package:comunic/models/user.dart';
 | 
					import 'package:comunic/models/user.dart';
 | 
				
			||||||
import 'package:comunic/ui/widgets/account_image_widget.dart';
 | 
					import 'package:comunic/ui/widgets/account_image_widget.dart';
 | 
				
			||||||
 | 
					import 'package:comunic/ui/widgets/network_image_widget.dart';
 | 
				
			||||||
import 'package:comunic/ui/widgets/text_rich_content_widget.dart';
 | 
					import 'package:comunic/ui/widgets/text_rich_content_widget.dart';
 | 
				
			||||||
import 'package:comunic/utils/date_utils.dart';
 | 
					import 'package:comunic/utils/date_utils.dart';
 | 
				
			||||||
import 'package:comunic/utils/intl_utils.dart';
 | 
					import 'package:comunic/utils/intl_utils.dart';
 | 
				
			||||||
import 'package:comunic/utils/ui_utils.dart';
 | 
					 | 
				
			||||||
import 'package:flutter/material.dart';
 | 
					import 'package:flutter/material.dart';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Conversation message tile
 | 
					/// Conversation message tile
 | 
				
			||||||
@@ -74,38 +73,11 @@ class ConversationMessageTile extends StatelessWidget {
 | 
				
			|||||||
  Widget _buildMessageImage(BuildContext context) {
 | 
					  Widget _buildMessageImage(BuildContext context) {
 | 
				
			||||||
    return Container(
 | 
					    return Container(
 | 
				
			||||||
      margin: EdgeInsets.only(bottom: 2),
 | 
					      margin: EdgeInsets.only(bottom: 2),
 | 
				
			||||||
      child: Material(
 | 
					      child: NetworkImageWidget(
 | 
				
			||||||
        child: InkWell(
 | 
					        url: message.imageURL,
 | 
				
			||||||
          onTap: () {
 | 
					        allowFullScreen: true,
 | 
				
			||||||
            showImageFullScreen(context, message.imageURL);
 | 
					 | 
				
			||||||
          },
 | 
					 | 
				
			||||||
          child: CachedNetworkImage(
 | 
					 | 
				
			||||||
            imageUrl: message.imageURL,
 | 
					 | 
				
			||||||
            width: 200.0,
 | 
					 | 
				
			||||||
            height: 200.0,
 | 
					 | 
				
			||||||
            fit: BoxFit.cover,
 | 
					 | 
				
			||||||
            placeholder: (c, s) => Container(
 | 
					 | 
				
			||||||
        width: 200,
 | 
					        width: 200,
 | 
				
			||||||
        height: 200,
 | 
					        height: 200,
 | 
				
			||||||
                  color: Colors.lightBlueAccent,
 | 
					 | 
				
			||||||
                  child: Center(
 | 
					 | 
				
			||||||
                    child: CircularProgressIndicator(),
 | 
					 | 
				
			||||||
                  ),
 | 
					 | 
				
			||||||
                ),
 | 
					 | 
				
			||||||
            errorWidget: (c, s, o) => Container(
 | 
					 | 
				
			||||||
                  width: 200,
 | 
					 | 
				
			||||||
                  height: 200,
 | 
					 | 
				
			||||||
                  color: Colors.red,
 | 
					 | 
				
			||||||
                  child: Center(
 | 
					 | 
				
			||||||
                      child: Icon(
 | 
					 | 
				
			||||||
                    Icons.error,
 | 
					 | 
				
			||||||
                    color: Colors.white,
 | 
					 | 
				
			||||||
                  )),
 | 
					 | 
				
			||||||
                ),
 | 
					 | 
				
			||||||
          ),
 | 
					 | 
				
			||||||
        ),
 | 
					 | 
				
			||||||
        borderRadius: BorderRadius.all(Radius.circular(8.0)),
 | 
					 | 
				
			||||||
        clipBehavior: Clip.hardEdge,
 | 
					 | 
				
			||||||
      ),
 | 
					      ),
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										66
									
								
								lib/ui/widgets/network_image_widget.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								lib/ui/widgets/network_image_widget.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,66 @@
 | 
				
			|||||||
 | 
					import 'package:cached_network_image/cached_network_image.dart';
 | 
				
			||||||
 | 
					import 'package:comunic/utils/ui_utils.dart';
 | 
				
			||||||
 | 
					import 'package:flutter/material.dart';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Network image widget
 | 
				
			||||||
 | 
					///
 | 
				
			||||||
 | 
					/// Widget useful to show remote image
 | 
				
			||||||
 | 
					///
 | 
				
			||||||
 | 
					/// @author Pierre HUBERT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class NetworkImageWidget extends StatelessWidget {
 | 
				
			||||||
 | 
					  final String url;
 | 
				
			||||||
 | 
					  final bool allowFullScreen;
 | 
				
			||||||
 | 
					  final double width;
 | 
				
			||||||
 | 
					  final double height;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const NetworkImageWidget({
 | 
				
			||||||
 | 
					    Key key,
 | 
				
			||||||
 | 
					    @required this.url,
 | 
				
			||||||
 | 
					    this.allowFullScreen = false,
 | 
				
			||||||
 | 
					    this.width,
 | 
				
			||||||
 | 
					    this.height,
 | 
				
			||||||
 | 
					  })  : assert(url != null),
 | 
				
			||||||
 | 
					        assert(allowFullScreen != null),
 | 
				
			||||||
 | 
					        super(key: key);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @override
 | 
				
			||||||
 | 
					  Widget build(BuildContext context) {
 | 
				
			||||||
 | 
					    return Material(
 | 
				
			||||||
 | 
					      child: InkWell(
 | 
				
			||||||
 | 
					        onTap: allowFullScreen
 | 
				
			||||||
 | 
					            ? () {
 | 
				
			||||||
 | 
					                showImageFullScreen(context, url);
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					            : null,
 | 
				
			||||||
 | 
					        child: CachedNetworkImage(
 | 
				
			||||||
 | 
					          imageUrl: url,
 | 
				
			||||||
 | 
					          width: width,
 | 
				
			||||||
 | 
					          height: height,
 | 
				
			||||||
 | 
					          fit: BoxFit.cover,
 | 
				
			||||||
 | 
					          placeholder: (c, s) => Container(
 | 
				
			||||||
 | 
					                width: width,
 | 
				
			||||||
 | 
					                height: height,
 | 
				
			||||||
 | 
					                color: Colors.lightBlueAccent,
 | 
				
			||||||
 | 
					                child: Center(
 | 
				
			||||||
 | 
					                  child: CircularProgressIndicator(),
 | 
				
			||||||
 | 
					                ),
 | 
				
			||||||
 | 
					              ),
 | 
				
			||||||
 | 
					          errorWidget: (c, s, o) => Container(
 | 
				
			||||||
 | 
					                width: width,
 | 
				
			||||||
 | 
					                height: height,
 | 
				
			||||||
 | 
					                color: Colors.red,
 | 
				
			||||||
 | 
					                child: Center(
 | 
				
			||||||
 | 
					                  child: Icon(
 | 
				
			||||||
 | 
					                    Icons.error,
 | 
				
			||||||
 | 
					                    color: Colors.white,
 | 
				
			||||||
 | 
					                  ),
 | 
				
			||||||
 | 
					                ),
 | 
				
			||||||
 | 
					              ),
 | 
				
			||||||
 | 
					        ),
 | 
				
			||||||
 | 
					      ),
 | 
				
			||||||
 | 
					      borderRadius: BorderRadius.all(Radius.circular(8.0)),
 | 
				
			||||||
 | 
					      clipBehavior: Clip.hardEdge,
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user