-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathmain.dart
192 lines (177 loc) Β· 5.57 KB
/
main.dart
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import 'package:flutter/material.dart';
import 'package:wiredash/wiredash.dart';
void main() {
runApp(WiredashExampleApp());
}
/// The first widget put into `runApp` should be stateful to make hot reload
/// work
class WiredashExampleApp extends StatefulWidget {
WiredashExampleApp({super.key});
@override
_WiredashExampleAppState createState() => _WiredashExampleAppState();
}
class _WiredashExampleAppState extends State<WiredashExampleApp> {
@override
Widget build(BuildContext context) {
return Wiredash(
projectId: "Project ID from console.wiredash.io",
secret: "API Key from console.wiredash.io",
psOptions: PsOptions(
collectMetaData: (metaData) async =>
metaData..userEmail = 'dash@wiredash.io',
// frequency: Duration(days: 90), // default
// initialDelay: Duration(days: 7), // default
// initialDelay: Duration.zero, // disable initial delay
// minimumAppStarts: 3, // default
// minimumAppStarts: 0, // disable minimum app starts
),
feedbackOptions: WiredashFeedbackOptions(
collectMetaData: (metaData) => metaData
..userEmail = 'dash@flutter.dev'
..userId = '007',
),
theme: WiredashThemeData.fromColor(
primaryColor: Colors.tealAccent,
brightness: Brightness.dark,
).copyWith(
appHandleBackgroundColor: Color(0xFF3A3A3A),
),
child: MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.teal,
brightness: Brightness.dark,
),
home: _HomePage(),
),
);
}
}
class _HomePage extends StatefulWidget {
_HomePage();
@override
State<_HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<_HomePage> {
@override
void initState() {
super.initState();
// Simple method to automatically show the promoter score survey on app start
Future.delayed(Duration(seconds: 5), () {
if (!mounted) return;
// Trigger this at significant point in your application to probably show
// the Promoter Score survey.
// Use [options] to adjust how often the survey is shown.
Wiredash.of(context).showPromoterSurvey(
options: PsOptions(
// minimum time between two surveys
frequency: Duration(days: 90),
// delay before the first survey is available
initialDelay: Duration(days: 7),
// minimum number of app starts before the survey will be shown
minimumAppStarts: 3,
),
// for testing, add force the promoter score survey to appear
force: true,
);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Wiredash Demo'),
),
body: ListView.builder(
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text('Sample Item #$index'),
subtitle: Text('Tap me to open a new page'),
onTap: () => _openDetailsPage(context, index),
);
},
),
floatingActionButton: FloatingActionButton(
onPressed: () {
// force: true is only used for testing
Wiredash.of(context).showPromoterSurvey(force: true);
// Always prefer delegating the decision to show the promoter score
// to Wiredash so you don't annoy your users.
// Wiredash.of(context).showPromoterSurvey();
},
child: Icon(Icons.feedback_outlined),
),
);
}
void _openDetailsPage(BuildContext context, int which) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return _DetailsPage(index: which);
},
),
);
}
}
class _DetailsPage extends StatelessWidget {
_DetailsPage({
required this.index,
});
final int index;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Details Page #$index'),
actions: [
TextButton(
onPressed: () {
Wiredash.of(context).show();
},
child: Text(
"Send feedback",
style: TextStyle(
color: Theme.of(context).primaryIconTheme.color,
),
),
),
],
),
body: Center(
child: Padding(
padding: EdgeInsets.all(16),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Details page #$index',
style: Theme.of(context).textTheme.titleLarge,
),
SizedBox(height: 32),
Text('Try navigating here in feedback mode.'),
ConstrainedBox(
constraints: BoxConstraints(maxWidth: 400),
child: TextField(
textAlign: TextAlign.center,
decoration: InputDecoration(
hintText: 'You can even write text in capture mode',
),
),
),
SizedBox(height: 32),
Text('Secret data can be hidden with the Confidential Widget'),
SizedBox(height: 16),
Confidential(
// mode: ConfidentialMode.invisible,
child: Text(
'Secret: "wiredash rocks!"',
style: TextStyle(fontWeight: FontWeight.w200, fontSize: 20),
),
),
],
),
),
),
);
}
}