[Web] Fix missing MatrixState in context because of wrong order in widget tree

Took 21 minutes
This commit is contained in:
Marcel 2020-01-23 11:11:57 +00:00 committed by Christian Pauly
parent a512dc6dbd
commit a980217779
10 changed files with 114 additions and 90 deletions

View file

@ -346,10 +346,12 @@ class MatrixState extends State<Matrix> {
@override
void initState() {
if (widget.client == null) {
print("[Matrix] Init matrix client");
client = Client(widget.clientName, debug: false);
if (!kIsWeb) {
_initWithStore();
} else {
print("[Web] Web platform detected - Store disabled!");
loadAccount();
}
} else {

View file

@ -20,7 +20,8 @@ class App extends StatelessWidget {
Widget build(BuildContext context) {
return Matrix(
clientName: "FluffyChat",
child: MaterialApp(
child: Builder(
builder: (BuildContext context) => MaterialApp(
title: 'FluffyChat',
theme: ThemeData(
brightness: Brightness.light,
@ -58,8 +59,7 @@ class App extends StatelessWidget {
const Locale('en'), // English
const Locale('de'), // German
],
home: Builder(
builder: (BuildContext context) => FutureBuilder<LoginState>(
home: FutureBuilder<LoginState>(
future: Matrix.of(context).client.onLoginStateChanged.stream.first,
builder: (context, snapshot) {
if (!snapshot.hasData) {

View file

@ -7,7 +7,7 @@ extension LocalizedRoomDisplayname on Room {
if ((this.name?.isEmpty ?? true) &&
(this.canonicalAlias?.isEmpty ?? true) &&
!this.isDirectChat &&
this.mHeroes.isNotEmpty) {
(this.mHeroes != null && this.mHeroes.isNotEmpty)) {
return I18n.of(context).groupWith(this.displayname);
}
return this.displayname;

View file

@ -20,6 +20,7 @@ class Chat extends StatefulWidget {
final String id;
const Chat(this.id, {Key key}) : super(key: key);
@override
_ChatState createState() => _ChatState();
}
@ -55,6 +56,8 @@ class _ChatState extends State<Chat> {
}
void updateView() {
if (!mounted) return;
String seenByText = "";
if (timeline.events.isNotEmpty) {
List lastReceipts = List.from(timeline.events.first.receipts);
@ -74,10 +77,12 @@ class _ChatState extends State<Chat> {
(lastReceipts.length - 1).toString());
}
}
if (timeline != null) {
setState(() {
this.seenByText = seenByText;
});
}
}
Future<bool> getTimeline() async {
timeline ??= await room.getTimeline(onUpdate: updateView);
@ -88,6 +93,7 @@ class _ChatState extends State<Chat> {
@override
void dispose() {
timeline?.sub?.cancel();
timeline = null;
matrix.activeRoomId = "";
super.dispose();
}
@ -243,11 +249,15 @@ class _ChatState extends State<Chat> {
timeline.events.isNotEmpty) {
room.sendReadReceipt(timeline.events[0].eventId);
}
if (timeline.events.isEmpty) return Container();
return ListView.builder(
reverse: true,
itemCount: timeline.events.length + 1,
controller: _scrollController,
itemBuilder: (BuildContext context, int i) => i == 0
itemBuilder: (BuildContext context, int i) {
return i == 0
? AnimatedContainer(
height: seenByText.isEmpty ? 0 : 24,
duration: seenByText.isEmpty
@ -273,8 +283,8 @@ class _ChatState extends State<Chat> {
)
: Message(timeline.events[i - 1],
nextEvent:
i >= 2 ? timeline.events[i - 2] : null),
);
i >= 2 ? timeline.events[i - 2] : null);
});
},
),
),

View file

@ -13,6 +13,7 @@ import 'package:fluffychat/utils/room_extension.dart';
import 'package:fluffychat/utils/room_state_enums_extensions.dart';
import 'package:fluffychat/views/chat_list.dart';
import 'package:fluffychat/views/invitation_selection.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:image_picker/image_picker.dart';
@ -181,7 +182,8 @@ class _ChatDetailsState extends State<ChatDetails> {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
ContentBanner(widget.room.avatar,
onEdit: widget.room.canSendEvent("m.room.avatar")
onEdit:
widget.room.canSendEvent("m.room.avatar") && !kIsWeb
? () => setAvatarAction(context)
: null),
Divider(height: 1),

View file

@ -11,6 +11,7 @@ import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/utils/url_launcher.dart';
import 'package:fluffychat/views/archive.dart';
import 'package:fluffychat/views/settings.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
@ -51,7 +52,8 @@ class _ChatListState extends State<ChatList> {
if (client.prevBatch?.isEmpty ?? true) {
await client.onFirstSync.stream.first;
}
sub ??= client.onSync.stream.listen((s) => setState(() => null));
sub ??= client.onSync.stream
.listen((s) => mounted ? setState(() => null) : null);
return true;
}
@ -60,13 +62,16 @@ class _ChatListState extends State<ChatList> {
searchController.addListener(
() => setState(() => null),
);
if (kIsWeb) {
getSharedData();
}
super.initState();
}
StreamSubscription _intentDataStreamSubscription;
void processSharedText(String text) {
if (text?.isEmpty ?? true) return;
if (text.startsWith("https://matrix.to/#/")) {
UrlLauncher(context, text).openMatrixToUrl();
} else {

View file

@ -4,6 +4,7 @@ import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/matrix.dart';
import 'package:fluffychat/i18n/i18n.dart';
import 'package:fluffychat/utils/app_route.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'chat_list.dart';
@ -73,6 +74,7 @@ class _LoginState extends State<Login> {
setState(() => passwordError = exception.toString());
return setState(() => loading = false);
}
if (!kIsWeb) {
try {
print("[Login] Setup Firebase...");
await matrix.setupFirebase();
@ -83,6 +85,8 @@ class _LoginState extends State<Login> {
setState(() => passwordError = exception.toString());
return setState(() => loading = false);
}
}
print("[Login] Store account and go to ChatListView");
await Matrix.of(context).saveAccount();
setState(() => loading = false);

View file

@ -8,6 +8,7 @@ import 'package:fluffychat/i18n/i18n.dart';
import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/views/chat_list.dart';
import 'package:fluffychat/views/sign_up.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:toast/toast.dart';
@ -106,7 +107,7 @@ class _SettingsState extends State<Settings> {
profile?.avatarUrl ?? MxContent(""),
defaultIcon: Icons.account_circle,
loading: profile == null,
onEdit: () => setAvatarAction(context),
onEdit: kIsWeb ? null : () => setAvatarAction(context),
),
ListTile(
leading: Icon(Icons.edit),

View file

@ -110,8 +110,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: "2545995bbe96a1d96fe176ab666f4dd03d591aa6"
resolved-ref: "2545995bbe96a1d96fe176ab666f4dd03d591aa6"
ref: bc2ca9749cfcc0506c59f97f4ae4987f0e84fbf4
resolved-ref: bc2ca9749cfcc0506c59f97f4ae4987f0e84fbf4
url: "https://gitlab.com/famedly/famedlysdk.git"
source: git
version: "0.0.1"

View file

@ -27,7 +27,7 @@ dependencies:
famedlysdk:
git:
url: https://gitlab.com/famedly/famedlysdk.git
ref: 2545995bbe96a1d96fe176ab666f4dd03d591aa6
ref: bc2ca9749cfcc0506c59f97f4ae4987f0e84fbf4
localstorage: ^3.0.1+4
bubble: ^1.1.9+1