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

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.

Related

The Flutter build is stuck on the splash screen

Flutter build is stuck on the splash screen. I tried it on both a real device and the Pixel 4 Api33 emulator. Using Namal woocommerce source code available on codecanyon website and I am a beginner. I tried my best to figure out what's wrong but I failed. Asking for your help guys, please let me know if you need any other information.
**main.dart error log file on Pixel 4 Api33 emulator**
Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...
Running Gradle task 'assembleDebug'...
√ Built build\app\outputs\flutter-apk\app-debug.apk.
D/FlutterGeolocator(10640): Attaching Geolocator to activity
W/FlutterActivityAndFragmentDelegate(10640): A splash screen was provided to Flutter, but this is deprecated. See flutter.dev/go/android-splash-migration for migration steps.
D/FlutterGeolocator(10640): Creating service.
D/FlutterGeolocator(10640): Binding to location service.
D/FlutterLocationService(10640): Creating service.
D/FlutterLocationService(10640): Binding to location service.
D/FlutterGeolocator(10640): Geolocator foreground service connected
D/FlutterGeolocator(10640): Initializing Geolocator services
D/FlutterGeolocator(10640): Flutter engine connected. Connected engine count 1
Debug service listening on ws://127.0.0.1:54544/-pXfnrJ83sQ=/ws
Syncing files to device sdk gphone64 x86 64...
V/OneSignal(10640): Initializing the OneSignal Flutter SDK (3.3.2)
D/OneSignal(10640): Adding a task to the pending queue with ID: 1
D/OneSignal(10640): startPendingTasks with task queue quantity: 1
D/OneSignal(10640): Attempted to clean 6 month old IAM data, but none exists!
D/OneSignal(10640): OneSignal InAppMessageTracker initInfluencedTypeFromCache: OSChannelTracker{tag=iam_id, influenceType=UNATTRIBUTED, indirectIds=null, directId=null}
D/OneSignal(10640): OneSignal NotificationTracker initInfluencedTypeFromCache: OSChannelTracker{tag=notification_id, influenceType=UNATTRIBUTED, indirectIds=null, directId=null}
D/OneSignal(10640): OneSignal getUnattributedUniqueOutcomeEventsSentByChannel: null
W/OneSignal(10640): appContext set, but please call setAppId(appId) with a valid appId to complete OneSignal init!
V/OneSignal(10640): setAppId called with id: YOUR_ONESIGNAL_APP_ID changing id from: null
V/OneSignal(10640): Starting OneSignal initialization!
D/OneSignal(10640): Retrieved IAMs from DB redisplayedInAppMessages: []
V/OneSignal(10640): No class found, not setting up OSRemoteNotificationReceivedHandler
I/OneSignal(10640): Last Pending Task has ran, shutting down
V/OneSignal(10640): OneSignal SDK initialization delayed, waiting for remote params.
D/OneSignal(10640): Starting request to get Android parameters.
D/OneSignal(10640): OneSignalRestClient: Making request to: https://api.onesignal.com/apps/YOUR_ONESIGNAL_APP_ID/android_params.js
W/SQLiteLog(10640): (28) double-quoted string literal: "notification"
D/OneSignal(10640): OneSignalRestClient: Adding header if-none-match: W/"05702b137a259242f45cdd80824abb9f"
D/TrafficStats(10640): tagSocket(135) with statsTag=0x2710, statsUid=-1
V/OneSignal(10640): OneSignalRestClient: After con.getResponseCode to: https://api.onesignal.com/apps/YOUR_ONESIGNAL_APP_ID/android_params.js
D/OneSignal(10640): OneSignalRestClient: GET - Using Cached response due to 304: {"awl_list":{},"receive_receipts_enable":false}
D/OneSignal(10640): OneSignal saveInfluenceParams: InfluenceParams{indirectNotificationAttributionWindow=1440, notificationLimit=10, indirectIAMAttributionWindow=1440, iamLimit=10, directEnabled=false, indirectEnabled=false, unattributedEnabled=false}
D/OneSignal(10640): reassignDelayedInitParams with appContext: androidx.multidex.MultiDexApplication#7610e7d
V/OneSignal(10640): setAppId called with id: YOUR_ONESIGNAL_APP_ID changing id from: null
V/OneSignal(10640): Starting OneSignal initialization!
V/OneSignal(10640): No class found, not setting up OSRemoteNotificationReceivedHandler
E/OneSignal(10640): OneSignal AppId format is invalid.
E/OneSignal(10640): Example: 'b2f7f966-d8cc-11e4-bed1-df8f05be55ba'
E/OneSignal(10640):
E/OneSignal(10640): java.lang.IllegalArgumentException: Invalid UUID string: YOUR_ONESIGNAL_APP_ID
E/OneSignal(10640): at java.util.UUID.fromString(UUID.java:194)
E/OneSignal(10640): at com.onesignal.OSUtils.initializationChecker(OSUtils.java:118)
E/OneSignal(10640): at com.onesignal.OneSignal.init(OneSignal.java:841)
E/OneSignal(10640): at com.onesignal.OneSignal.setAppId(OneSignal.java:735)
E/OneSignal(10640): at com.onesignal.OneSignal.reassignDelayedInitParams(OneSignal.java:1181)
E/OneSignal(10640): at com.onesignal.OneSignal.onRemoteParamSet(OneSignal.java:889)
E/OneSignal(10640): at com.onesignal.OneSignal$7.complete(OneSignal.java:1122)
E/OneSignal(10640): at com.onesignal.OneSignalRemoteParams.processJson(OneSignalRemoteParams.java:211)
E/OneSignal(10640): at com.onesignal.OneSignalRemoteParams.access$100(OneSignalRemoteParams.java:12)
E/OneSignal(10640): at com.onesignal.OneSignalRemoteParams$1.onSuccess(OneSignalRemoteParams.java:156)
E/OneSignal(10640): at com.onesignal.OneSignalRestClient$5.run(OneSignalRestClient.java:279)
E/OneSignal(10640): at java.lang.Thread.run(Thread.java:1012)
V/OneSignal(10640): initWithContext called with: androidx.multidex.MultiDexApplication#7610e7d
V/OneSignal(10640): Starting OneSignal initialization!
V/OneSignal(10640): No class found, not setting up OSRemoteNotificationReceivedHandler
I/flutter (10640): --> GET https://sidemenclothing.in/wp-json/api/tc_settings/app_all_settings
I/flutter (10640): {clientid: 1234, clientsecret: sk_1234, X-Requested-With: XMLHttpRequest, authorization: }
[log]
<-- START PARAMS:
null
END PARAMS -->
<-- END HTTP
I/flutter (10640): Hivedata
I/flutter (10640): Instance of 'BoxImpl<WooCartData>'
E/flutter (10640): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: RangeError (index): Invalid value: Valid value range is empty: 0
E/flutter (10640): #0 List.[] (dart:core-patch/growable_array.dart:264:36)
E/flutter (10640): #1 _SplashScreenState.getCart (package:flutter_kundol/ui/screens/splash_screen.dart:136:28)
E/flutter (10640): <asynchronous suspension>
E/flutter (10640):
I/flutter (10640): <-- 200 GET https://sidemenclothing.in/wp-json/api/tc_settings/app_all_settings
[log]
<-- START RESPONSE:
{last_tab: 1, home_style: 1, category_style: 1, banner_style: 3, card_style: 1, cancel_order_button: 0, cancel_order_hours: 1, package_name: app.beastdeals, site_url: https://sidemenclothing.in/, new_product_duration: 5, filter_max_price: 100000, update_order: 10, one_page_checkout: 1, checkout_process: yes, custom_css_for_checkout: .site-header, nav, #secondary, footer {display: none!important;}, contact_us_email: info#domain-name.com, from_email: from#domain-name.com, phone_no: +92 123 456-789, address: 228 Park avs, city: New York, state: NY, Zip: 10003, Country: USA, Latitude: 40.730610, Longitude: -73.935242, sidebar_menu_icon: 0, wish_list_page: 0, edit_profile_page: 0, shipping_address_page: 0, my_orders_page: 0, contact_us_page: 0, about_us_page: 0, bill_ship_info: 0, downloads: 0, news_page: 0, intro_page: 0, share_app: 0, rate_app: 0, setting_page: 0, notification_title: Theme Coder, notification_text: A bundle of products wating for you!, notification_duration: 0, facebook_login: 0, about_page_id: , refund_page_id: , privacy_page_id: , terms_page_id: , wpml_enabled: 0, mvf_enabled: 0, wp_point_reward: 0, wp_multi_currency: 0, delivery_tracking: 0, tracking_url: http://urltracking.com/, geo_fencing: 0, one_signal_notification: 0, one_signal_app_id: , one_signal_app_key: , privacy_page: , refund_page: , terms_page: , about_page: , currency: {name: INR, position: left}, language: {name: en_US}}
END RESPONSE -->
<-- END HTTP
E/flutter (10640): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value
E/flutter (10640): #0 _SplashScreenState.build.<anonymous closure> (package:flutter_kundol/ui/screens/splash_screen.dart:74:76)
E/flutter (10640): #1 _BlocListenerBaseState._subscribe.<anonymous closure> (package:flutter_bloc/src/bloc_listener.dart:204:24)
E/flutter (10640): #2 _RootZone.runUnaryGuarded (dart:async/zone.dart:1586:10)
E/flutter (10640): #3 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (10640): #4 _DelayedData.perform (dart:async/stream_impl.dart:515:14)
E/flutter (10640): #5 _PendingEvents.handleNext (dart:async/stream_impl.dart:620:11)
E/flutter (10640): #6 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:591:7)
E/flutter (10640): #7 _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
E/flutter (10640): #8 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
E/flutter (10640):
D/EGL_emulation(10640): app_time_stats: avg=988.05ms min=162.14ms max=1813.96ms count=2
**pubsec.yml file**
name: flutter_kundol
description: A new Flutter ecommerce application.
# 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.17.6 <3.0.5'
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
flutter_bloc: ^7.3.3 # need to change InitialState implementations for above 7.3.3
equatable: ^2.0.5
shared_preferences: ^2.0.15
carousel_slider: ^4.1.1
dio: ^4.0.6
cached_network_image: ^3.2.1
flutter_html: ^2.2.1
# flutter_range_slider: "^1.5.0"
firebase_auth: ^4.1.1
google_sign_in: ^5.4.1
firebase_core: ^2.1.1
flutter_login_facebook: ^1.6.0
share: ^2.0.4
in_app_review: ^2.0.4
onesignal_flutter: ^3.4.1
flutter_svg: ^0.23.0+1
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.5
launch_review: ^3.0.1
dropdown_search: ^1.0.0
google_maps_place_picker_mb: ^2.0.0-mb.22
google_maps_flutter: ^2.1.12
bubble_tab_indicator: ^0.1.6
webview_flutter: ^2.8.0
url_launcher: ^6.1.5
hive: ^2.2.3
path_provider: ^2.0.11
hive_flutter: ^1.1.0
dev_dependencies:
hive_generator: ^1.1.3
build_runner: ^2.2.0
change_app_package_name: ^1.1.0
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
# To add assets to your application, add an assets section, like this:
assets:
- assets/langs/
- assets/images/
- assets/icons/
- assets/json/
fonts:
- family: MontserratRegular
fonts:
- asset: assets/fonts/Montserrat-Regular.ttf
- family: MontserratLight
fonts:
- asset: assets/fonts/Montserrat-Light.ttf
- family: MontserratMedium
fonts:
- asset: assets/fonts/Montserrat-Medium.ttf
- family: MontserratBold
fonts:
- asset: assets/fonts/Montserrat-Bold.ttf
- family: MontserratSemiBold
fonts:
- asset: assets/fonts/Montserrat-SemiBold.ttf
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages

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)

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

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)

Flutter play custom sound using audioplayers 0.7.7?

pubspec.yaml
flutter:
uses-material-design: true
assets:
- assets/Images/1.png
- assets/Images/MP3.mp3
Test.dart
Widget localAsset() {
return _tab([
Text("Click to play"),
_btn('Play', () => audioCache.play('assets\Images\MP3.mp3')),
]);
}
I am new to flutter, for my applications i want play two sounds mode(background sound ,button action sound), after referred from flutter package i have changed code like as above , when i used this widget in my material,i am getting below error,
E/flutter ( 2750): [ERROR:flutter/shell/common/shell.cc(181)] Dart Error: Unhandled exception:
E/flutter ( 2750): Unable to load asset: assets/assetsImagesMP3.mp3
E/flutter ( 2750): #0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
Backslash are Windows-specific. Use slashes instead. Android is Unix-based and so is iOS
audioCache.play('assets/Images/MP3.mp3')