Compiler error using webView in flutter: The argument type 'AutoMediaPlaybackPolicy can't be assigned to the parameter type 'AutoMediaPlaybackPolicy - flutter

I'm trying to write an app with the use of the WebView in flutter. However, i'm receiving the error described below:
compiler message:
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.22+1/lib/webview_flutter.Dart:395:37: Error: The argument type 'AutoMediaPlaybackPolicy/*1*/' can't be assigned to the parameter type 'AutoMediaPlaybackPolicy/*2*/'.
- 'AutoMediaPlaybackPolicy/*1*/' is from 'package:webview_flutter/webview_flutter.Dart' ('/C:/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.22+1/lib/webview_flutter.Dart').
- 'AutoMediaPlaybackPolicy/*2*/' is from 'package:webview_flutter/webview_flutter.dart' ('/C:/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.22+1/lib/webview_flutter.dart').
autoMediaPlaybackPolicy: widget.initialMediaPlaybackPolicy,
^
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.22+1/lib/webview_flutter.Dart:401:28: Error: The argument type 'JavascriptMode/*1*/' can't be assigned to the parameter type 'JavascriptMode/*2*/'.
- 'JavascriptMode/*1*/' is from 'package:webview_flutter/webview_flutter.Dart' ('/C:/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.22+1/lib/webview_flutter.Dart').
- 'JavascriptMode/*2*/' is from 'package:webview_flutter/webview_flutter.dart' ('/C:/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.22+1/lib/webview_flutter.dart').
javascriptMode: widget.javascriptMode,
^
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.22+1/lib/webview_flutter.Dart:426:31: Error: A value of type 'JavascriptMode/*1*/' can't be assigned to a variable of type 'JavascriptMode/*2*/'.
- 'JavascriptMode/*1*/' is from 'package:webview_flutter/webview_flutter.dart' ('/C:/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.22+1/lib/webview_flutter.dart').
- 'JavascriptMode/*2*/' is from 'package:webview_flutter/webview_flutter.Dart' ('/C:/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.22+1/lib/webview_flutter.Dart').
javascriptMode = newValue.javascriptMode;
^
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.22+1/lib/webview_flutter.Dart:439:21: Error: The argument type 'JavascriptMode/*1*/' can't be assigned to the parameter type 'JavascriptMode/*2*/'.
- 'JavascriptMode/*1*/' is from 'package:webview_flutter/webview_flutter.Dart' ('/C:/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.22+1/lib/webview_flutter.Dart').
- 'JavascriptMode/*2*/' is from 'package:webview_flutter/webview_flutter.dart' ('/C:/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.22+1/lib/webview_flutter.dart').
javascriptMode: javascriptMode,
I created a separate app only using WebView (to test my environment) and that's running correctly. I don't understand because in the first application (with error) presents the issue. If I remove all code related to WebView the compiler message still the same, i.e, the problem happens when I do the import in the package. The pubspec.yaml is identical in the two Applications.
The respective code:
import 'package:webview_flutter/webview_flutter.Dart';
class WebViewContainer extends StatefulWidget {
final url;
WebViewContainer(this.url);
#override
createState() => _WebViewContainerState(this.url);
}
class _WebViewContainerState extends State<WebViewContainer> {
var _url;
final _key = UniqueKey();
_WebViewContainerState(this._url);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Column(
children: [
Expanded(
child: WebView(
key: _key,
javascriptMode: JavascriptMode.unrestricted,
initialUrl: _url))
],
));
}
}
The piece of code where the action happens:
class CursoDeNoivos extends StatelessWidget{
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Curso de Noivos"),
centerTitle: true,
backgroundColor: Colors.deepPurple,
),
body:SingleChildScrollView(
child: Column(
children: <Widget>[
Expanded(
child: Padding(
padding: EdgeInsets.only(left: 1.0, top: 1.0, right: 1.0, bottom: 1.0),
child: Container(
height: button_height,
child: buildIconButton("Inscrições", _insc, context, Icons.add_circle_outline),
)
),
)
],
The action when the button is pressed:
Widget buildIconButton(String _text, Object _obj, BuildContext _context, IconData _icon) {
return RaisedButton.icon(
onPressed: (){
//Navigator.push(_context, MaterialPageRoute(builder: (context) => _obj));
Navigator.push(_context, MaterialPageRoute(builder: (context) => WebViewContainer('https://google.com')));
},
icon: Icon(_icon, color: Colors.white, size: 30.0,),
label: Text(_text, style: TextStyle(color: Colors.white, fontSize: 20), textAlign: TextAlign.left),
color: Colors.deepPurple,
);
}
The pubspec.yaml file:
# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.3
webview_flutter: ^0.3.3
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
assets:
- images/casados.jpg
- images/noivos.jpg
The Flutter doctor results:
C:\flutter\bin\flutter.bat doctor --verbose
[√] Flutter (Channel beta, v1.17.0, on Microsoft Windows [versão 10.0.18362.836], locale pt-BR)
• Flutter version 1.17.0 at C:\flutter
• Framework revision e6b34c2b5c (4 weeks ago), 2020-05-02 11:39:18 -0700
• Engine revision 540786dd51
• Dart version 2.8.1
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.0-rc4)
• Android SDK at C:\Users\feps\AppData\Local\Android\sdk
• Platform android-29, build-tools 30.0.0-rc4
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
• All Android licenses accepted.
[√] Android Studio (version 3.6)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 45.1.1
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
[√] VS Code, 64-bit edition (version 1.24.0)
• VS Code at C:\Program Files\Microsoft VS Code
• Flutter extension version 2.21.1
[√] Connected device (1 available)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)
• No issues found!
Process finished with exit code 0
I've got no idea about the cause of the issue...
(I'm new in Flutter or Apps development)

Related

Flutter: Debug error when import rive package

I am new. I am building my first app but there is a difficult error.
I created an animation and want to use it like a button. Tap on it and the animation starts.
I try to use rive but can not run the app when importing rive.dart
this is my code:
import 'dart:ffi';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({Key? key}) : super(key: key);
#override
State createState() => _Home();
}
class _Home extends State {
String bamboo_tube_animation = 'assets/animations/OngQue.svg';
#override
Widget build(BuildContext context) {
double device_width = MediaQuery.of(context).size.width;
double device_height = MediaQuery.of(context).size.height;
double bamboo_button_size = device_width * 0.9;
double icon_size = 60;
return Container(
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: [
RiveAnimation.asset(bamboo_tube_animation);
Container(
height: 20,
),
],
),
);
}
}
I add rive to pubspec.yaml
dependencies:
flutter:
sdk: flutter
flutter_svg: ^1.1.6
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
flare_flutter: ^3.0.2
rive: ^0.10.1
And this is debug console:
Launching lib/main.dart on iPhone 13 Pro Max in debug mode...
Xcode build done. 6.7s
Failed to build iOS app
Error output from Xcode build:
↳
2023-01-26 21:51:46.183 xcodebuild[26922:202491] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionSentinelHostApplications for extension Xcode.DebuggerFoundation.AppExtensionHosts.watchOS of plug-in com.apple.dt.IDEWatchSupportCore
2023-01-26 21:51:46.184 xcodebuild[26922:202491] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionPointIdentifierToBundleIdentifier for extension Xcode.DebuggerFoundation.AppExtensionToBundleIdentifierMap.watchOS of plug-in com.apple.dt.IDEWatchSupportCore
BUILD FAILED
Xcode's output:
↳
Writing result bundle at path:
/var/folders/3w/nscscyx1109ckdn_r__40g7m0000gn/T/flutter_tools.XO1RoC/flutter_ios_build_temp_dirvZKZ6S/temporary_xcresult_bundle
: Error: Type 'Uint8List' not found.
Future<void> decode(Uint8List bytes) {
^^^^^^^^^
: Error: 'Uint8List' isn't a type.
Future<void> decode(Uint8List bytes) {
^^^^^^^^^
Failed to package /Users/manh.do/Documents/flutter_example/angicungduoc/angicungduoc.
Command PhaseScriptExecution failed with a nonzero exit code
note: Using new build system
note: Planning
note: Build preparation complete
note: Building targets in dependency order
Result bundle written to path:
/var/folders/3w/nscscyx1109ckdn_r__40g7m0000gn/T/flutter_tools.XO1RoC/flutter_ios_build_temp_dirvZKZ6S/temporary_xcresult_bundle
Could not build the application for the simulator.
Error launching application on iPhone 13 Pro Max.
Exited
Any idea?
I just start my app, but it's hard to resolve this error

The following _CastError was thrown building Container: Null check operator used on a null value

I got this error when I run my simple flutter APP. I could not figure out why this error occurred.
Error
Null check operator used on a null value
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:star_book/src/controller/mapDataController.dart';
import 'package:star_book/src/model/app_settings.dart';
import 'package:star_book/src/model/category.dart';
import 'package:star_book/src/model/map_data.dart';
class MapInformationPage extends StatefulWidget {
late final String selectedMap;
MapInformationPage(this.selectedMap);
#override
_MapInformationPageState createState() => _MapInformationPageState();
}
class _MapInformationPageState extends State<MapInformationPage> {
final _mapController = Get.put(MapDataController());
late final MapData mapData;
late AppSettings _appSettings;
late List<Category> _favoriteIcons;
late int _favoriteIconsIndex;
#override
void initState() {
super.initState();
_appSettings = AppSettings();
_favoriteIcons = [
Category(Icons.favorite_border, Colors.black),
Category(Icons.favorite, Colors.red),
];
_favoriteIconsIndex = 0;
_mapController.selectedMapData(widget.selectedMap);
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: IconButton(
onPressed: () {
Get.back();
},
icon: Icon(Icons.arrow_back),
iconSize: 24,
),
backgroundColor: _appSettings.appBarAndNavColor,
),
body: Container(
width: _appSettings.appWidth * 0.9,
height: _appSettings.appHeight - _appSettings.appBarHeight,
child: ListView(children: [
Container(
child: GetBuilder(
builder: (_) {
return Text(
'map > star1 >' + _mapController.mapData.name.toString(),
style: TextStyle(fontSize: 20),
);
},
),
),
]),
),
);
}
}
My flutter doctor output
[√] Flutter (Channel stable, 2.2.3, on Microsoft Windows [Version 10.0.19043.1165], locale ko-KR)
• Flutter version 2.2.3 at C:\Program Files\flutter
• Framework revision f4abaa0735 (8 weeks ago), 2021-07-01 12:46:11 -0700
• Engine revision 241c87ad80
• Dart version 2.13.4
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at C:\Users\HOME\AppData\Local\Android\sdk
• Platform android-30, build-tools 29.0.3
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 4.1.0)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[√] VS Code (version 1.59.1)
• VS Code at C:\Users\HOME\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.25.0
[√] Connected device (3 available)
• sdk gphone x86 (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator)
• Chrome (web) • chrome • web-javascript • Google Chrome 92.0.4515.159
• Edge (web) • edge • web-javascript • Microsoft Edge 92.0.902.78
Can anyone provide a solution for this?
Normally, "Null check operator used on a null value" is throw when
var v = null;
var s = v!.value; <--"Null check operator used on a null value"
You can check the simple flutter APP codes.
Also, this may help: Null check operator used on a null value
It's most probably you are using SDK of flutter which employs null safety.
Edit your pubspec.yaml with fluuter sdk less than 2.12 or ensure null safety in your code.

Getting an error "Null check operator used on a null value" when trying to consume value from provider

I'm getting the below error when trying to execute my flutter app:
======== Exception caught by widgets library =======================================================
The following _CastError was thrown building VerifyEmail(dirty, dependencies: [_InheritedProviderScope<User?>], state: _VerifyEmailState#da862):
Null check operator used on a null value
The relevant error-causing widget was:
VerifyEmail file:///Users/sas/Projects/Development/App/Flutter/netapp/lib/screens/sign_up.dart:152:61
When the exception was thrown, this was the stack:
#0 _VerifyEmailState.build (package:netapp/screens/verify_email.dart:58:40)
#1 StatefulElement.build (package:flutter/src/widgets/framework.dart:4691:27)
#2 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4574:15)
#3 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4746:11)
#4 Element.rebuild (package:flutter/src/widgets/framework.dart:4267:5)
...
====================================================================================================
The error causing code:
User? firebaseUser = Provider.of<User?>(context, listen: false);
String? emailAddress = firebaseUser!.email;
If I do not specify the null check operator [!] to email then I get a syntax error.
I'm using this emailAddress variable within a Text widget.
Text(
emailAddress!,
textAlign: TextAlign.center,
style: GoogleFonts.roboto(
textStyle: Theme.of(context).textTheme.subtitle1!.copyWith(
color: kBrandAccentColor,
),
),
),
The code listed below is relevant to the provider present within the main.dart file:
return MultiProvider(
providers: [
StreamProvider<User?>.value(
value: AuthService().onAuthStateChanged,
initialData: null,
),
]
)
The below code is present within my authentication service file:
Stream<User?> get onAuthStateChanged => authInstance.authStateChanges();
Versions of the packages:
firebase_core: ^1.3.0
firebase_auth: ^1.4.1
cloud_firestore: ^2.2.2
provider: ^5.0.0
Output of the flutter --version:
Flutter 2.2.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 02c026b03c (5 weeks ago) • 2021-05-27 12:24:44 -0700
Engine • revision 0fdb562ac8
Tools • Dart 2.13.1
The firebaseUser is still null when you want to ask its email. By using the ! operator, you explicitly tell "I personally guarantee this object is not null", which isn't the case so it throws the exception.
Maybe you wanted to use the ? operator instead?
String? emailAddress = firebaseUser?.email;
This will use optional chaining, which seems to be the thing you need here.

Flutter: Getting "Null check operator used on a null value" error creating MaterialColor

I'm creating a custom MaterialColor object but it's throwing that error.
colors.dart (where I'm creating the MaterialColor object)
import 'package:flutter/material.dart';
class JarsColors {
static const MaterialColor palette = MaterialColor(
0xFF276678,
<int, Color> {
0: Color(0xFFF6F5F5),
100: Color(0xFFD3E0EA),
400: Color(0xFF1687A7),
500: Color(0xFF276678),
}
);
}
main.dart
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: JarsColors.palette,
),
home: JarsHome(title: 'Hello'),
);
}
}
Error output:
The following _CastError was thrown building MyApp(dirty):
Null check operator used on a null value
The relevant error-causing widget was
MyApp
When the exception was thrown, this was the stack
#0 new ThemeData
#1 MyApp.build
#2 StatelessElement.build
#3 ComponentElement.performRebuild
#4 Element.rebuild
flutter doctor output
λ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.0.3, on Microsoft Windows [Version 10.0.19042.928], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[√] Chrome - develop for the web
[√] Android Studio (version 4.1.0)
[√] VS Code (version 1.55.2)
[√] Connected device (3 available)
• No issues found!
I managed to make it work by adding more shades to the MaterialColor swatch argument:
class JarsColors {
static const MaterialColor palette = MaterialColor(
0xFF276678,
<int, Color> {
50: Color(0xFFF6F5F5),
100: Color(0xFFD3E0EA),
200: Color(0xFFD3E0EA),
300: Color(0xFFD3E0EA),
400: Color(0xFF1687A7),
500: Color(0xFF276678),
600: Color(0xFFD3E0EA),
700: Color(0xFF1687A7),
}
);
}
With the help of: https://api.flutter.dev/flutter/material/MaterialColor-class.html
Nonetheless I can't find an explanation to this. It'd be great to know.
To keep answer short and straight forward, when defining MaterialColor you must start from 50, then 100 and increments in interval of 100 to 800 is enough to allow you to use it without null check errors, check this one how they did it here
How to define and use custom MaterialColor in flutter

Dart if(A is B) condition not working properly

var data = snapshot.data as List;
return ListView.builder(
itemCount: data.length,
itemBuilder: (context, i) {
var item = data[i];
print('instance: $item');
if (item is BookFavorItem) {
return BookItemCard(
bookId: item.bookId,
title: item.title,
author: item.author,
);
} else if (item is BookLentItem) {
return BookItemCard(
bookId: item.bookId,
title: item.title,
author: item.author,
dateRange: '${item.lentDate} - ${item.deadline}',
);
} else {
return ListTile(
title: Text('<$item> not matched'),
);
}
},
);
Console Output
I/flutter ( 6832): instance: Instance of 'BookFavorItem'
I/flutter ( 6832): instance: Instance of 'BookFavorItem'
I/flutter ( 6832): instance: Instance of 'BookFavorItem'
I/chatty ( 6832): uid=10336(com.example.library) 1.ui identical 6 lines
I/flutter ( 6832): instance: Instance of 'BookFavorItem'
I/flutter ( 6832): instance: Instance of 'BookFavorItem'
I/chatty ( 6832): uid=10336(com.example.library) 1.ui identical 5 lines
I/flutter ( 6832): instance: Instance of 'BookFavorItem'
Screen Result
As you can see from the code, I got a variable called item which is an instance of BookFavorItem.
However, when I use condition if( item is BookFavorItem ) to control the flow, it did not work as expected behavior. (I thought this condition should be true, but it didn't)
The evidence is that I got the message of "Instance of BookFavorItem", which is the exact type used for is condition from Debug Console and App Screen
What's wrong with me?
-> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.17.1, on Microsoft Windows [Version 10.0.19041.264], locale zh-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
X Android license status unknown.
Try re-installing or updating your Android SDK Manager.
See https://developer.android.com/studio/#downloads or visit visit
https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions.
[!] Android Studio (version 3.6)
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
[√] VS Code (version 1.45.1)
[√] Connected device (1 available)