Skip to content

Commit b537cec

Browse files
Fix warnings (#1367)
* fix warnings * fixed warnings example project
1 parent 817ae00 commit b537cec

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

permission_handler_html/example/lib/main.dart

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,19 @@ final MaterialColor themeMaterialColor =
1717

1818
/// A Flutter application demonstrating the functionality of this plugin
1919
class PermissionHandlerWidget extends StatefulWidget {
20+
/// Creates a [PermissionHandlerWidget].
21+
const PermissionHandlerWidget({
22+
super.key,
23+
});
24+
2025
/// Create a page containing the functionality of this plugin
2126
static ExamplePage createPage() {
2227
return ExamplePage(
23-
Icons.location_on, (context) => PermissionHandlerWidget());
28+
Icons.location_on, (context) => const PermissionHandlerWidget());
2429
}
2530

2631
@override
27-
_PermissionHandlerWidgetState createState() =>
32+
State<PermissionHandlerWidget> createState() =>
2833
_PermissionHandlerWidgetState();
2934
}
3035

@@ -52,18 +57,20 @@ class _PermissionHandlerWidgetState extends State<PermissionHandlerWidget> {
5257
/// Permission widget containing information about the passed [Permission]
5358
class PermissionWidget extends StatefulWidget {
5459
/// Constructs a [PermissionWidget] for the supplied [Permission]
55-
const PermissionWidget(this._permission);
60+
const PermissionWidget(
61+
this._permission, {
62+
super.key,
63+
});
5664

5765
final Permission _permission;
5866

5967
@override
60-
_PermissionState createState() => _PermissionState(_permission);
68+
State<PermissionWidget> createState() => _PermissionState();
6169
}
6270

6371
class _PermissionState extends State<PermissionWidget> {
64-
_PermissionState(this._permission);
72+
_PermissionState();
6573

66-
final Permission _permission;
6774
final PermissionHandlerPlatform _permissionHandler =
6875
PermissionHandlerPlatform.instance;
6976
PermissionStatus _permissionStatus = PermissionStatus.denied;
@@ -76,9 +83,9 @@ class _PermissionState extends State<PermissionWidget> {
7683
}
7784

7885
void _listenForPermissionStatus() async {
79-
await _permissionHandler.checkPermissionStatus(_permission).then(
86+
await _permissionHandler.checkPermissionStatus(widget._permission).then(
8087
(status) => setState(() => _permissionStatus = status),
81-
onError: (error, st) => print('$error'));
88+
onError: (error, st) => debugPrint('$error'));
8289
}
8390

8491
Color getPermissionColor() {
@@ -98,26 +105,26 @@ class _PermissionState extends State<PermissionWidget> {
98105
Widget build(BuildContext context) {
99106
return ListTile(
100107
title: Text(
101-
_permission.toString(),
108+
widget._permission.toString(),
102109
style: Theme.of(context).textTheme.bodyLarge,
103110
),
104111
subtitle: Text(
105112
_permissionStatus.toString(),
106113
style: TextStyle(color: getPermissionColor()),
107114
),
108-
trailing: (_permission is PermissionWithService)
115+
trailing: (widget._permission is PermissionWithService)
109116
? IconButton(
110117
icon: const Icon(
111118
Icons.info,
112119
color: Colors.white,
113120
),
114121
onPressed: () {
115122
checkServiceStatus(
116-
context, _permission as PermissionWithService);
123+
context, widget._permission as PermissionWithService);
117124
})
118125
: null,
119126
onTap: () {
120-
requestPermission(_permission);
127+
requestPermission(widget._permission);
121128
},
122129
);
123130
}
@@ -133,10 +140,8 @@ class _PermissionState extends State<PermissionWidget> {
133140
Future<void> requestPermission(Permission permission) async {
134141
await _permissionHandler.requestPermissions([permission]).then(
135142
(status) => setState(() {
136-
print(status);
137143
_permissionStatus = status[permission] ?? PermissionStatus.denied;
138-
print(_permissionStatus);
139144
}),
140-
onError: (error, st) => print('$error'));
145+
onError: (error, st) => debugPrint('$error'));
141146
}
142147
}

permission_handler_html/example/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ environment:
55
sdk: ">=3.0.5 <4.0.0"
66

77
dependencies:
8+
permission_handler_platform_interface: ^4.2.0
89
baseflow_plugin_template: ^2.1.2
910
flutter:
1011
sdk: flutter

permission_handler_html/lib/web_delegate.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class WebDelegate {
7575

7676
try {
7777
web.MediaStream? mediaStream = await _devices
78-
?.getUserMedia(web.MediaStreamConstraints(audio: true.toJS))
78+
.getUserMedia(web.MediaStreamConstraints(audio: true.toJS))
7979
.toDart;
8080

8181
// In browsers, calling [getUserMedia] will start the recording
@@ -85,8 +85,8 @@ class WebDelegate {
8585
// The manual stop action is then needed here for to stop the automatic
8686
// recording.
8787

88-
if (mediaStream?.active ?? false) {
89-
final audioTracks = mediaStream?.getAudioTracks().toDart ?? [];
88+
if (mediaStream.active) {
89+
final audioTracks = mediaStream.getAudioTracks().toDart;
9090
if (audioTracks.isNotEmpty) {
9191
audioTracks[0].stop();
9292
}
@@ -105,7 +105,7 @@ class WebDelegate {
105105

106106
try {
107107
web.MediaStream? mediaStream = await _devices
108-
?.getUserMedia(web.MediaStreamConstraints(video: true.toJS))
108+
.getUserMedia(web.MediaStreamConstraints(video: true.toJS))
109109
.toDart;
110110

111111
// In browsers, calling [getUserMedia] will start the recording
@@ -115,8 +115,8 @@ class WebDelegate {
115115
// The manual stop action is then needed here for to stop the automatic
116116
// recording.
117117

118-
if (mediaStream?.active ?? false) {
119-
final videoTracks = mediaStream?.getVideoTracks().toDart ?? [];
118+
if (mediaStream.active) {
119+
final videoTracks = mediaStream.getVideoTracks().toDart;
120120
if (videoTracks.isNotEmpty) {
121121
videoTracks[0].stop();
122122
}

0 commit comments

Comments
 (0)