flutter_app/lib/widgets/messagelist.dart

85 lines
4.5 KiB
Dart
Raw Permalink Normal View History

2021-01-21 20:37:35 +00:00
import 'package:flutter/material.dart';
2021-06-04 22:00:09 +00:00
import 'package:flutter/rendering.dart';
2021-01-21 20:37:35 +00:00
import 'package:provider/provider.dart';
2021-06-04 20:17:40 +00:00
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
2021-01-21 20:37:35 +00:00
import '../model.dart';
import '../settings.dart';
2021-04-14 02:33:21 +00:00
import 'messagerow.dart';
2021-01-21 20:37:35 +00:00
class MessageList extends StatefulWidget {
@override
_MessageListState createState() => _MessageListState();
}
class _MessageListState extends State<MessageList> {
2021-04-08 05:07:01 +00:00
ScrollController ctrlr1 = ScrollController();
2021-01-21 20:37:35 +00:00
@override
2021-03-17 22:54:41 +00:00
Widget build(BuildContext outerContext) {
2021-06-04 21:38:29 +00:00
bool showEphemeralWarning = (Provider.of<ContactInfoState>(context).isGroup == false && Provider.of<ContactInfoState>(context).savePeerHistory != "SaveHistory");
bool showOfflineWarning = Provider.of<ContactInfoState>(context).isOnline() == false;
bool showMessageWarning = showEphemeralWarning || showOfflineWarning;
2021-06-24 20:38:41 +00:00
bool showSyncing = Provider.of<ContactInfoState>(context).isGroup == true && Provider.of<ContactInfoState>(context).status != "Synced";
2021-05-25 20:43:13 +00:00
return RepaintBoundary(
child: Container(
2021-06-04 20:17:40 +00:00
child: Column(children: [
Visibility(
2021-06-04 21:38:29 +00:00
visible: showMessageWarning,
2021-06-04 20:17:40 +00:00
child: Container(
padding: EdgeInsets.all(5.0),
color: Provider.of<Settings>(context).theme.defaultButtonActiveColor(),
2021-06-24 20:38:41 +00:00
child: showSyncing ?
Text(AppLocalizations.of(context)!.serverNotSynced,
textAlign: TextAlign.center)
: showOfflineWarning
2021-06-04 22:00:09 +00:00
? Text(Provider.of<ContactInfoState>(context).isGroup ? AppLocalizations.of(context)!.serverConnectivityDisconnected : AppLocalizations.of(context)!.peerOfflineMessage,
textAlign: TextAlign.center)
2021-06-04 21:38:29 +00:00
// Only show the ephemeral status for peer conversations, not for groups...
: (showEphemeralWarning
2021-06-04 22:00:09 +00:00
? Text(AppLocalizations.of(context)!.chatHistoryDefault, textAlign: TextAlign.center)
2021-06-04 21:38:29 +00:00
:
// We are not allowed to put null here, so put an empty text widge
Text("")),
2021-06-04 20:17:40 +00:00
)),
Expanded(
child: Scrollbar(
controller: ctrlr1,
child: Container(
2021-05-25 20:43:13 +00:00
// Only show broken heart is the contact is offline...
decoration: BoxDecoration(
image: Provider.of<ContactInfoState>(outerContext).isOnline()
? null
: DecorationImage(
2021-06-04 22:00:09 +00:00
fit: BoxFit.scaleDown,
alignment: Alignment.center,
2021-05-25 20:43:13 +00:00
image: AssetImage("assets/core/negative_heart_512px.png"),
2021-06-04 22:00:09 +00:00
colorFilter: ColorFilter.mode(Provider.of<Settings>(context).theme.hilightElementTextColor(), BlendMode.srcIn))),
2021-06-24 20:38:41 +00:00
// Don't load messages for syncing server...
2021-05-25 20:43:13 +00:00
child: ListView.builder(
controller: ctrlr1,
itemCount: Provider.of<ContactInfoState>(outerContext).totalMessages,
2021-06-07 22:12:24 +00:00
reverse: true, // NOTE: There seems to be a bug in flutter that corrects the mouse wheel scroll, but not the drag direction...
2021-05-25 20:43:13 +00:00
itemBuilder: (itemBuilderContext, index) {
var trueIndex = Provider.of<ContactInfoState>(outerContext).totalMessages - index - 1;
return ChangeNotifierProvider(
key: ValueKey(trueIndex),
create: (x) => MessageState(
context: itemBuilderContext,
profileOnion: Provider.of<ProfileInfoState>(outerContext, listen: false).onion,
// We don't want to listen for updates to the contact handle...
2021-05-25 20:43:13 +00:00
contactHandle: Provider.of<ContactInfoState>(x, listen: false).onion,
messageIndex: trueIndex,
),
builder: (bcontext, child) {
String idx = Provider.of<ContactInfoState>(outerContext).isGroup == true && Provider.of<MessageState>(bcontext).signature.isEmpty == false
? Provider.of<MessageState>(bcontext).signature
: trueIndex.toString();
return RepaintBoundary(child: MessageRow(key: Provider.of<ContactInfoState>(bcontext).getMessageKey(idx)));
});
},
2021-06-04 20:17:40 +00:00
))))
])));
2021-01-21 20:37:35 +00:00
}
2021-03-24 23:35:24 +00:00
}