Browse Source

feat(neon): Implement RichObject

Signed-off-by: jld3103 <jld3103yt@gmail.com>
pull/366/head
jld3103 2 years ago
parent
commit
70cd0a6239
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 8
      packages/app/pubspec.lock
  2. 50
      packages/neon/neon/lib/src/widgets/rich_object.dart
  3. 1
      packages/neon/neon/lib/widgets.dart
  4. 1
      packages/neon/neon/pubspec.yaml

8
packages/app/pubspec.lock

@ -398,6 +398,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.3.5"
flutter_parsed_text:
dependency: transitive
description:
name: flutter_parsed_text
sha256: "529cf5793b7acdf16ee0f97b158d0d4ba0bf06e7121ef180abe1a5b59e32c1e2"
url: "https://pub.dev"
source: hosted
version: "2.2.1"
flutter_plugin_android_lifecycle:
dependency: transitive
description:

50
packages/neon/neon/lib/src/widgets/rich_object.dart

@ -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);
}
},
),
);
}

1
packages/neon/neon/lib/widgets.dart

@ -4,4 +4,5 @@ export 'package:neon/src/widgets/image.dart';
export 'package:neon/src/widgets/linear_progress_indicator.dart';
export 'package:neon/src/widgets/list_view.dart';
export 'package:neon/src/widgets/relative_time.dart';
export 'package:neon/src/widgets/rich_object.dart';
export 'package:neon/src/widgets/server_icon.dart';

1
packages/neon/neon/pubspec.yaml

@ -22,6 +22,7 @@ dependencies:
sdk: flutter
flutter_material_design_icons: ^1.0.0
flutter_native_splash: ^2.0.0
flutter_parsed_text: ^2.0.0
flutter_svg: ^2.0.0
flutter_zxing: ^1.0.0
go_router: ^12.0.0

Loading…
Cancel
Save