-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathinvite_individual_users.dart
More file actions
132 lines (125 loc) · 4.27 KB
/
Copy pathinvite_individual_users.dart
File metadata and controls
132 lines (125 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import 'package:acter/common/toolkit/buttons/primary_action_button.dart';
import 'package:acter/common/widgets/acter_search_widget.dart';
import 'package:acter/features/invite_members/widgets/direct_invite.dart';
import 'package:acter/features/member/providers/invite_providers.dart';
import 'package:acter/features/member/widgets/user_builder.dart';
import 'package:acter/features/member/widgets/user_search_results.dart';
import 'package:acter_flutter_sdk/acter_flutter_sdk_ffi.dart';
import 'package:flutter/material.dart';
import 'package:acter/l10n/generated/l10n.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
class InviteIndividualUsers extends ConsumerWidget {
final String roomId;
final Task? task;
final bool isFullPageMode;
const InviteIndividualUsers({
super.key,
required this.roomId,
this.isFullPageMode = true,
this.task,
});
@override
Widget build(BuildContext context, WidgetRef ref) {
return Scaffold(
appBar: isFullPageMode ? _buildAppBar(context) : null,
body: _buildBody(context, ref),
);
}
AppBar _buildAppBar(BuildContext context) {
return AppBar(
title: Text(L10n.of(context).inviteIndividualUsersTitle),
centerTitle: true,
);
}
Widget _buildBody(BuildContext context, WidgetRef ref) {
final lang = L10n.of(context);
return Center(
child: Container(
constraints: const BoxConstraints(maxWidth: 500),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (isFullPageMode)...[
const SizedBox(height: 10),
Text(
lang.inviteIndividualUsersDescription,
textAlign: TextAlign.center,
),
],
const SizedBox(height: 10),
ActerSearchWidget(
initialText: ref.read(userSearchValueProvider),
hintText: lang.searchUsernameToStartDM,
onChanged: (value) {
final notifier = ref.read(userSearchValueProvider.notifier);
notifier.update((state) => value);
},
onClear: () {
final notifier = ref.read(userSearchValueProvider.notifier);
notifier.state = null;
},
),
const SizedBox(height: 10),
_buildUserDirectInvite(ref),
Expanded(
child: UserSearchResults(
roomId: roomId,
userItemBuilder: ({
required bool isSuggestion,
required UserProfile profile,
}) {
return UserBuilder(
userId: profile.userId().toString(),
roomId: roomId,
userProfile: profile,
includeSharedRooms: isSuggestion,
task: task,
);
},
),
),
if (!isFullPageMode || task != null)...[
const SizedBox(height: 16),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: _buildActionButton(context, lang),
),
const SizedBox(height: 16),
],
],
),
),
);
}
Widget _buildActionButton(BuildContext context, L10n lang) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
ActerPrimaryActionButton(
onPressed: () {
Navigator.pop(context);
},
child: Text(lang.done, style: const TextStyle(fontSize: 16)),
),
],
);
}
Widget _buildUserDirectInvite(WidgetRef ref) {
final searchValue = ref.watch(userSearchValueProvider);
if (searchValue != null && searchValue.isNotEmpty == true) {
final cleaned = searchValue.trim();
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Column(
children: [
if (userNameRegExp.hasMatch(cleaned))
DirectInvite(roomId: roomId, userId: cleaned),
if (noAtUserNameRegExp.hasMatch(cleaned))
DirectInvite(roomId: roomId, userId: '@$cleaned'),
],
),
);
}
return const SizedBox.shrink();
}
}