jld3103
2 years ago
4 changed files with 60 additions and 0 deletions
@ -0,0 +1,50 @@
|
||||
import 'package:flutter/material.dart'; |
||||
import 'package:flutter_parsed_text/flutter_parsed_text.dart'; |
||||
import 'package:neon/src/blocs/accounts.dart'; |
||||
import 'package:neon/src/widgets/user_avatar.dart'; |
||||
import 'package:provider/provider.dart'; |
||||
|
||||
class NeonRichObject extends MatchText { |
||||
NeonRichObject({ |
||||
required final Map<String, dynamic> parameters, |
||||
}) : super( |
||||
onTap: (final _) {}, |
||||
pattern: '{(${parameters.keys.join('|')})}', |
||||
renderWidget: ({ |
||||
required final pattern, |
||||
required final text, |
||||
}) => |
||||
Builder( |
||||
builder: (final context) { |
||||
final richObject = parameters[text.substring(1, text.length - 1)] as Map<String, dynamic>; |
||||
switch (richObject['type']! as String) { |
||||
case 'user': |
||||
case 'call': |
||||
final account = Provider.of<AccountsBloc>(context, listen: false).activeAccount.value!; |
||||
final id = richObject['id']! as String; |
||||
final isOwnUser = id == account.username; |
||||
return Chip( |
||||
avatar: NeonUserAvatar( |
||||
account: account, |
||||
username: id, |
||||
showStatus: false, |
||||
), |
||||
label: Text( |
||||
richObject['name']! as String, |
||||
style: TextStyle( |
||||
color: isOwnUser |
||||
? Theme.of(context).colorScheme.onPrimary |
||||
: Theme.of(context).colorScheme.onBackground, |
||||
), |
||||
), |
||||
backgroundColor: |
||||
isOwnUser ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.background, |
||||
); |
||||
default: |
||||
debugPrint('Rich message type ${richObject['type']} not implemented yet'); |
||||
return Text(text); |
||||
} |
||||
}, |
||||
), |
||||
); |
||||
} |
Loading…
Reference in new issue