Skip to content

Commit cda5f98

Browse files
committed
chore: clean code
1 parent a8057bb commit cda5f98

File tree

26 files changed

+423
-396
lines changed

26 files changed

+423
-396
lines changed

lib/imports.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export 'package:permission_handler/permission_handler.dart' show Permission;
3434
export 'package:file_picker/file_picker.dart' show PlatformFile;
3535
export 'package:flutter_inappwebview/flutter_inappwebview.dart'
3636
show CookieManager, WebUri, HTTPCookieSameSitePolicy;
37+
export 'package:url_launcher/url_launcher.dart';
3738

3839
export 'dart:io' show File, Platform;
3940
export 'dart:async';

lib/l10n/app_en.arb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"contacts_empty_description": "Start adding new contacts by clicking on the button below",
8282
"contacts_add": "Add contact",
8383
"settings": "Settings",
84+
"settings_notification": "Notification",
8485
"login_title": "Log in to your account",
8586
"login_description": "You are connected to {base_url}.",
8687
"@login_description": {
@@ -233,7 +234,8 @@
233234
"notification_empty_description": "Once you start receiving notifications, they'll appear here.",
234235
"notification_no_more": "All notifications loaded",
235236
"notification_mark_all_read": "Mark all as read",
236-
"notification_push": "Push Notifications",
237+
"notification_type": "Notification type",
238+
"notification_push": "Push Notification",
237239
"notification_create_push": "A new conversation is created",
238240
"notification_assignee_push": "A conversation is assigned to you",
239241
"notification_new_message_push": "You are mentioned in a conversation",

lib/layouts/default/default.dart

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,20 @@ class DefaultLayoutController extends GetxController
3333
}
3434
}
3535

36-
class DefaultLayout extends GetView<DefaultLayoutController> {
36+
class DefaultLayout extends StatelessWidget {
3737
final theme = Get.find<ThemeService>();
38+
final controller = Get.put(DefaultLayoutController());
3839
final conversations = Get.find<ConversationsController>();
3940
final notifications = Get.find<NotificationsController>();
4041

4142
DefaultLayout({super.key});
4243

4344
@override
4445
Widget build(BuildContext context) {
45-
return GetBuilder(
46-
init: DefaultLayoutController(),
47-
builder: (_) {
48-
if (GetPlatform.isDesktop) {
49-
return buildDesktop(context);
50-
}
51-
return buildMobile(context);
52-
},
53-
);
46+
if (GetPlatform.isDesktop) {
47+
return buildDesktop(context);
48+
}
49+
return buildMobile(context);
5450
}
5551

5652
Widget buildMobile(BuildContext context) {

lib/screens/agents/controllers/index.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class AgentsController extends GetxController {
55
final _logger = Logger();
66
final _api = Get.find<ApiService>();
77
final _auth = Get.find<AuthService>();
8+
89
final items = RxList<UserInfo>();
910

1011
@override

lib/screens/agents/views/index.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import '/imports.dart';
22

3-
class AgentsView extends GetView<AgentsController> {
3+
class AgentsView extends StatelessWidget {
44
final auth = Get.find<AuthService>();
55
final realtime = Get.find<RealtimeService>();
6-
late final AgentsController c;
76

8-
AgentsView({super.key}) : c = Get.put(AgentsController());
7+
final AgentsController controller;
8+
AgentsView({super.key}) : controller = Get.put(AgentsController());
99

1010
@override
1111
Widget build(BuildContext context) {
@@ -30,7 +30,7 @@ class AgentsView extends GetView<AgentsController> {
3030
),
3131
),
3232
Obx(() {
33-
final items = c.items.value;
33+
final items = controller.items.value;
3434

3535
return SliverList(
3636
delegate: SliverChildBuilderDelegate(

lib/screens/audit_logs/views/index.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import '../controllers/index.dart';
22
import '/imports.dart';
33

4-
class AuditLogsView extends GetView<AuditLogsController> {
5-
late final AuditLogsController c;
6-
AuditLogsView({super.key}) : c = Get.put(AuditLogsController());
4+
class AuditLogsView extends StatelessWidget {
5+
final AuditLogsController controller;
6+
AuditLogsView({super.key}) : controller = Get.put(AuditLogsController());
77

88
@override
99
Widget build(BuildContext context) {

lib/screens/browser/views/index.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import '/imports.dart';
44

55
class BrowserView extends StatelessWidget {
66
final BrowserController controller;
7-
87
BrowserView({
98
super.key,
109
required String url,
11-
}) : controller = Get.put(BrowserController(initialUrl: url), tag: url);
10+
}) : controller = Get.put(
11+
BrowserController(initialUrl: url),
12+
tag: url,
13+
);
1214

1315
@override
1416
Widget build(BuildContext context) {

lib/screens/canned_responses/views/index.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import '/imports.dart';
22

33
class CannedResponsesView extends StatelessWidget {
4-
final CannedResponsesController c;
54
final auth = Get.find<AuthService>();
65

7-
CannedResponsesView({super.key}) : c = Get.find<CannedResponsesController>();
6+
final CannedResponsesController controller;
7+
CannedResponsesView({super.key})
8+
: controller = Get.find<CannedResponsesController>();
89

910
@override
1011
Widget build(BuildContext context) {
@@ -29,7 +30,7 @@ class CannedResponsesView extends StatelessWidget {
2930
),
3031
),
3132
Obx(() {
32-
final items = c.items.value;
33+
final items = controller.items.value;
3334

3435
return SliverList(
3536
delegate: SliverChildBuilderDelegate(

lib/screens/contacts/controllers/detail.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ class ContactDetailController extends GetxController {
66
final _api = Get.find<ApiService>();
77
final _realtime = Get.find<RealtimeService>();
88

9-
final int id;
9+
final int contact_id;
1010

1111
ContactDetailController(
12-
this.id, {
12+
this.contact_id, {
1313
ContactInfo? initial,
1414
}) : info = Rxn<ContactInfo>(initial);
1515

@@ -41,7 +41,7 @@ class ContactDetailController extends GetxController {
4141
Future<void> getContact() async {
4242
try {
4343
final result = await _api.getContact(
44-
contact_id: id,
44+
contact_id: contact_id,
4545
onCacheHit: (data) => info.value = data,
4646
);
4747
final data = result.getOrThrow();
@@ -58,7 +58,7 @@ class ContactDetailController extends GetxController {
5858
Future<void> getLabels() async {
5959
try {
6060
final result = await _api.getContactLabels(
61-
contact_id: id,
61+
contact_id: contact_id,
6262
onCacheHit: (data) => labels.value = data,
6363
);
6464
final data = result.getOrThrow();
@@ -75,7 +75,7 @@ class ContactDetailController extends GetxController {
7575
Future<void> getConversations() async {
7676
try {
7777
final result = await _api.getContactConversations(
78-
contact_id: id,
78+
contact_id: contact_id,
7979
onCacheHit: (data) => conversations.value = data,
8080
);
8181
final data = result.getOrThrow();
@@ -94,7 +94,7 @@ class ContactDetailController extends GetxController {
9494
if (items.isEmpty) return;
9595
labels.value = items.map((e) => e.title).toList();
9696
await _api.updateContactLabels(
97-
contact_id: id,
97+
contact_id: contact_id,
9898
labels: items.map((e) => e.title).toList(),
9999
);
100100
}

lib/screens/contacts/views/detail.dart

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1-
import 'package:url_launcher/url_launcher.dart';
2-
31
import '../../conversations/widgets/item.dart';
42
import '/screens/contacts/controllers/detail.dart';
53
import '/imports.dart';
64

75
class ContactDetailView extends StatelessWidget {
86
final labels = Get.find<LabelsController>();
97
final realtime = Get.find<RealtimeService>();
10-
final attributeService = Get.find<CustomAttributesController>();
11-
12-
final ContactDetailController c;
13-
final int id;
8+
final customAttributes = Get.find<CustomAttributesController>();
149

10+
final ContactDetailController controller;
1511
ContactDetailView({
1612
super.key,
17-
required this.id,
13+
required int id,
1814
ContactInfo? initial,
19-
}) : c = Get.put(ContactDetailController(id, initial: initial), tag: '$id');
15+
}) : controller = Get.putOrFind(
16+
() => ContactDetailController(id, initial: initial),
17+
tag: '$id',
18+
);
2019

2120
@override
2221
Widget build(BuildContext context) {
2322
return Obx(() {
24-
final info = c.info.value;
23+
final info = controller.info.value;
2524
if (info == null) {
2625
return Scaffold(
2726
appBar: AppBar(),
@@ -89,7 +88,7 @@ class ContactDetailView extends StatelessWidget {
8988
}
9089

9190
Widget buildActions() {
92-
final info = c.info.value;
91+
final info = controller.info.value;
9392

9493
return Padding(
9594
padding: const EdgeInsets.all(4.0),
@@ -132,18 +131,15 @@ class ContactDetailView extends StatelessWidget {
132131
}) {
133132
return FilledButton.tonal(
134133
onPressed: onPressed,
135-
child: Column(
136-
children: [
137-
Padding(
138-
padding:
139-
const EdgeInsets.only(left: 8, right: 8, top: 8, bottom: 4),
140-
child: Icon(iconData),
141-
),
142-
Padding(
143-
padding: const EdgeInsets.only(left: 8, right: 8, bottom: 8),
144-
child: Text(label),
145-
),
146-
],
134+
child: Padding(
135+
padding: const EdgeInsets.only(top: 8, bottom: 8),
136+
child: Column(
137+
spacing: 4,
138+
children: [
139+
Icon(iconData),
140+
Text(label),
141+
],
142+
),
147143
),
148144
);
149145
}
@@ -189,7 +185,7 @@ class ContactDetailView extends StatelessWidget {
189185

190186
Widget buildLabels(BuildContext context) {
191187
return Obx(() {
192-
final items = c.labels.value;
188+
final items = controller.labels.value;
193189

194190
return Column(
195191
crossAxisAlignment: CrossAxisAlignment.start,
@@ -229,7 +225,7 @@ class ContactDetailView extends StatelessWidget {
229225
Chip(
230226
label: Text(t.modify),
231227
deleteIcon: Icon(Icons.edit),
232-
onDeleted: c.modifyLabels,
228+
onDeleted: controller.modifyLabels,
233229
)
234230
],
235231
),
@@ -241,7 +237,7 @@ class ContactDetailView extends StatelessWidget {
241237

242238
Widget buildConversations(BuildContext context) {
243239
return Obx(() {
244-
final items = c.conversations.value;
240+
final items = controller.conversations.value;
245241
if (items.isEmpty) return Container();
246242

247243
return Column(
@@ -310,7 +306,7 @@ class ContactDetailView extends StatelessWidget {
310306
buildLabel(t.custom_attributes),
311307
Card(
312308
child: Obx(() {
313-
final attributes = attributeService.items.value;
309+
final attributes = customAttributes.items.value;
314310

315311
return ListView.builder(
316312
padding: EdgeInsets.zero,

0 commit comments

Comments
 (0)