mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +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();
|
||||
|
Reference in New Issue
Block a user