Commit 43952f2e authored by Wilko Manger's avatar Wilko Manger

Remove use for FutureOrBuilder

Also rename ChatOverview to Chat.
parent 0d2b088b
......@@ -20,7 +20,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:matrix_sdk/matrix_sdk.dart';
import 'package:pattle/src/redirect.dart';
import 'package:provider/provider.dart';
......@@ -32,6 +31,7 @@ import 'resources/theme.dart';
import 'section/main/chat/page.dart';
import 'section/main/chat/image/page.dart';
import 'section/main/chat/settings/page.dart';
import 'section/main/chats/models/chat_overview.dart';
import 'section/main/chats/page.dart';
import 'section/main/chats/create/group/details_page.dart';
import 'section/main/chats/create/group/members_page.dart';
......@@ -67,7 +67,7 @@ final routes = {
),
Routes.chats: (Object arguments) => MaterialPageRoute(
settings: RouteSettings(name: Routes.chats),
builder: (context) => arguments is Room
builder: (context) => arguments is Chat
? ChatPage.withBloc(arguments)
: ChatsPage.withBloc(),
),
......
......@@ -26,6 +26,7 @@ import 'package:pattle/src/app.dart';
import 'package:pattle/src/resources/localizations.dart';
import 'package:pattle/src/resources/theme.dart';
import 'package:pattle/src/section/main/chats/models/chat_overview.dart';
import 'package:pattle/src/section/main/widgets/chat_name.dart';
import 'package:pattle/src/section/main/widgets/error.dart';
import 'package:pattle/src/section/main/widgets/title_with_sub.dart';
......@@ -42,14 +43,14 @@ import 'widgets/bubble/state.dart';
import 'widgets/date_header.dart';
class ChatPage extends StatefulWidget {
final Room room;
final Chat chat;
ChatPage._(this.room);
ChatPage._(this.chat);
static Widget withBloc(Room room) {
static Widget withBloc(Chat chat) {
return BlocProvider<ChatBloc>(
create: (c) => ChatBloc(Matrix.of(c), room),
child: ChatPage._(room),
create: (c) => ChatBloc(Matrix.of(c), chat.room),
child: ChatPage._(chat),
);
}
......@@ -60,7 +61,7 @@ class ChatPage extends StatefulWidget {
class _ChatPageState extends State<ChatPage> {
Timer _readTimer;
Room get _room => widget.room;
Room get _room => widget.chat.room;
@override
void dispose() {
......@@ -87,7 +88,7 @@ class _ChatPageState extends State<ChatPage> {
@override
Widget build(BuildContext context) {
Widget avatar = Container();
final avatarUrl = widget.room.displayAvatarUrl;
final avatarUrl = widget.chat.room.displayAvatarUrl;
if (avatarUrl != null) {
avatar = Hero(
tag: _room.id,
......@@ -103,7 +104,7 @@ class _ChatPageState extends State<ChatPage> {
final settingsGestureDetector = ({Widget child}) {
return GestureDetector(
onTap: () => Navigator.of(context)
.pushNamed(Routes.chatsSettings, arguments: _room),
.pushNamed(Routes.chatsSettings, arguments: widget.chat),
child: child,
);
};
......@@ -112,14 +113,14 @@ class _ChatPageState extends State<ChatPage> {
Widget title =
_room.isSomeoneElseTyping && !_room.typingUsers.any((u) => u == null)
? TitleWithSub(
title: ChatName(room: _room),
title: ChatName(chat: widget.chat),
subtitle: RichText(
text: TextSpan(
children: typingSpan(context, _room),
),
),
)
: ChatName(room: _room);
: ChatName(chat: widget.chat);
return Scaffold(
backgroundColor: chatBackgroundColor(context),
......
......@@ -23,6 +23,7 @@ import 'package:matrix_sdk/matrix_sdk.dart';
import 'package:pattle/src/resources/localizations.dart';
import 'package:pattle/src/resources/theme.dart';
import 'package:pattle/src/section/main/chats/models/chat_overview.dart';
import 'package:pattle/src/section/main/widgets/chat_name.dart';
import 'package:pattle/src/section/main/widgets/user_item.dart';
......@@ -33,14 +34,14 @@ import '../../../../util/room.dart';
import 'bloc.dart';
class ChatSettingsPage extends StatefulWidget {
final Room room;
final Chat chat;
ChatSettingsPage._(this.room);
ChatSettingsPage._(this.chat);
static Widget withBloc(Room room) {
static Widget withBloc(Chat chat) {
return BlocProvider<ChatSettingsBloc>(
create: (c) => ChatSettingsBloc(Matrix.of(c), room),
child: ChatSettingsPage._(room),
create: (c) => ChatSettingsBloc(Matrix.of(c), chat.room),
child: ChatSettingsPage._(chat),
);
}
......@@ -49,7 +50,7 @@ class ChatSettingsPage extends StatefulWidget {
}
class _ChatSettingsPageState extends State<ChatSettingsPage> {
Room get room => widget.room;
Room get room => widget.chat.room;
@override
void didChangeDependencies() {
......@@ -67,15 +68,15 @@ class _ChatSettingsPageState extends State<ChatSettingsPage> {
),
body: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
final url = widget.room.displayAvatarUrl?.toDownloadString(context);
final url =
widget.chat.room.displayAvatarUrl?.toDownloadString(context);
return <Widget>[
SliverAppBar(
expandedHeight: 128.0,
floating: false,
pinned: true,
flexibleSpace: FlexibleSpaceBar(
title: ChatName(
room: room,
title: DefaultTextStyle(
style: TextStyle(
shadows: [
Shadow(
......@@ -84,6 +85,9 @@ class _ChatSettingsPageState extends State<ChatSettingsPage> {
)
],
),
child: ChatName(
chat: widget.chat,
),
),
background: url != null
? CachedNetworkImage(
......
......@@ -34,12 +34,12 @@ class ChatsBloc extends Bloc<ChatsEvent, ChatsState> {
ChatsBloc(this._matrix);
Future<List<ChatOverview>> _getChats() async {
Future<List<Chat>> _getChats() async {
final me = _matrix.user;
await me.sync.first;
final chats = List<ChatOverview>();
final chats = List<Chat>();
// Get all rooms and push them as a single list
for (Room room in await me.rooms.get()) {
......@@ -74,9 +74,10 @@ class ChatsBloc extends Bloc<ChatsEvent, ChatsState> {
latestEventForSorting = latestEvent;
}
final chat = ChatOverview(
final chat = Chat(
room: room,
name: room.name,
name: await room.getDisplayName(),
isJustYou: room.members.count == 1,
latestMessage: latestEvent != null
? ChatMessage(
room,
......
......@@ -20,7 +20,7 @@ import 'package:meta/meta.dart';
import 'package:pattle/src/section/main/models/chat_message.dart';
/// Chat overview used in the 'chats' page.
class ChatOverview {
class Chat {
final Room room;
final String name;
......@@ -28,10 +28,13 @@ class ChatOverview {
final ChatMessage latestMessage;
final ChatMessage latestMessageForSorting;
ChatOverview({
final bool isJustYou;
Chat({
@required this.room,
@required this.name,
@required this.latestMessage,
@required this.latestMessageForSorting,
this.isJustYou = false,
});
}
......@@ -10,8 +10,8 @@ abstract class ChatsState extends Equatable {
class ChatsLoading extends ChatsState {}
class ChatsLoaded extends ChatsState {
final List<ChatOverview> personal;
final List<ChatOverview> public;
final List<Chat> personal;
final List<Chat> public;
ChatsLoaded({@required this.personal, @required this.public});
......
......@@ -25,7 +25,7 @@ import 'chat_avatar.dart';
import 'subtitle.dart';
class ChatOverviewList extends StatefulWidget {
final List<ChatOverview> chats;
final List<Chat> chats;
const ChatOverviewList({Key key, this.chats}) : super(key: key);
......@@ -51,7 +51,7 @@ class ChatOverviewListState extends State<ChatOverviewList> {
);
}
Widget _buildChatOverview(ChatOverview chat) {
Widget _buildChatOverview(Chat chat) {
final time = formatAsListItem(context, chat.latestMessage?.event?.time);
return ListTile(
......@@ -61,7 +61,7 @@ class ChatOverviewListState extends State<ChatOverviewList> {
children: <Widget>[
Expanded(
child: ChatName(
room: chat.room,
chat: chat,
),
),
Text(
......@@ -75,7 +75,7 @@ class ChatOverviewListState extends State<ChatOverviewList> {
),
dense: false,
onTap: () {
Navigator.pushNamed(context, Routes.chats, arguments: chat.room);
Navigator.pushNamed(context, Routes.chats, arguments: chat);
},
leading: ChatAvatar(room: chat.room),
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 4),
......
......@@ -35,12 +35,12 @@ import 'typing_subtitle.dart';
import 'unsupported_subtitle.dart';
class Subtitle extends StatelessWidget {
final ChatOverview chat;
final Chat chat;
final Widget child;
const Subtitle({Key key, this.chat, this.child}) : super(key: key);
static Widget withContent(ChatOverview chat) {
static Widget withContent(Chat chat) {
Widget content;
// TODO: typingUsers should not contain nulls
......
......@@ -16,43 +16,24 @@
// along with Pattle. If not, see <https://www.gnu.org/licenses/>.
import 'package:flutter/material.dart';
import 'package:future_or_builder/future_or_builder.dart';
import 'package:matrix_sdk/matrix_sdk.dart';
import 'package:meta/meta.dart';
import '../../../util/room.dart';
import 'package:pattle/src/resources/localizations.dart';
import 'package:pattle/src/section/main/chats/models/chat_overview.dart';
class ChatName extends StatelessWidget {
final Room room;
final TextStyle style;
ChatName({
@required this.room,
this.style = const TextStyle(),
});
final Chat chat;
TextStyle _textStyle() => style.copyWith(
fontWeight: FontWeight.w600,
);
ChatName({@required this.chat});
@override
Widget build(BuildContext context) {
return FutureOrBuilder<String>(
futureOr: room.getDisplayName(context),
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
if (snapshot.hasData) {
final name = snapshot.data;
return Text(
name,
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: _textStyle(),
);
}
return Container();
},
return Text(
chat.isJustYou ? l(context).you : chat.name,
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: TextStyle(
fontWeight: FontWeight.w600,
),
);
}
}
......@@ -200,13 +200,6 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
future_or_builder:
dependency: "direct main"
description:
name: future_or_builder
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
html:
dependency: transitive
description:
......
......@@ -23,8 +23,6 @@ dependencies:
cached_network_image: ^2.0.0-rc.1
flutter_cache_manager: ^1.1.3
future_or_builder: ^1.0.3
sqflite: ^1.1.6
async: ^2.3.0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment