Skip to content

Commit 0932982

Browse files
authored
Null safety support (#893)
* fix: added temporary & env files to .gitignore and updated example/pubspec.yaml * feat: Migrate library and example project to null-safety * Update version to 1.0.0-nullsafety.0 * fix: Update flutter-version in workflows * fix: replace mocktail with mockito * fix: Replace Future<Null> return types with Future<void>
1 parent bb82d6e commit 0932982

File tree

11 files changed

+225
-200
lines changed

11 files changed

+225
-200
lines changed

.github/workflows/android_ut.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
java-version: '12.x'
1515
- uses: subosito/flutter-action@v1
1616
with:
17-
flutter-version: '1.7.8+hotfix.4'
17+
flutter-version: '2.0.4'
1818
- run: flutter doctor
1919
- run: flutter pub get
2020
- run: sh android_test.sh

.github/workflows/flutter_ut.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
java-version: '12.x'
1515
- uses: subosito/flutter-action@v1
1616
with:
17-
flutter-version: '1.7.8+hotfix.4'
17+
flutter-version: '2.0.4'
1818
- run: flutter doctor
1919
- run: flutter pub get
2020
- run: flutter test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ build/
99
ios/.generated/
1010
packages
1111
pubspec.lock
12+
.dart_tool/
1213

1314
example/ios/Podfile.lock
1415
**/Flutter/App.framework/

example/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ ios/.generated/
88
packages
99
pubspec.lock
1010
.flutter-plugins
11+
.flutter-plugins-dependencies

example/lib/main.dart

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class MyApp extends StatelessWidget {
8484
}
8585

8686
class MyHomePage extends StatefulWidget {
87-
const MyHomePage({Key key, this.title}) : super(key: key);
87+
const MyHomePage({Key? key, required this.title}) : super(key: key);
8888

8989
final String title;
9090

@@ -97,21 +97,21 @@ class _MyHomePageState extends State<MyHomePage> {
9797
final flutterWebViewPlugin = FlutterWebviewPlugin();
9898

9999
// On destroy stream
100-
StreamSubscription _onDestroy;
100+
late StreamSubscription _onDestroy;
101101

102102
// On urlChanged stream
103-
StreamSubscription<String> _onUrlChanged;
103+
late StreamSubscription<String> _onUrlChanged;
104104

105105
// On urlChanged stream
106-
StreamSubscription<WebViewStateChanged> _onStateChanged;
106+
late StreamSubscription<WebViewStateChanged> _onStateChanged;
107107

108-
StreamSubscription<WebViewHttpError> _onHttpError;
108+
late StreamSubscription<WebViewHttpError> _onHttpError;
109109

110-
StreamSubscription<double> _onProgressChanged;
110+
late StreamSubscription<double> _onProgressChanged;
111111

112-
StreamSubscription<double> _onScrollYChanged;
112+
late StreamSubscription<double> _onScrollYChanged;
113113

114-
StreamSubscription<double> _onScrollXChanged;
114+
late StreamSubscription<double> _onScrollXChanged;
115115

116116
final _urlCtrl = TextEditingController(text: selectedUrl);
117117

@@ -135,8 +135,8 @@ class _MyHomePageState extends State<MyHomePage> {
135135
_onDestroy = flutterWebViewPlugin.onDestroy.listen((_) {
136136
if (mounted) {
137137
// Actions like show a info toast.
138-
_scaffoldKey.currentState.showSnackBar(
139-
const SnackBar(content: const Text('Webview Destroyed')));
138+
ScaffoldMessenger.of(context)
139+
.showSnackBar(const SnackBar(content: Text('Webview Destroyed')));
140140
}
141141
});
142142

@@ -226,7 +226,7 @@ class _MyHomePageState extends State<MyHomePage> {
226226
padding: const EdgeInsets.all(24.0),
227227
child: TextField(controller: _urlCtrl),
228228
),
229-
RaisedButton(
229+
ElevatedButton(
230230
onPressed: () {
231231
flutterWebViewPlugin.launch(
232232
selectedUrl,
@@ -239,19 +239,19 @@ class _MyHomePageState extends State<MyHomePage> {
239239
},
240240
child: const Text('Open Webview (rect)'),
241241
),
242-
RaisedButton(
242+
ElevatedButton(
243243
onPressed: () {
244244
flutterWebViewPlugin.launch(selectedUrl, hidden: true);
245245
},
246246
child: const Text('Open "hidden" Webview'),
247247
),
248-
RaisedButton(
248+
ElevatedButton(
249249
onPressed: () {
250250
flutterWebViewPlugin.launch(selectedUrl);
251251
},
252252
child: const Text('Open Fullscreen Webview'),
253253
),
254-
RaisedButton(
254+
ElevatedButton(
255255
onPressed: () {
256256
Navigator.of(context).pushNamed('/widget');
257257
},
@@ -261,30 +261,31 @@ class _MyHomePageState extends State<MyHomePage> {
261261
padding: const EdgeInsets.all(24.0),
262262
child: TextField(controller: _codeCtrl),
263263
),
264-
RaisedButton(
264+
ElevatedButton(
265265
onPressed: () {
266266
final future =
267267
flutterWebViewPlugin.evalJavascript(_codeCtrl.text);
268-
future.then((String result) {
268+
future.then((String? result) {
269269
setState(() {
270270
_history.add('eval: $result');
271271
});
272272
});
273273
},
274274
child: const Text('Eval some javascript'),
275275
),
276-
RaisedButton(
276+
ElevatedButton(
277277
onPressed: () {
278-
final future = flutterWebViewPlugin.evalJavascript('alert("Hello World");');
279-
future.then((String result) {
278+
final future = flutterWebViewPlugin
279+
.evalJavascript('alert("Hello World");');
280+
future.then((String? result) {
280281
setState(() {
281282
_history.add('eval: $result');
282283
});
283284
});
284285
},
285286
child: const Text('Eval javascript alert()'),
286287
),
287-
RaisedButton(
288+
ElevatedButton(
288289
onPressed: () {
289290
setState(() {
290291
_history.clear();
@@ -293,7 +294,7 @@ class _MyHomePageState extends State<MyHomePage> {
293294
},
294295
child: const Text('Close'),
295296
),
296-
RaisedButton(
297+
ElevatedButton(
297298
onPressed: () {
298299
flutterWebViewPlugin.getCookies().then((m) {
299300
setState(() {

example/pubspec.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
name: flutter_webview_plugin_example
22
description: Demonstrates how to use the flutter_webview_plugin plugin.
3+
version: 1.0.0+1
4+
publish_to: 'none'
5+
6+
environment:
7+
sdk: '>=2.12.0 <3.0.0'
38

49
dependencies:
510
flutter:

0 commit comments

Comments
 (0)