-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.dart
More file actions
152 lines (129 loc) · 4.74 KB
/
main.dart
File metadata and controls
152 lines (129 loc) · 4.74 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:help_scout_beacon/help_scout_beacon.dart';
import 'package:help_scout_beacon/help_scout_beacon_api.g.dart';
import 'package:path_provider/path_provider.dart';
/// YOUR HELPSCOUT BEACON ID
const String yourBeaconId = "";
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _formKey = GlobalKey<FormState>();
final HelpScoutBeacon beacon = HelpScoutBeacon(
HSBeaconSettings(beaconId: yourBeaconId, debugLogging: true));
@override
Widget build(BuildContext context) {
const spacer = SizedBox(height: 16, width: 16);
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Help Scout Plugin'),
),
body: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// Enter your beacon id
const Text("BeaconId: \n$yourBeaconId"),
spacer,
// Start a beacon ui
ElevatedButton(
onPressed: () => beacon.open(),
child: const Text('Open (Default)'),
),
spacer,
ElevatedButton(
onPressed: () => beacon.open(route: HSBeaconRoute.ask),
child: const Text('Open Ask'),
),
spacer,
ElevatedButton(
onPressed: () => beacon.open(route: HSBeaconRoute.chat),
child: const Text('Open Chat'),
),
spacer,
ElevatedButton(
onPressed: () => beacon.open(route: HSBeaconRoute.docs),
child: const Text('Open Docs'),
),
spacer,
ElevatedButton(
onPressed: () =>
beacon.open(route: HSBeaconRoute.docs, parameter: 'Help'),
child: const Text('Open Docs (+search term)'),
),
spacer,
ElevatedButton(
onPressed: () => beacon.open(route: HSBeaconRoute.contactForm),
child: const Text('Open Contact Form'),
),
spacer,
ElevatedButton(
onPressed: () async {
try {
final logs = ['This is a sample logs text'];
final logsJsonString = logs.join('\n');
final directory = await getApplicationDocumentsDirectory();
final logFile = File('${directory.path}/session_logs.txt'); //Create new file
await logFile.writeAsString(logsJsonString); //Write data or logs into the file
//call prefillContactForm with subject, message and attachments
await beacon.prefillContactForm(
subject: 'Help Scout',
message: 'This is sample prefilled message',
attachments: [logFile],
);
// Now open contactForm
beacon.open(route: HSBeaconRoute.contactForm);
} on Exception catch (e) {
if (kDebugMode) {
print('open exception: $e');
}
}
},
child: const Text('Open Prefilled Contact Form'),
),
spacer,
ElevatedButton(
onPressed: () =>
beacon.open(route: HSBeaconRoute.previousMessages),
child: const Text('Open Previous Messages'),
),
const SizedBox(height: 32),
// Clear everything
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
FilledButton(
onPressed: () => beacon.identify(
beaconUser: HSBeaconUser(
email: "john.doe@example.com", name: "John Doe")),
child: const Text('Set User'),
),
const SizedBox(width: 16),
FilledButton(
onPressed: clearBeacon,
child: const Text('Clear'),
),
],
),
],
),
),
),
);
}
Future<void>? clearBeacon() async {
await beacon.clear();
}
bool isFormValid() {
return _formKey.currentState?.validate() ?? false;
}
}