I have been reading some answers to this question at stackoverflow but no one has worked for me. For example this one: Flutter how to handle Image.network error (like 404 or wrong url)
Here the code:
ListView.builder(
itemCount: steamUsers.length,
itemBuilder: (context, index) => ListTile(
leading: CircleAvatar(
child: steamUsers[index].avatarUrl != null
? Image.network(
steamUsers[index].avatarUrl!,
errorBuilder: (context, error, stackTrace) {
return
const Icon(Icons.person);
},
)
: const Icon(Icons.person),
),
title: Text(steamUsers[index].accountName),
subtitle: Text(steamUsers[index].personName),
)),
How can I avoid flutter throwing an exception when picture is not found (404)? Notice I'm already using the errorBuilder property.
The exception dump is:
HTTP request failed, statusCode: 404,
https://avatars.akamai.steamstatic.com/5e3a3f851ea968aa4a35fa454ddfe5acafe2ec3.jg
Related
new to flutter and working on this error.
this is the code.
PROBLEM- I want to to show the text(your cart is empty!) when the firestore is empty. The text is displaying when the firestore document is empty but the problem is when firestore has some data to display, the text(your cart is empty!) will display and after a moment(0.5 sec) the data will display.
I don't want to display the text (your cart is empty) even for a milliseconds when the firestore has data. I appreciate if you guys can light the bulb for me.
that happened because you didn't get response yet for the database so to make sure that you received respond you will use snapshot.hasData
StreamBuilder(
stream: FirebaseFirestore.instance
.collection('User-Cart-Item')
.doc(FirebaseAuth.instance.currentUser!.email)
.collection("items")
.snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasData) {
if (snapshot.data == null || snapshot.data!.docs.isEmpty) {
return const Center(
child: Text(
'YOUR CART IS EMPTY!',
style: TextStyle(
color: Colors.purple,
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
);
} else {
return ListView.builder(
itemCount:
snapshot.data == null ? 0 : snapshot.data!.docs.length,
itemBuilder: (_, index) {
DocumentSnapshot documentSnapshot =
snapshot.data!.docs[index];
return Card(
color: const Color.fromARGB(255, 255, 248, 250),
margin: const EdgeInsets.all(20),
child: Container(
height: 120,
padding: const EdgeInsets.all(0),
child: Row(
children: [
Expanded(
flex: 6,
child: Container(decoration: const BoxDecoration()),
),
],
),
),
);
},
);
}
} else {
return const Center(child: CircularProgressIndicator());
}
},
),
I hope this work for you
With FutureBuilder, the app is listening to changes to the database. What you are noticing is the latency between a change being made, and your app receiving it. This can never be absolute 0 because a reading device only sees a change after the change has been made. You can decrease this number with optic internet (fast internet connection) and by moving the database closer to where you are. There are multiple regions that you can choose from in order to get you as close as possible.
I currently have a page with a scaffold that has a Stream Builder in it's body connected to Cloud Firestore for the database. The StreamView just returns a ListView of the contents of the database.
return Scaffold(
body: StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance.collection('tasks').snapshots(),
builder: ((context, snapshot) {
if (!snapshot.hasData) {
return const Center(
child: CircularProgressIndicator(),
);
}
return ListView.builder(
itemCount: snapshot.data!.docs.length,
itemBuilder: (context, index) => buildItem(
context,
snapshot.data!.docs[index],
));
}),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
openDialog();
},
backgroundColor: Color(Colors.blueAccent.value),
child: const Icon(Icons.add),
),
);
}
To add new entries to the database I created a ShowDialog nested in a function called openDialog().
To open that dialog I used a floating action button but it is not appearing on the screen
Edit: Possibly concerning output from flutter run -v:
Gradle detected a problem with the following location: '[path to my app]\build\app\intermediates\assets\debug\mergeDebugAssets'. Reason: Task ':app:compressDebugAssets'
uses this output of task ':app:copyFlutterAssetsDebug' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are
executed. Please refer to https://docs.gradle.org/7.4/userguide/validation_problems.html#implicit_dependency for more details about this problem.
I went to the website but it was java so I don't really understand it.
I have an application like this:
Also codes:
String yapilacaklar;
Container(
height: 500,
child: ListView.builder(
itemBuilder: (context, index) {
return ListTile(
title: Text(yapilacaklar.toString() ?? "Yok")
);
},
),
),
ArrayList from Firestore is kept in yapilacaklar variable.
yapilacaklar = ["Görev 1", "Görev 2"]
I want to show these items one by one in ListTile. How can I do that? Thanks in advance for your help.
I am getting an error while trying to compile my code could anyone help me fix it? I am trying to create a list of buttons that will navigate to another screen. It was previously a expansion tile and I am trying to switch it to a list tile.
return ListTile(
title: Text(StudyViewModel.studies[index].name,
style: TextStyle(fontSize: 18.0)),
children: <Widget>[
ListView.builder(
shrinkWrap: true,
physics: ClampingScrollPhysics(),
itemCount: StudyViewModel.studies[index].tasks.length,
itemBuilder: (context, int taskIndex) {
return ListTile(
title: Text(StudyViewModel.studies[index].tasks[taskIndex].name),
contentPadding: EdgeInsets.symmetric(horizontal: 32.0),
subtitle: Text(
StudyViewModel.studies[index].tasks[taskIndex].elapsedTime),
);
},
),
Based off of responses, the goal of this code is to create a list of buttons that have previously been defined in a template. These buttons will be used in a time study app. I would like to be able to upload the activities into a new page. Originally, the code was written as an expansiontile, but I am trying to change it to a listtile. The error we are encountering is:
lib/pages/home_page.dart:107:7: Error: No named parameter with the name 'children'.
children: [
^^^^^^^^
../../lib/flutter/packages/flutter/lib/src/material/list_tile.dart:762:9: Context: Found this candidate, but the arguments don't match.
const ListTile({
^^^^^^^^
Failed to compile application
Error code for ListView
The ListTile widget doesn't contain a parameter named children. In your code you're setting a parameter 'children' which is invalid.
This might help:
return ListView(
children: <Widget>[
Text(StudyViewModel.studies[index].name,
style: TextStyle(fontSize: 18.0),
),
ListView.builder(
shrinkWrap: true,
primary: false,
itemCount: StudyViewModel.studies[index].tasks.length,
itemBuilder: (context, int taskIndex) {
return ListTile(
title: Text(StudyViewModel.studies[index].tasks[taskIndex].name),
contentPadding: EdgeInsets.symmetric(horizontal: 32.0),
subtitle: Text(StudyViewModel.studies[index].tasks[taskIndex].elapsedTime),
);
},
),
I am running into an issue trying to populate a SliverFixedExtentList with children from a JSON API response. I have a function _getMyListOfCustomJsonObjects() that returns a Future<'List<'CustomJsonObject>>. I am fairly new to flutter, but my understanding of SliverLists is that they should behave similarly to a ListView. I have been able to populate a ListView of these children using a FutureBuilder and ListView.builder. However, making the change to a SliverList is throwing me an error.
Below is an example of my code
CustomScrollView(
slivers: [
SliverAppBar(),
FutureBuilder(
future: _getMyListOfCustomJsonObjects,
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.data != null)
return SliverFixedExtentList(
itemExtent: 150,
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return
Container(
color: Colors.red,
child: Text('${snapshot.data[index].Name}'));
},
childCount: snapshot.data.length),
);
else {
return Padding(
padding: EdgeInsets.only(top:50),
//alignment: Alignment.center,
child: Stack(
alignment: Alignment.bottomCenter,
children: <Widget>[
new CircularProgressIndicator(
value: null,
strokeWidth: 4,
backgroundColor: Color(0xFFe5ac3b),
semanticsLabel: "Loading",
valueColor:
new AlwaysStoppedAnimation<Color>(Color(0xFF12336c)),
),
],
),
);
}
},
),
],
),
I think I might be close, but this is my first time trying to use Slivers so I'm not sure if I'm missing a key component to make this all work. Below are the errors I get when I try to run this code.
flutter: Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 4345 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
flutter: Another exception was thrown: Duplicate GlobalKeys detected in widget tree.
Any suggestions to achieve populating a SliverList with Future<List<CustomJSONObject>>?