mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 04:04:18 +00:00 
			
		
		
		
	Created conversation route
This commit is contained in:
		
							
								
								
									
										90
									
								
								lib/ui/routes/conversation_route.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								lib/ui/routes/conversation_route.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,90 @@
 | 
			
		||||
import 'package:comunic/helpers/conversations_helper.dart';
 | 
			
		||||
import 'package:comunic/models/conversation.dart';
 | 
			
		||||
import 'package:comunic/utils/intl_utils.dart';
 | 
			
		||||
import 'package:comunic/utils/ui_utils.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
 | 
			
		||||
/// Single conversation route
 | 
			
		||||
///
 | 
			
		||||
/// @author Pierre HUBERT
 | 
			
		||||
 | 
			
		||||
class ConversationRoute extends StatefulWidget {
 | 
			
		||||
  final int conversationID;
 | 
			
		||||
 | 
			
		||||
  const ConversationRoute({
 | 
			
		||||
    Key key,
 | 
			
		||||
    @required this.conversationID,
 | 
			
		||||
  })  : assert(conversationID != null),
 | 
			
		||||
        super(key: key);
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  State<StatefulWidget> createState() => _ConversationRouteState();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class _ConversationRouteState extends State<ConversationRoute> {
 | 
			
		||||
  final ConversationsHelper _conversationsHelper = ConversationsHelper();
 | 
			
		||||
  Conversation _conversation;
 | 
			
		||||
  String _conversationName;
 | 
			
		||||
  bool _error = false;
 | 
			
		||||
 | 
			
		||||
  setError(bool err) => setState(() => _error = err);
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  void didChangeDependencies() {
 | 
			
		||||
    super.didChangeDependencies();
 | 
			
		||||
    _loadConversation();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Future<void> _loadConversation() async {
 | 
			
		||||
    setError(false);
 | 
			
		||||
 | 
			
		||||
    _conversation =
 | 
			
		||||
        await _conversationsHelper.getSingle(widget.conversationID);
 | 
			
		||||
 | 
			
		||||
    if (_conversation == null) return setError(true);
 | 
			
		||||
 | 
			
		||||
    final conversationName =
 | 
			
		||||
        await ConversationsHelper.getConversationNameAsync(_conversation);
 | 
			
		||||
 | 
			
		||||
    if(conversationName == null)
 | 
			
		||||
      return setError(true);
 | 
			
		||||
 | 
			
		||||
    setState(() {
 | 
			
		||||
      _conversationName = conversationName;
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Widget _buildRouteBody() {
 | 
			
		||||
    //Handle errors
 | 
			
		||||
    if (_error != null && _error)
 | 
			
		||||
      return buildErrorCard(
 | 
			
		||||
        tr("Could not get conversation information!"),
 | 
			
		||||
        actions: <Widget>[
 | 
			
		||||
          FlatButton(
 | 
			
		||||
            onPressed: _loadConversation,
 | 
			
		||||
            child: Text(
 | 
			
		||||
              tr("Try again").toUpperCase(),
 | 
			
		||||
              style: TextStyle(
 | 
			
		||||
                color: Colors.white,
 | 
			
		||||
              ),
 | 
			
		||||
            ),
 | 
			
		||||
          ),
 | 
			
		||||
        ],
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
    //if (_conversationName == null || _conversation == null)
 | 
			
		||||
      return buildCenteredProgressBar();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return Scaffold(
 | 
			
		||||
      appBar: AppBar(
 | 
			
		||||
        title: Text(
 | 
			
		||||
          _conversationName == null ? tr("Loading") : _conversationName,
 | 
			
		||||
        ),
 | 
			
		||||
      ),
 | 
			
		||||
      body: _buildRouteBody(),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
import 'package:comunic/ui/screens/conversations_screen.dart';
 | 
			
		||||
import 'package:comunic/ui/screens/conversations_list_screen.dart';
 | 
			
		||||
import 'package:comunic/ui/screens/menus_screen.dart';
 | 
			
		||||
import 'package:comunic/ui/tiles/custom_bottom_navigation_bar_item.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
@@ -49,7 +49,7 @@ class _HomeRouteState extends State<HomeRoute> {
 | 
			
		||||
  Widget _buildBody(BuildContext context) {
 | 
			
		||||
    switch (_currTab) {
 | 
			
		||||
      case 0:
 | 
			
		||||
        return ConversationsScreen();
 | 
			
		||||
        return ConversationsListScreen();
 | 
			
		||||
 | 
			
		||||
      case 1:
 | 
			
		||||
        return MenuScreen();
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@ import 'package:comunic/enums/load_error_level.dart';
 | 
			
		||||
import 'package:comunic/helpers/conversations_helper.dart';
 | 
			
		||||
import 'package:comunic/helpers/users_helper.dart';
 | 
			
		||||
import 'package:comunic/lists/conversations_list.dart';
 | 
			
		||||
import 'package:comunic/ui/routes/conversation_route.dart';
 | 
			
		||||
import 'package:comunic/ui/tiles/conversation_tile.dart';
 | 
			
		||||
import 'package:comunic/utils/intl_utils.dart';
 | 
			
		||||
import 'package:comunic/utils/ui_utils.dart';
 | 
			
		||||
@@ -11,12 +12,12 @@ import 'package:flutter/material.dart';
 | 
			
		||||
///
 | 
			
		||||
/// @author Pierre HUBERT
 | 
			
		||||
 | 
			
		||||
class ConversationsScreen extends StatefulWidget {
 | 
			
		||||
class ConversationsListScreen extends StatefulWidget {
 | 
			
		||||
  @override
 | 
			
		||||
  State<StatefulWidget> createState() => _ConversationScreenState();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class _ConversationScreenState extends State<ConversationsScreen> {
 | 
			
		||||
class _ConversationScreenState extends State<ConversationsListScreen> {
 | 
			
		||||
  final ConversationsHelper _conversationsHelper = ConversationsHelper();
 | 
			
		||||
  final UsersHelper _usersHelper = UsersHelper();
 | 
			
		||||
  ConversationsList _list;
 | 
			
		||||
@@ -88,6 +89,13 @@ class _ConversationScreenState extends State<ConversationsScreen> {
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Open a conversation
 | 
			
		||||
  void _openConversation(BuildContext context, int conversationId){
 | 
			
		||||
    Navigator.of(context).push(MaterialPageRoute(builder: (c){
 | 
			
		||||
      return ConversationRoute(conversationID: conversationId,);
 | 
			
		||||
    }));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    if (_error == LoadErrorLevel.MAJOR) return _buildErrorCard();
 | 
			
		||||
@@ -103,10 +111,12 @@ class _ConversationScreenState extends State<ConversationsScreen> {
 | 
			
		||||
            ),
 | 
			
		||||
            Expanded(
 | 
			
		||||
              child: ListView.builder(
 | 
			
		||||
                controller: ScrollController(),
 | 
			
		||||
                itemBuilder: (context, index) {
 | 
			
		||||
                  return ConversationTile(
 | 
			
		||||
                    conversation: _list.elementAt(index),
 | 
			
		||||
                    usersList: _list.users,
 | 
			
		||||
                    onOpen: (c){_openConversation(context, c.id);},
 | 
			
		||||
                  );
 | 
			
		||||
                },
 | 
			
		||||
                itemCount: _list.length,
 | 
			
		||||
@@ -9,14 +9,21 @@ import 'package:flutter/material.dart';
 | 
			
		||||
///
 | 
			
		||||
/// @author Pierre HUBERT
 | 
			
		||||
 | 
			
		||||
typedef OpenConversationCallback = void Function(Conversation);
 | 
			
		||||
 | 
			
		||||
class ConversationTile extends StatelessWidget {
 | 
			
		||||
  final Conversation conversation;
 | 
			
		||||
  final UsersList usersList;
 | 
			
		||||
  final OpenConversationCallback onOpen;
 | 
			
		||||
 | 
			
		||||
  const ConversationTile(
 | 
			
		||||
      {Key key, @required this.conversation, @required this.usersList})
 | 
			
		||||
      {Key key,
 | 
			
		||||
      @required this.conversation,
 | 
			
		||||
      @required this.usersList,
 | 
			
		||||
      @required this.onOpen})
 | 
			
		||||
      : assert(conversation != null),
 | 
			
		||||
        assert(usersList != null),
 | 
			
		||||
        assert(onOpen != null),
 | 
			
		||||
        super(key: key);
 | 
			
		||||
 | 
			
		||||
  _buildSubInformation(IconData icon, String content) {
 | 
			
		||||
@@ -35,6 +42,7 @@ class ConversationTile extends StatelessWidget {
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return ListTile(
 | 
			
		||||
      onTap: () => onOpen(conversation),
 | 
			
		||||
      // Conversation name
 | 
			
		||||
      title: Text(
 | 
			
		||||
        ConversationsHelper.getConversationName(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user