Skip to content

Commit d3619a1

Browse files
authored
Linting (#88)
* added lints for root file. * sorted pubspec dependencies * adding editor config and 300 line length. * updated no push to use new linting rules
1 parent b6f8c42 commit d3619a1

File tree

9 files changed

+91
-82
lines changed

9 files changed

+91
-82
lines changed

example-no-push/lib/main.dart

Lines changed: 76 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
1-
import 'dart:io';
2-
3-
import 'package:flutter/material.dart';
41
import 'dart:async';
5-
import 'dart:math';
62
import 'dart:convert';
3+
import 'dart:io';
4+
import 'dart:math';
75

8-
import 'package:countly_flutter_np/countly_flutter.dart';
6+
// ignore: depend_on_referenced_packages
97
import 'package:countly_flutter_np/countly_config.dart';
10-
8+
// ignore: depend_on_referenced_packages
9+
import 'package:countly_flutter_np/countly_flutter.dart';
10+
import 'package:flutter/material.dart';
1111

1212
final navigatorKey = GlobalKey<NavigatorState>();
13+
1314
/// This or a similar call needs to added to catch and report Dart Errors to Countly,
14-
/// You need to run app inside a Zone
15+
/// You need to run the app inside a Zone
1516
/// and provide the [Countly.recordDartError] callback for [onError()]
1617
void main() {
1718
runZonedGuarded<Future<void>>(() async {
18-
runApp(MaterialApp(
19-
home: MyApp(),
20-
navigatorKey: navigatorKey, // Setting a global key for navigator
21-
),);
19+
runApp(
20+
MaterialApp(
21+
home: const MyApp(),
22+
navigatorKey: navigatorKey, // Setting a global key for navigator
23+
),
24+
);
2225
}, Countly.recordDartError);
2326
}
2427

2528
class MyApp extends StatefulWidget {
29+
const MyApp({Key? key}) : super(key: key);
30+
2631
@override
27-
_MyAppState createState() => _MyAppState();
32+
State<MyApp> createState() => _MyAppState();
2833
}
2934

3035
class _MyAppState extends State<MyApp> {
@@ -44,7 +49,7 @@ class _MyAppState extends State<MyApp> {
4449
Countly.isInitialized().then((bool isInitialized) {
4550
if (!isInitialized) {
4651
Countly.pushTokenType(Countly.messagingMode['TEST']!); // Set messaging mode for push notifications
47-
52+
4853
var crashSegment = {'Key': 'Value'};
4954
var userProperties = {'customProperty': 'custom Value', 'username': 'USER_NAME', 'email': 'USER_EMAIL'};
5055

@@ -117,7 +122,7 @@ class _MyAppState extends State<MyApp> {
117122
static String SERVER_URL = 'https://master.count.ly';
118123

119124
// ignore: non_constant_identifier_names
120-
static String APP_KEY = '58594c9a3f461ebc000761a68c2146659ef75ea0';
125+
static String APP_KEY = 'YOUR_API_KEY';
121126

122127
void enableTemporaryIdMode() {
123128
Countly.changeDeviceId(Countly.deviceIDType['TemporaryDeviceID']!, false);
@@ -126,8 +131,8 @@ class _MyAppState extends State<MyApp> {
126131
bool isManualSession() {
127132
//
128133
if (!_enableManualSession) {
129-
final snackBar = SnackBar(
130-
content: const Text("Set '_enableManualSession = true' in 'main.dart' to test Manual Session Handling"),
134+
const snackBar = SnackBar(
135+
content: Text("Set '_enableManualSession = true' in 'main.dart' to test Manual Session Handling"),
131136
);
132137
_messangerKey.currentState!.showSnackBar(snackBar);
133138
}
@@ -184,21 +189,21 @@ class _MyAppState extends State<MyApp> {
184189

185190
void endEventBasic() {
186191
Countly.startEvent('Timed Event');
187-
Timer(Duration(seconds: 5), () {
192+
Timer(const Duration(seconds: 5), () {
188193
Countly.endEvent({'key': 'Timed Event'});
189194
});
190195
}
191196

192197
void endEventWithSum() {
193198
Countly.startEvent('Timed Event With Sum');
194-
Timer(Duration(seconds: 5), () {
199+
Timer(const Duration(seconds: 5), () {
195200
Countly.endEvent({'key': 'Timed Event With Sum', 'sum': '0.99'});
196201
});
197202
}
198203

199204
void endEventWithSegment() {
200205
Countly.startEvent('Timed Event With Segment');
201-
Timer(Duration(seconds: 5), () {
206+
Timer(const Duration(seconds: 5), () {
202207
var event = {
203208
'key': 'Timed Event With Segment',
204209
'count': 1,
@@ -210,7 +215,7 @@ class _MyAppState extends State<MyApp> {
210215

211216
void endEventWithSumSegment() {
212217
Countly.startEvent('Timed Event With Segment, Sum and Count');
213-
Timer(Duration(seconds: 5), () {
218+
Timer(const Duration(seconds: 5), () {
214219
var event = {'key': 'Timed Event With Segment, Sum and Count', 'count': 1, 'sum': '0.99'};
215220
event['segmentation'] = {'Country': 'Turkey', 'Age': '28'};
216221
Countly.endEvent(event);
@@ -404,16 +409,16 @@ class _MyAppState extends State<MyApp> {
404409
Countly.askForNotificationPermission();
405410
}
406411

407-
void _showDialog(String alterText) {
412+
void _showDialog(String alertText) {
408413
showDialog(
409414
context: navigatorKey.currentContext!,
410415
builder: (BuildContext context) {
411416
return AlertDialog(
412-
title: Text('Alert!!'),
413-
content: Text(alterText),
417+
title: const Text('Alert!!'),
418+
content: Text(alertText),
414419
actions: <Widget>[
415420
ElevatedButton(
416-
child: Text('OK'),
421+
child: const Text('OK'),
417422
onPressed: () {
418423
Navigator.of(navigatorKey.currentContext!).pop();
419424
},
@@ -433,6 +438,7 @@ class _MyAppState extends State<MyApp> {
433438
});
434439
});
435440
}
441+
436442
void eventForGoal_1() {
437443
var event = {'key': 'eventForGoal_1', 'count': 1};
438444
Countly.recordEvent(event);
@@ -497,7 +503,7 @@ class _MyAppState extends State<MyApp> {
497503
});
498504
}
499505

500-
void getDeviceIDType() async {
506+
Future<void> getDeviceIDType() async {
501507
DeviceIdType? deviceIdType = await Countly.getDeviceIDType();
502508
if (deviceIdType != null) {
503509
setState(() {
@@ -516,7 +522,7 @@ class _MyAppState extends State<MyApp> {
516522

517523
void addCrashLog() {
518524
Countly.addCrashLog('User Performed Step A');
519-
Timer(Duration(seconds: 5), () {
525+
Timer(const Duration(seconds: 5), () {
520526
Countly.logException('one.js \n two.js \n three.js', true, {'_facebook_version': '0.0.1'});
521527
});
522528
}
@@ -587,7 +593,7 @@ class _MyAppState extends State<MyApp> {
587593
});
588594
}
589595

590-
void showFeedbackWidget() async {
596+
Future<void> showFeedbackWidget() async {
591597
FeedbackWidgetsResponse feedbackWidgetsResponse = await Countly.getAvailableFeedbackWidgets();
592598
List<CountlyPresentableFeedback> widgets = feedbackWidgetsResponse.presentableFeedback;
593599
String? error = feedbackWidgetsResponse.error;
@@ -598,14 +604,14 @@ class _MyAppState extends State<MyApp> {
598604

599605
if (widgets.isNotEmpty) {
600606
await Countly.presentFeedbackWidget(widgets.first, 'Close', widgetShown: () {
601-
print('showFeedbackWidget widgetShown');
607+
print('showFeedbackWidget widget shown');
602608
}, widgetClosed: () {
603-
print('showFeedbackWidget widgetClosed');
609+
print('showFeedbackWidget widget closed');
604610
});
605611
}
606612
}
607613

608-
void showSurvey() async {
614+
Future<void> showSurvey() async {
609615
FeedbackWidgetsResponse feedbackWidgetsResponse = await Countly.getAvailableFeedbackWidgets();
610616
List<CountlyPresentableFeedback> widgets = feedbackWidgetsResponse.presentableFeedback;
611617
String? error = feedbackWidgetsResponse.error;
@@ -622,7 +628,7 @@ class _MyAppState extends State<MyApp> {
622628
}
623629
}
624630

625-
void showNPS() async {
631+
Future<void> showNPS() async {
626632
FeedbackWidgetsResponse feedbackWidgetsResponse = await Countly.getAvailableFeedbackWidgets();
627633
List<CountlyPresentableFeedback> widgets = feedbackWidgetsResponse.presentableFeedback;
628634
String? error = feedbackWidgetsResponse.error;
@@ -634,16 +640,16 @@ class _MyAppState extends State<MyApp> {
634640
for (CountlyPresentableFeedback widget in widgets) {
635641
if (widget.type == 'nps') {
636642
await Countly.presentFeedbackWidget(widget, 'Close', widgetShown: () {
637-
print('NPS widgetShown');
643+
print('NPS widget shown');
638644
}, widgetClosed: () {
639-
print('NPS widgetClosed');
645+
print('NPS widget closed');
640646
});
641647
break;
642648
}
643649
}
644650
}
645651

646-
void reportSurveyManually() async {
652+
Future<void> reportSurveyManually() async {
647653
FeedbackWidgetsResponse feedbackWidgetsResponse = await Countly.getAvailableFeedbackWidgets();
648654
List<CountlyPresentableFeedback> widgets = feedbackWidgetsResponse.presentableFeedback;
649655
String? error = feedbackWidgetsResponse.error;
@@ -659,11 +665,11 @@ class _MyAppState extends State<MyApp> {
659665
}
660666
}
661667
if (chosenWidget != null) {
662-
reportSurvey(chosenWidget);
668+
unawaited(reportSurvey(chosenWidget));
663669
}
664670
}
665671

666-
void reportSurvey(CountlyPresentableFeedback chosenWidget) async {
672+
Future<void> reportSurvey(CountlyPresentableFeedback chosenWidget) async {
667673
List result = await Countly.getFeedbackWidgetData(chosenWidget);
668674
String? error = result[1];
669675
if (error == null) {
@@ -679,7 +685,7 @@ class _MyAppState extends State<MyApp> {
679685
Map<dynamic, dynamic> question = questions[a];
680686
String wType = question['type'];
681687
String questionId = question['id'];
682-
String answerKey = 'answ-' + questionId;
688+
String answerKey = 'answ-$questionId';
683689
switch (wType) {
684690
//multiple answer question
685691
case 'multi':
@@ -718,7 +724,7 @@ class _MyAppState extends State<MyApp> {
718724
}
719725
}
720726

721-
void reportNPSManually() async {
727+
Future<void> reportNPSManually() async {
722728
FeedbackWidgetsResponse feedbackWidgetsResponse = await Countly.getAvailableFeedbackWidgets();
723729
List<CountlyPresentableFeedback> widgets = feedbackWidgetsResponse.presentableFeedback;
724730
String? error = feedbackWidgetsResponse.error;
@@ -808,7 +814,7 @@ class _MyAppState extends State<MyApp> {
808814
child: SingleChildScrollView(
809815
child: Column(
810816
children: <Widget>[
811-
Text(_deviceIdType, style: TextStyle(color: Colors.red), textAlign: TextAlign.center),
817+
Text(_deviceIdType, style: const TextStyle(color: Colors.red), textAlign: TextAlign.center),
812818
MyButton(text: 'Get Device Id Type', color: 'green', onPressed: getDeviceIDType),
813819
MyButton(text: 'Begin Session', color: 'green', onPressed: beginSession),
814820
MyButton(text: 'Update Session', color: 'green', onPressed: updateSession),
@@ -860,12 +866,10 @@ class _MyAppState extends State<MyApp> {
860866
MyButton(text: 'Remove Consent Push', color: 'blue', onPressed: removeConsentpush),
861867
MyButton(text: 'Remove Consent starRating', color: 'blue', onPressed: removeConsentstarRating),
862868
MyButton(text: 'Remove Consent Performance', color: 'blue', onPressed: removeConsentAPM),
863-
864-
Text("Section for A/B testing:", style: TextStyle(color: Colors.green), textAlign: TextAlign.center),
869+
const Text('Section for A/B testing:', style: TextStyle(color: Colors.green), textAlign: TextAlign.center),
865870
MyButton(text: 'Get AB testing values', color: 'green', onPressed: getABTestingValues),
866871
MyButton(text: 'Record event for goal #1', color: 'green', onPressed: eventForGoal_1),
867872
MyButton(text: 'Record event for goal #2', color: 'green', onPressed: eventForGoal_2),
868-
869873
MyButton(text: 'Countly.remoteConfigUpdate', color: 'purple', onPressed: remoteConfigUpdate),
870874
MyButton(text: 'Countly.updateRemoteConfigForKeysOnly', color: 'purple', onPressed: updateRemoteConfigForKeysOnly),
871875
MyButton(text: 'Countly.updateRemoteConfigExceptKeys', color: 'purple', onPressed: updateRemoteConfigExceptKeys),
@@ -890,7 +894,7 @@ class _MyAppState extends State<MyApp> {
890894
MyButton(text: 'Open feedback modal', color: 'orange', onPressed: presentRatingWidget),
891895
TextField(
892896
controller: ratingIdController,
893-
decoration: InputDecoration(
897+
decoration: const InputDecoration(
894898
border: OutlineInputBorder(),
895899
hintText: 'Enter a Rating ID',
896900
),
@@ -914,20 +918,20 @@ class _MyAppState extends State<MyApp> {
914918
}
915919

916920
Map<String, Map<String, Color>> theColor = {
917-
'default': {'button': Color(0xffe0e0e0), 'text': Color(0xff000000)},
918-
'red': {'button': Color(0xffdb2828), 'text': Color(0xff000000)},
919-
'green': {'button': Colors.green, 'text': Color(0xffffffff)},
920-
'teal': {'button': Color(0xff00b5ad), 'text': Color(0xff000000)},
921-
'blue': {'button': Color(0xff00b5ad), 'text': Color(0xff000000)},
922-
'primary': {'button': Color(0xff54c8ff), 'text': Color(0xff000000)},
923-
'grey': {'button': Color(0xff767676), 'text': Color(0xff000000)},
924-
'brown': {'button': Color(0xffa5673f), 'text': Color(0xff000000)},
925-
'purple': {'button': Color(0xffa333c8), 'text': Color(0xff000000)},
926-
'violet': {'button': Color(0xff6435c9), 'text': Color(0xff000000)},
927-
'yellow': {'button': Color(0xfffbbd08), 'text': Color(0xffffffff)},
928-
'black': {'button': Color(0xff1b1c1d), 'text': Color(0xffffffff)},
929-
'olive': {'button': Color(0xffd9e778), 'text': Color(0xff000000)},
930-
'orange': {'button': Color(0xffff851b), 'text': Color(0xff000000)}
921+
'default': {'button': const Color(0xffe0e0e0), 'text': const Color(0xff000000)},
922+
'red': {'button': const Color(0xffdb2828), 'text': const Color(0xff000000)},
923+
'green': {'button': Colors.green, 'text': const Color(0xffffffff)},
924+
'teal': {'button': const Color(0xff00b5ad), 'text': const Color(0xff000000)},
925+
'blue': {'button': const Color(0xff00b5ad), 'text': const Color(0xff000000)},
926+
'primary': {'button': const Color(0xff54c8ff), 'text': const Color(0xff000000)},
927+
'grey': {'button': const Color(0xff767676), 'text': const Color(0xff000000)},
928+
'brown': {'button': const Color(0xffa5673f), 'text': const Color(0xff000000)},
929+
'purple': {'button': const Color(0xffa333c8), 'text': const Color(0xff000000)},
930+
'violet': {'button': const Color(0xff6435c9), 'text': const Color(0xff000000)},
931+
'yellow': {'button': const Color(0xfffbbd08), 'text': const Color(0xffffffff)},
932+
'black': {'button': const Color(0xff1b1c1d), 'text': const Color(0xffffffff)},
933+
'olive': {'button': const Color(0xffd9e778), 'text': const Color(0xff000000)},
934+
'orange': {'button': const Color(0xffff851b), 'text': const Color(0xff000000)}
931935
};
932936

933937
Map<String, Color>? getColor(color) {
@@ -961,25 +965,28 @@ Map<String, Color>? getColor(color) {
961965
}
962966

963967
class MyButton extends StatelessWidget {
964-
String? _text;
965-
Color? _button;
966-
Color? _textC;
967-
void Function()? _onPressed;
968-
969-
MyButton({String? color, String? text, void Function()? onPressed}) {
970-
_text = text!;
971-
968+
final String _text;
969+
late final Color? _button;
970+
late final Color? _textC;
971+
final void Function()? _onPressed;
972+
973+
MyButton({
974+
required String text,
975+
String? color,
976+
void Function()? onPressed,
977+
Key? key,
978+
}) : _text = text,
979+
_onPressed = onPressed,
980+
super(key: key) {
972981
Map<String, Color>? tColor;
973982
tColor = getColor(color);
974-
tColor = tColor ??= theColor['default'];
983+
tColor ??= theColor['default'];
975984
_button = tColor?['button'];
976985
_textC = tColor?['text'];
977-
978-
_onPressed = onPressed;
979986
}
980987

981988
@override
982989
Widget build(BuildContext context) {
983-
return ElevatedButton(style: ElevatedButton.styleFrom(primary: _button, padding: EdgeInsets.all(10.0), minimumSize: Size(double.infinity, 36)), onPressed: _onPressed, child: Text(_text!, style: TextStyle(color: _textC), textAlign: TextAlign.center));
990+
return ElevatedButton(style: ElevatedButton.styleFrom(backgroundColor: _button, padding: const EdgeInsets.all(10.0), minimumSize: const Size(double.infinity, 36)), onPressed: _onPressed, child: Text(_text, style: TextStyle(color: _textC), textAlign: TextAlign.center));
984991
}
985992
}

example/ios/Flutter/AppFrameworkInfo.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
<key>CFBundleVersion</key>
2222
<string>1.0</string>
2323
<key>MinimumOSVersion</key>
24-
<string>8.0</string>
24+
<string>11.0</string>
2525
</dict>
2626
</plist>

example/ios/Flutter/Flutter.podspec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
Pod::Spec.new do |s|
77
s.name = 'Flutter'
88
s.version = '1.0.0'
9-
s.summary = 'High-performance, high-fidelity mobile apps.'
10-
s.homepage = 'https://flutter.io'
11-
s.license = { :type => 'MIT' }
9+
s.summary = 'A UI toolkit for beautiful and fast apps.'
10+
s.homepage = 'https://flutter.dev'
11+
s.license = { :type => 'BSD' }
1212
s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' }
1313
s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s }
14-
s.ios.deployment_target = '10.0'
14+
s.ios.deployment_target = '11.0'
1515
# Framework linking is handled by Flutter tooling, not CocoaPods.
1616
# Add a placeholder to satisfy `s.dependency 'Flutter'` plugin podspecs.
1717
s.vendored_frameworks = 'path/to/nothing'

example/ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Uncomment this line to define a global platform for your project
2-
# platform :ios, '9.0'
2+
# platform :ios, '11.0'
33

44
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
55
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

example/ios/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ EXTERNAL SOURCES:
1414
:path: Flutter
1515

1616
SPEC CHECKSUMS:
17-
countly_flutter: 48109a453b6f1a25cb6a47c34c2701f3a7be4d15
18-
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
17+
countly_flutter: 5f6ce066d705a3d7de3728dfb0ea5626065641ee
18+
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
1919

20-
PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c
20+
PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3
2121

2222
COCOAPODS: 1.11.3

0 commit comments

Comments
 (0)