using 2 formtextfield throws exception '<optimized out>': is not true - flutter

I'm using 2 FormTextField in a form, both take numbers , first for landline and second for mobile number,when I use only one field the apps works fine but when I add the second field I get this exception when the page loads :
════════ Exception caught by rendering library ══════
The following assertion was thrown during paint():
'dart:ui/text.dart': Failed assertion: line 1372: '': is not true.
this is the code :
Flexible(
flex: 1,
fit: FlexFit.loose,
child: Form_Text_Field_Number(
tf_label: 'Landline # ',
fieldController: landlineFieldController,
icon: Icons.phone,
),
),
Flexible(
flex: 1,
fit: FlexFit.loose,
child: Form_Text_Field_Number(
tf_label: 'Mobile #',
fieldController: mobileFieldController,
icon: Icons.phone_android,
),
),
the design of both fields is the same based on FormTextField..only field name differ.
I tried some suggestions like placing the text field in a Container ...but non solved the issue.
why this happen only when adding the second field , what could be the reason ?
and how to solve.

Related

Flutter Form Builder with Date Picker. No named parameter with the name 'anchorPoint'. anchorPoint: widget.anchorPoint,

I have a strange problem, I used Flutter Form Builder before and I can't fix any issues but when I use it in other project this is occurred with me.
I cleaned my project and run flutter pub get then flutter run but no thing is changed
this is complete error:
Error Image
FormBuilder(
key: _formKey,
child: Column(
children: [
FormBuilderTextField(
name: 'age',
decoration: const InputDecoration(
labelText:
'This value is passed along to the [Text.maxLines] attribute of the [Text] widget used to display the hint text.',
),
onChanged: (value) {},
// valueTransformer: (text) => num.tryParse(text),
keyboardType: TextInputType.number,
),
],
),
)
Error
../../FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_form_builder-7.2.1/lib/src/fields/for
m_builder_date_time_picker.dart:355:7: Error: No named parameter with the name 'anchorPoint'.
anchorPoint: widget.anchorPoint,
^^^^^^^^^^^
../../FlutterDev/flutter/packages/flutter/lib/src/material/date_picker.dart:133:19: Context: Found this
candidate, but the arguments don't match.
Future<DateTime?> showDatePicker({
^^^^^^^^^^^^^^
../../FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_form_builder-7.2.1/lib/src/fields/for
m_builder_date_time_picker.dart:373:7: Error: No named parameter with the name 'anchorPoint'.
anchorPoint: widget.anchorPoint,
^^^^^^^^^^^
../../FlutterDev/flutter/packages/flutter/lib/src/material/time_picker.dart:2413:20: Context: Found this
candidate, but the arguments don't match.
Future<TimeOfDay?> showTimePicker({
^^^^^^^^^^^^^^
add form_builder_extra_fields: ^8.2.0 dependencies.

Why showcaseview throws error on first try?

Hey I am using ShowCaseView in my Flutterapp. When I first open my app, after registration there is no showcase, not even the icon which should be 'showcased' is shown. But when I am closing the app and opening it again it works just fine.
Thats the code referring to showcase:
class _HomeSearchPageState extends State<HomeSearchPage> {
final keyOne = GlobalKey();
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback(
(_) => ShowCaseWidget.of(context).startShowCase([
keyOne,
]),
);
}
And now the scaffold:
return Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(getTopBarSize()),
child: AppBar(
automaticallyImplyLeading: false,
title: Text(
'username',
style: TextStyle(fontSize: 14),
),
actions: <Widget>[
Showcase(
key: keyOne,
description: 'test',
child: IconButton(
icon: Icon(Icons.search),
onPressed: () {
showSearch(context: context, delegate: DataSearch())
.whenComplete(() => setName());
}),
),
],
),
),)
I did exactly the same as in the Github example but still it throws this error the first time:
════════ Exception caught by widgets library ═══════════════════════════════════
The following NoSuchMethodError was thrown building IconTheme(color: Color(0xffffffff)):
The getter 'activeWidgetIds' was called on null.
Receiver: null
Tried calling: activeWidgetIds
The relevant error-causing widget was
AppBar
lib\Views\HomeSearchPage.dart:182
When the exception was thrown, this was the stack
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 ShowCaseWidget.activeTargetWidget
package:showcaseview/showcase_widget.dart:51
#2 _ShowcaseState.showOverlay
package:showcaseview/showcase.dart:171
#3 _ShowcaseState.didChangeDependencies
package:showcaseview/showcase.dart:164
#4 StatefulElement._firstBuild
package:flutter/…/widgets/framework.dart:4786
════════ Exception caught by rendering library ═════════════════════════════════
Each child must be laid out exactly once.
The relevant error-causing widget was
AppBar
lib\Views\HomeSearchPage.dart:182
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by scheduler library ═════════════════════════════════
Exception: Please provide ShowCaseView context
════════ Exception caught by widgets library ═══════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 6224 pos 12: '_children.contains(child)': is not true.
The relevant error-causing widget was
AppBar
lib\Views\HomeSearchPage.dart:182
════════════════════════════════════════════════════════════════════════════════
These errors are kind a looped, so the debug console shows them all the time.
The only difference between the first app opening and the second one is: In the first one the user enters a registrationpage and after this he enters the page with the showcaseview. In the second the user enters directly the page with the showcaseview. How can this affect the showcase and more accurate why does this throw the errors?
Not sure if we share a similar issue but maybe my answer will help you somehow :). The issue occurs when I navigate to the page where I have Showcase widget, but it does not occur when I navigate "back" to the page from the other page.
Maybe you can check this page "This error is thrown if you haven't wrapped your widget with ShowCaseWidget. This is not the problem with the package itself."
Thus, I tried raising the level of the ShowCaseWidget in the main.dart and the issue was solved.
void main() {
// runApp(MyApp());
runApp(
ShowCaseWidget(
autoPlay: false,
autoPlayDelay: Duration(seconds: 8),
autoPlayLockEnable: false,
builder: Builder(
builder: (context) => MyApp(),
),
onStart: (index, key) {
print('onStart: $index, $key');
},
onComplete: (index, key) {
print('onComplete: $index, $key');
},
),
);
}
So far the app still works well. I will report again here in case any issues occur.

Flutter and Google Sing in: Invalid image data

I have implemented Google Authentication with FlutterFire. I use the official package to sing in users.
However, if I navigate to a page where the user profile picture is seen and try to render the GoogleUserCircleAvatarar, although the page seems to be working just fine, I get an error in the console:
════════ Exception caught by image resource service ════════════════════════════════════════════════
Exception: Invalid image data
════════════════════════════════════════════════════════════════════════════════════════════════════
On the screen, it takes a few milliseconds, to load up the picture. Before it's loaded, I can see the placeholder image (First letter of the users initials on a filled background) next to the user's name and email address (so the currentUser is loaded) which transitions to the user profile picture. As I am using the recommended Widget, I am confused how should I prevent the error from happening.
Code:
if (widget.userService.currentUser != null) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
ListTile(
leading: GoogleUserCircleAvatar(
identity: widget.userService.currentUser,
),
title: Text(widget.userService.currentUser.displayName ?? ''),
subtitle: Text(widget.userService.currentUser.email ?? ''),
),
const Text("Signed in successfully."),
RaisedButton(
child: const Text('SIGN OUT'),
onPressed: _handleSignOut,
),
],
);
} else {
...
currentUser object is created with the official API:
currentUser = await GoogleSignIn().signIn();
and my pubspec.yml:
dependencies:
flutter:
sdk: flutter
cloud_firestore: ^0.14.0+1
provider: ^4.3.2+2
google_sign_in: "^4.5.1"
firebase_core: "^0.5.0+1"
firebase_auth: "^0.18.1+2"
This issue should've resolved on the latest version of the google_sign_in plugin. More details of the fix for the issue is discussed on this pull request.

Flutter/Dart - How can I play sounds from a list using onPressed with a flatButton in flutter_Swiper package?

G'day Stackoverflowers!
I have started learning Flutter/Dart for a personal project and I came across a problem I can't solve. I would really appreciate a bit of help, please.
I'm building an application to learn English (I'm an English teacher and author) and one of the pages of the app is where you can see pictures of different foods and drinks with their name written and the possibility to listen to the pronunciation of the food or drink.
here is a snippet of the code so far:
Swiper(
itemWidth: MediaQuery.of(context).size.width,
itemHeight: MediaQuery.of(context).size.height,
layout: SwiperLayout.TINDER,
itemCount: 43,
indicatorLayout: PageIndicatorLayout.WARM,
itemBuilder: (BuildContext context, int index,) {
return Card(
elevation: 5.0,
child: Column(
children: <Widget>[
FlatButton(
onPressed: () => {
foodSounds[index],
},
child: Row(
children: <Widget>[
SizedBox(
width: 70.0,
),
Icon(Icons.volume_up),
SizedBox(
width: 30.0,
),
Text(foodNouns[index],
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w500,
)),
],
),
),
Image.asset(foodPictures[index], fit: BoxFit.contain),
],
),
);
As you can probably guess, I have no problem displaying the pictures I want and their respective nouns using a list and the index of this list.
Here are the lists I've got for the pictures and nouns
final List foodPictures = [
'images/foodnouns/apple.jpg',
'images/foodnouns/banana.jpg',
'images/foodnouns/bar.jpg',
'images/foodnouns/beer.jpg',
'images/foodnouns/biscuits.jpg',
'images/foodnouns/bread.jpg',
'images/foodnouns/breakfast.jpg',
'images/foodnouns/butter.jpg',
'images/foodnouns/cafe.jpg',
'images/foodnouns/cake.jpg',
'images/foodnouns/cheese.jpg',
'images/foodnouns/chocolate.jpg',
'images/foodnouns/coffee.jpg',
'images/foodnouns/cup.jpg',
'images/foodnouns/cup_of_coffee.jpg',
'images/foodnouns/dinner.jpg',
'images/foodnouns/egg.jpg',
'images/foodnouns/fish.jpg',
'images/foodnouns/food.jpg',
'images/foodnouns/fries.jpg',
'images/foodnouns/fruits.jpg',
'images/foodnouns/glass.jpg',
'images/foodnouns/ice_cream.jpg',
'images/foodnouns/juice.jpg',
'images/foodnouns/knife.jpg',
'images/foodnouns/lunch.jpg',
'images/foodnouns/meal.jpg',
'images/foodnouns/meat.jpg',
'images/foodnouns/milk.jpg',
'images/foodnouns/orange.jpg',
'images/foodnouns/picnic.jpg',
'images/foodnouns/pizza.jpg',
'images/foodnouns/plate.jpg',
'images/foodnouns/potatoes.jpg',
'images/foodnouns/rice.jpg',
'images/foodnouns/salt.jpg',
'images/foodnouns/sandwich.jpg',
'images/foodnouns/soup.jpg',
'images/foodnouns/sugar.jpg',
'images/foodnouns/tea.jpg',
'images/foodnouns/tomato.jpg',
'images/foodnouns/vegetables.jpg',
'images/foodnouns/wine.jpg',];
final List foodNouns =[
'apple',
'banana',
'bar',
'beer',
'biscuits',
'bread',
'breakfast',
'butter',
'cafe',
'cake',
'cheese',
'chocolate',
'coffee',
'cup',
'cup_of_coffee',
'dinner',
'egg',
'fish',
'food',
'fries',
'fruits',
'glass',
'ice_cream',
'juice',
'knife',
'lunch',
'meal',
'meat',
'milk',
'orange',
'picnic',
'pizza',
'plate',
'potatoes',
'rice',
'salt',
'sandwich',
'soup',
'sugar',
'tea',
'tomato',
'vegetables',
'wine',];
This is how it looks like so far:
overview of the page
Now I would like to be able to play a sound for each card. I have the sounds in my assets in the following directory : assets: -assets/foodsounds/
I want to be able to play the sound from a list of my sounds. here is the list :
final List foodSounds=[
'assets/foodsounds/apple.mp3',
'assets/foodsounds/banana.mp3',
'assets/foodsounds/bar.mp3',
'assets/foodsounds/beer.mp3',
'assets/foodsounds/biscuits.mp3',
'assets/foodsounds/bread.mp3',
'assets/foodsounds/breakfast.mp3',
'assets/foodsounds/butter.mp3',
'assets/foodsounds/café.mp3',
'assets/foodsounds/cake.mp3',
'assets/foodsounds/cheese.mp3',
'assets/foodsounds/chocolate.mp3',
'assets/foodsounds/coffee.mp3',
'assets/foodsounds/cup.mp3',
'assets/foodsounds/cup_of_coffee.mp3',
'assets/foodsounds/dinner.mp3',
'assets/foodsounds/egg.mp3',
'assets/foodsounds/fish.mp3',
'assets/foodsounds/food.mp3',
'assets/foodsounds/fries.mp3',
'assets/foodsounds/fruits.mp3',
'assets/foodsounds/glass.mp3',
'assets/foodsounds/ice_cream.mp3',
'assets/foodsounds/juice.mp3',
'assets/foodsounds/knife.mp3',
'assets/foodsounds/lunch.mp3',
'assets/foodsounds/meal.mp3',
'assets/foodsounds/meat.mp3',
'assets/foodsounds/milk.mp3',
'assets/foodsounds/orange.mp3',
'assets/foodsounds/picnic.mp3',
'assets/foodsounds/pizza.mp3',
'assets/foodsounds/plate.mp3',
'assets/foodsounds/potatoes.mp3',
'assets/foodsounds/rice.mp3',
'assets/foodsounds/salt.mp3',
'assets/foodsounds/sandwich.mp3',
'assets/foodsounds/soup.mp3',
'assets/foodsounds/sugar.mp3',
'assets/foodsounds/tea.mp3',
'assets/foodsounds/tomato.mp3',
'assets/foodsounds/vegetables.mp3',
'assets/foodsounds/wine.mp3',];
I thought about using the audioplayers-0.14.0 package like so :
void playFoodSound(int foodSounds) {
final player = AudioCache(prefix: 'foodsounds/');
player.play('$foodSounds.mp3');
}
and use it in Swiper like the following:
FlatButton(
onPressed: () => {
foodSounds[index],
},
This method doesn't work. I have tried a few others and I really can't figure out how to play those sounds...
I thank you all very much in advance for your help because I really don't want to have to hardcode those sounds.
Turns out I finally found my answer.
I used the assets_audio_player 1.2.3 package.
Declared the following vaiable:
final AssetsAudioPlayer playFoodSound= AssetsAudioPlayer();
and used the following statement in my code :
FlatButton(onPressed: () =>{
playFoodSound.open(foodSounds[index],),
},
And it works like a charm.

Exception caught by image resource service, The following assertion was thrown resolving an image codec:

I am trying to load an image into a scroll, but every time it does not load the image due to error:
Exception caught by image resource service The following assertion was thrown resolving an image codec:
Unable to load asset: assets/images/jorge.png
When the exception was thrown, this was the stack:
0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:464:44)
2 AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:449:14)
...
Image provider: AssetImage(bundle: null, name: "assets/images/jorge.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#dd41f(), name: "assets/images/jorge.png", scale: 1.0)
(2) Exception caught by image resource service
Unable to load asset: assets/images/heitor.png
(3) Exception caught by image resource service
Unable to load asset: assets/images/john.png
I/chatty ( 8763): uid=10206(com.festapp.flutter_app_fest) identical 5 lines
E/AccessibilityBridge( 8763): VirtualView node must not be the root node.
flutter clean was used, besides exchanging images
final User currentUser = User(
id: 0,
name: 'Current User',
imageUrl: 'assets/images/greg.png'
);
//usuários
final User Jorge = User(
id: 1,
name: 'Jorge',
imageUrl: 'assets/images/jorge.png'
);
final User John= User(
id: 2,
name: 'John',
imageUrl: 'assets/images/john.png'
);
final User Heitor = User(
id: 3,
name: 'Heitor',
imageUrl: 'assets/images/heitor.png'
);
final User Gui = User(
id: 4,
name: 'Gui',
imageUrl: 'assets/images/heitor.png'
);
and images use in:
return Padding(
padding: EdgeInsets.all(10.0),
child: Column(
children: <Widget>[
CircleAvatar(
radius: 35.0,
backgroundImage: AssetImage(favorites[index].imageUrl),
),
SizedBox(
height: 6.0,
),
Text(favorites[index].name, style: TextStyle(
color: Colors.blueGrey,
fontSize: 16.0,
fontWeight: FontWeight.w600,
),
),
],
),
);
Exception caught by image resource service
The following assertion was thrown resolving an image codec:
Unable to load asset: assets/images/jorge.png
When the exception was thrown, this was the stack:
0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:464:44)
2 AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:449:14)
...
Image provider: AssetImage(bundle: null, name: "assets/images/jorge.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#dd41f(), name: "assets/images/jorge.png", scale: 1.0)
(2) Exception caught by image resource service
Unable to load asset: assets/images/heitor.png
(3) Exception caught by image resource service
Unable to load asset: assets/images/john.png
It seems that these image files aren't in your project:
assets/images/jorge.png
assets/images/john.png
assets/images/heitor.png
Make sure you are doing these things:
Add the images in the folder assets/images/
Specify the images in pubspec.yaml
Execute flutter packages get / tap Packages get from
pubspec.yaml / tap Get dependencies from any dart file.
Use Image.asset() or AssetImage() to show them.
i also faced the same issue,
the solution is to stop the main.dart -by clicking the red button given in taskbar
and then restart it.
sometime its not able to load the images when you add it as fresh
To solve this error, you should check your pubspec.yaml file, either the asset folder is indexed like below or not:
flutter:
[2 whitespaces or 1 tab]assets:
[4 whitespaces or 2 tabs]- assets/images/ #index all files inside images folder
[4 whitespaces or 2 tabs]- assets/images/elephant.jpg #index only elephant.jpg