refactor: Migrate to flutter 2

This commit is contained in:
Christian Pauly 2021-03-04 12:28:06 +01:00
commit b0ada828aa
39 changed files with 257 additions and 315 deletions

View file

@ -66,8 +66,8 @@ class ContentBanner extends StatelessWidget {
alignment: Alignment.bottomRight,
child: FloatingActionButton(
mini: true,
child: Icon(Icons.camera_alt_outlined),
onPressed: onEdit,
child: Icon(Icons.camera_alt_outlined),
),
),
],

View file

@ -18,17 +18,17 @@ class AdaptiveFlatButton extends StatelessWidget {
Widget build(BuildContext context) {
if (PlatformInfos.isCupertinoStyle) {
return CupertinoDialogAction(
child: Text(label),
onPressed: onPressed,
textStyle: textColor != null ? TextStyle(color: textColor) : null,
child: Text(label),
);
}
return TextButton(
onPressed: onPressed,
child: Text(
label,
style: TextStyle(color: textColor),
),
onPressed: onPressed,
);
}
}

View file

@ -105,6 +105,7 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
body = Container(
margin: EdgeInsets.only(left: 8.0, right: 8.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(L10n.of(context).askSSSSSign,
style: TextStyle(fontSize: 20)),
@ -128,7 +129,6 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
),
),
],
mainAxisSize: MainAxisSize.min,
),
);
buttons.add(AdaptiveFlatButton(
@ -145,10 +145,10 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
break;
case KeyVerificationState.askAccept:
body = Container(
margin: EdgeInsets.only(left: 8.0, right: 8.0),
child: Text(
L10n.of(context).askVerificationRequest(widget.request.userId),
style: TextStyle(fontSize: 20)),
margin: EdgeInsets.only(left: 8.0, right: 8.0),
);
buttons.add(AdaptiveFlatButton(
label: L10n.of(context).accept,
@ -165,6 +165,7 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
break;
case KeyVerificationState.waitingAccept:
body = Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
PlatformInfos.isCupertinoStyle
? CupertinoActivityIndicator()
@ -175,7 +176,6 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
textAlign: TextAlign.center,
),
],
mainAxisSize: MainAxisSize.min,
);
final key = widget.request.client.userDeviceKeys[widget.request.userId]
.deviceKeys[widget.request.deviceId];
@ -219,6 +219,7 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
TextSpan(text: numbstr, style: TextStyle(fontSize: 40));
}
body = Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Center(
child: Text(
@ -233,7 +234,6 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
textAlign: TextAlign.center,
),
],
mainAxisSize: MainAxisSize.min,
);
buttons.add(AdaptiveFlatButton(
textColor: Colors.red,
@ -250,6 +250,7 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
? L10n.of(context).waitingPartnerEmoji
: L10n.of(context).waitingPartnerNumbers;
body = Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
PlatformInfos.isCupertinoStyle
? CupertinoActivityIndicator()
@ -260,11 +261,11 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
textAlign: TextAlign.center,
),
],
mainAxisSize: MainAxisSize.min,
);
break;
case KeyVerificationState.done:
body = Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Icon(Icons.check_circle_outlined, color: Colors.green, size: 200.0),
SizedBox(height: 10),
@ -273,7 +274,6 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
textAlign: TextAlign.center,
),
],
mainAxisSize: MainAxisSize.min,
);
buttons.add(AdaptiveFlatButton(
label: L10n.of(context).close,
@ -282,6 +282,7 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
break;
case KeyVerificationState.error:
body = Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Icon(Icons.cancel, color: Colors.red, size: 200.0),
SizedBox(height: 10),
@ -290,7 +291,6 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
textAlign: TextAlign.center,
),
],
mainAxisSize: MainAxisSize.min,
);
buttons.add(AdaptiveFlatButton(
label: L10n.of(context).close,
@ -318,6 +318,7 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
}
final userNameTitle = Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
otherName,
@ -336,7 +337,6 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
),
),
],
crossAxisAlignment: CrossAxisAlignment.start,
);
final title = Text(L10n.of(context).verifyTitle);
final content = Scrollbar(

View file

@ -108,15 +108,21 @@ class _RecordingDialogState extends State<RecordingDialog> {
),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.of(context, rootNavigator: false).pop(),
child: Text(
L10n.of(context).cancel.toUpperCase(),
style: TextStyle(
color: Theme.of(context).textTheme.bodyText2.color.withAlpha(150),
),
),
onPressed: () => Navigator.of(context, rootNavigator: false).pop(),
),
TextButton(
onPressed: () async {
await _recorderSubscription?.cancel();
await flutterSound.stopRecorder();
Navigator.of(context, rootNavigator: false)
.pop<String>(_recordedPath);
},
child: Row(
children: <Widget>[
Text(L10n.of(context).send.toUpperCase()),
@ -124,12 +130,6 @@ class _RecordingDialogState extends State<RecordingDialog> {
Icon(Icons.send_outlined, size: 15),
],
),
onPressed: () async {
await _recorderSubscription?.cancel();
await flutterSound.stopRecorder();
Navigator.of(context, rootNavigator: false)
.pop<String>(_recordedPath);
},
),
],
);

View file

@ -78,14 +78,13 @@ class _SendFileDialogState extends State<SendFileDialog> {
content: contentWidget,
actions: <Widget>[
TextButton(
child: Text(L10n.of(context).cancel),
onPressed: () {
// just close the dialog
Navigator.of(context, rootNavigator: false).pop();
},
child: Text(L10n.of(context).cancel),
),
TextButton(
child: Text(L10n.of(context).send),
onPressed: _isSending
? null
: () async {
@ -94,8 +93,9 @@ class _SendFileDialogState extends State<SendFileDialog> {
});
await showFutureLoadingDialog(
context: context, future: () => _send());
await Navigator.of(context, rootNavigator: false).pop();
Navigator.of(context, rootNavigator: false).pop();
},
child: Text(L10n.of(context).send),
),
],
);

View file

@ -231,25 +231,25 @@ class InputBar extends StatelessWidget {
}
insertText = (isUnique
? insertEmote
: ':${insertPack}~${insertEmote.substring(1)}') +
: ':$insertPack~${insertEmote.substring(1)}') +
' ';
startText = replaceText.replaceAllMapped(
RegExp(r'(\s|^)(:(?:[-\w]+~)?[-\w]+)$'),
(Match m) => '${m[1]}${insertText}',
(Match m) => '${m[1]}$insertText',
);
}
if (suggestion['type'] == 'user') {
insertText = suggestion['mxid'] + ' ';
startText = replaceText.replaceAllMapped(
RegExp(r'(\s|^)(@[-\w]+)$'),
(Match m) => '${m[1]}${insertText}',
(Match m) => '${m[1]}$insertText',
);
}
if (suggestion['type'] == 'room') {
insertText = suggestion['mxid'] + ' ';
startText = replaceText.replaceAllMapped(
RegExp(r'(\s|^)(#[-\w]+)$'),
(Match m) => '${m[1]}${insertText}',
(Match m) => '${m[1]}$insertText',
);
}
if (insertText.isNotEmpty && startText.isNotEmpty) {

View file

@ -109,6 +109,11 @@ class Message extends StatelessWidget {
originServerTs: DateTime.now(),
);
return InkWell(
onTap: () {
if (scrollToEventId != null) {
scrollToEventId(replyEvent.eventId);
}
},
child: AbsorbPointer(
child: Container(
margin: EdgeInsets.symmetric(vertical: 4.0),
@ -116,11 +121,6 @@ class Message extends StatelessWidget {
lightText: ownMessage, timeline: timeline),
),
),
onTap: () {
if (scrollToEventId != null) {
scrollToEventId(replyEvent.eventId);
}
},
);
},
),

View file

@ -123,42 +123,28 @@ class MessageContent extends StatelessWidget {
continue textmessage;
case MessageTypes.BadEncrypted:
case EventTypes.Encrypted:
return RaisedButton(
elevation: 7,
color: Theme.of(context).scaffoldBackgroundColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.lock_outline),
SizedBox(width: 8),
Text(L10n.of(context).encrypted),
],
return ElevatedButton.icon(
style: ElevatedButton.styleFrom(
primary: Theme.of(context).scaffoldBackgroundColor,
onPrimary: Theme.of(context).textTheme.bodyText1.color,
),
onPressed: () => _verifyOrRequestKey(context),
icon: Icon(Icons.lock_outline),
label: Text(L10n.of(context).encrypted),
);
case MessageTypes.Location:
case MessageTypes.None:
textmessage:
default:
if (event.content['msgtype'] == Matrix.callNamespace) {
return RaisedButton(
elevation: 7,
color: Theme.of(context).scaffoldBackgroundColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Icon(Icons.phone_outlined, color: Colors.green),
SizedBox(width: 8),
Text(L10n.of(context).videoCall),
],
return ElevatedButton.icon(
style: ElevatedButton.styleFrom(
primary: Theme.of(context).scaffoldBackgroundColor,
onPrimary: Theme.of(context).textTheme.bodyText1.color,
),
onPressed: () => launch(event.body),
icon: Icon(Icons.phone_outlined, color: Colors.green),
label: Text(L10n.of(context).videoCall),
);
}
if (event.redacted) {

View file

@ -19,12 +19,12 @@ class MessageDownloadContent extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
RaisedButton(
elevation: 7,
color: Theme.of(context).scaffoldBackgroundColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6),
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Theme.of(context).scaffoldBackgroundColor,
onPrimary: Theme.of(context).textTheme.bodyText1.color,
),
onPressed: () => event.openFile(context),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
@ -38,7 +38,6 @@ class MessageDownloadContent extends StatelessWidget {
),
],
),
onPressed: () => event.openFile(context),
),
if (event.sizeString != null)
Text(

View file

@ -120,6 +120,7 @@ class _Reaction extends StatelessWidget {
));
}
return InkWell(
onTap: () => onTap != null ? onTap() : null,
child: Container(
decoration: BoxDecoration(
color: color,
@ -132,7 +133,6 @@ class _Reaction extends StatelessWidget {
padding: EdgeInsets.all(padding),
child: content,
),
onTap: () => onTap != null ? onTap() : null,
);
}
}

View file

@ -81,7 +81,7 @@ class UserBottomSheet extends StatelessWidget {
case 'message':
final roomId = await user.startDirectChat();
await AdaptivePageLayout.of(context)
.pushNamedAndRemoveUntilIsFirst('/rooms/${roomId}');
.pushNamedAndRemoveUntilIsFirst('/rooms/$roomId');
break;
}
}
@ -95,60 +95,66 @@ class UserBottomSheet extends StatelessWidget {
if (onMention != null) {
items.add(
PopupMenuItem(
child: _TextWithIcon(
L10n.of(context).mention,
Icons.alternate_email_outlined,
),
value: 'mention'),
value: 'mention',
child: _TextWithIcon(
L10n.of(context).mention,
Icons.alternate_email_outlined,
),
),
);
}
if (user.id != user.room.client.userID && !user.room.isDirectChat) {
items.add(
PopupMenuItem(
child: _TextWithIcon(
L10n.of(context).sendAMessage,
Icons.send_outlined,
),
value: 'message'),
value: 'message',
child: _TextWithIcon(
L10n.of(context).sendAMessage,
Icons.send_outlined,
),
),
);
}
if (user.canChangePowerLevel) {
items.add(
PopupMenuItem(
child: _TextWithIcon(
L10n.of(context).setPermissionsLevel,
Icons.edit_attributes_outlined,
),
value: 'permission'),
value: 'permission',
child: _TextWithIcon(
L10n.of(context).setPermissionsLevel,
Icons.edit_attributes_outlined,
),
),
);
}
if (user.canKick) {
items.add(
PopupMenuItem(
child: _TextWithIcon(
L10n.of(context).kickFromChat,
Icons.exit_to_app_outlined,
),
value: 'kick'),
value: 'kick',
child: _TextWithIcon(
L10n.of(context).kickFromChat,
Icons.exit_to_app_outlined,
),
),
);
}
if (user.canBan && user.membership != Membership.ban) {
items.add(
PopupMenuItem(
child: _TextWithIcon(
L10n.of(context).banFromChat,
Icons.warning_sharp,
),
value: 'ban'),
value: 'ban',
child: _TextWithIcon(
L10n.of(context).banFromChat,
Icons.warning_sharp,
),
),
);
} else if (user.canBan && user.membership == Membership.ban) {
items.add(
PopupMenuItem(
child: _TextWithIcon(
L10n.of(context).removeExile,
Icons.warning_outlined,
),
value: 'unban'),
value: 'unban',
child: _TextWithIcon(
L10n.of(context).removeExile,
Icons.warning_outlined,
),
),
);
}
return Center(