I want to get a download URL from firebase Storage - flutter

here is my build code for getting the URL from firebase storage and showing the image. The image name is save on my firestore as array. So i need to get the list of the image name and turn it into list of URL from firestorage.
#override
Widget build(BuildContext context){
return Container(
child: Stack(
children: [
FutureBuilder<QuerySnapshot>(
future: ref.get(),
builder: (context, snapshot) {
if(snapshot.hasError){
return Scaffold(
body: Center(
child: Text("Error: ${snapshot.error}"),
),
);
}
if(snapshot.connectionState == ConnectionState.done){
return Scaffold(
appBar: AppBar(title: Text("Home"),
centerTitle: true,
),
body: GridView(gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 200,
childAspectRatio: 2/3,
crossAxisSpacing: 15,
mainAxisSpacing: 15),
children: snapshot.data!.docs.map((document){
DateTime dt = (document['endDateTime'] as Timestamp).toDate();
List im = DownloadURL(document['imageURL']);// this are the call method
return Card(
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
child:Column(
children: [
Stack(
alignment: Alignment.center,
children: [
Ink.image(
image: NetworkImage(im[0]),
child: InkWell(
onTap: (){
Navigator.of(context).push(MaterialPageRoute(builder: (context)=>DetailScreen(productId: document.id,)));
},
),
height: 170,
fit: BoxFit.cover,
),
],
),
Expanded(
child: Container(
alignment: Alignment.center,
child: Padding(padding: EdgeInsets.all(4).copyWith(bottom: 0),
child: Text("${document['nameP']}",
style: TextStyle(fontSize: 16),
),
),
),
),
// SizedBox(height: 3),
Expanded(
child: Container(
alignment: Alignment.center,
child: Padding(padding: EdgeInsets.all(6).copyWith(bottom: 0),
child: Text("RM ${document['startPrice']}",
style: TextStyle(fontSize: 16),
),
),
),
),
SizedBox(height: 6),
Expanded(child: CountDownText(due: dt,
finishedText: "The Auction has End",
showLabel: true,
daysTextShort: "D ",
hoursTextShort: "H ",
minutesTextShort: "M ",
secondsTextShort: "S ",
style: TextStyle(fontSize: 16,color: Colors.deepPurpleAccent),
),
),
SizedBox(height: 2),
],
),
);
}).toList(),
),
);
}
//loading State
return Scaffold(
body: Center(
child: CircularProgressIndicator(),
),
);
}
),
],
),
);
}
and here is my method for getting the download URL from firebase storage
DownloadURL(List images) async{
List url = [];
for(int i = 0; i<images.length; i++){
url.add(await st.ref('products/${images[i]}').getDownloadURL());
}
return url;
}
it will show error, type 'Future' is not a subtype of type 'List' when run the code.

DownloadURL should return List.
Future<List<String>> DownloadURL(List images) async {
...
}
See Asynchronous programming

Related

Flutter: DropdownButton click causes error (LayoutBuilder does not support returning intrinsic dimensions)

Could someone explain me why I get the error LayoutBuilder does not support returning intrinsic dimensions when I click on a DropdownButton? And possibly how to fix it?
The code:
return Scaffold(
backgroundColor: CColors.lightBackground,
key: scaffoldKey,
endDrawer: const EndDrawer(),
body: SafeArea(
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
debugPrint('Building safe area');
safeWidth = constraints.maxWidth;
safeHeight = constraints.maxHeight;
return Column(
children: [
const HeaderBar(),
Expanded(
child: CustomScrollView(
slivers: [
SliverFillRemaining(
child: Align(
alignment: Alignment.topCenter,
child: SingleChildScrollView(
controller: keys['page_scroll'],
child: Center(
child: Container(
padding: EdgeInsets.symmetric(
horizontal: pagePadding / 2,
),
constraints: BoxConstraints(
maxWidth: maxWidth + pagePadding * 2,
),
child: IntrinsicHeight(
child: Column(
children: [
roleDropdown('user', {'role': 'ROOT_ADMIN'}),
],
),
),
)
)
),
),
)
],
),
),
]
);
},
),
),
);
The DropdownButton that's included:
Widget roleDropdown(String route, var entry) {
if (entry['role'] == 'USER_FEEDBACK')
return const Text('USER_FEEDBACK', style: TextStyle(color: Colors.red));
if (entry['role'] == 'ROOT_ADMIN' && !isAdmin(types: ['ROLE_ROOT_ADMIN']))
return const Text('ROOT_ADMIN', style: TextStyle(color: Colors.red));
List<String> roles = [
'USER_VIEWER',
'USER_ADMIN',
'ROOT_ADMIN',
];
List<DropdownMenuItem> items = [
DropdownMenuItem(value: 0, child: Row(children: [
const SizedBox(width: modulePadding),
Text(trans[languageCode.value]['user'] ?? "User")
])),
DropdownMenuItem(value: 1, child: Row(children: [
const SizedBox(width: modulePadding),
Text(trans[languageCode.value]['admin'] ?? "Admin")
])),
];
if (isAdmin(types: ['ROLE_ROOT_ADMIN'])) items.add(
DropdownMenuItem(value: 2, child: Row(children: const [
SizedBox(width: modulePadding),
Text("Root admin")
])),
);
return Container(
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(
color: CColors.buttonBackground,
borderRadius: BorderRadius.circular(20),
),
child: SizedBox(height: 31, child: DropdownButtonHideUnderline(
child: DropdownButton(
borderRadius: BorderRadius.circular(25),
style: TextStyle().copyWith(fontSize: 12),
items: items,
value: roles.indexOf(entry['role']),
onChanged: (dynamic value) async {
String valueString = roles[value];
if (entry['role'] == valueString) return;
/// TODO CHANGE ENTRY
// bool success = await changeEntry(type: 'uam', action: 'put', id: entry['auth_id'], status: valueString);
// if (!success) debugPrint('Something went wrong when updating user/key role');
},
isDense: true,
menuMaxHeight: 100,
)
))
);
}

Passing data from page to page firebase flutter

I am trying to pass firebase snapshot data from first page to second page in flutter using GET. I'm able to pass data from one screen to another in debug mode but not in release mode.
I have used a streambuilder on the page and a Future on second . Please where am i going wrong ?
here is code..
first page:
Container(
child: Expanded(
child: StreamBuilder(
stream: FirebaseFirestore.instance
.collection('Songs')
.snapshots(),
builder: (BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(),
);
}
return Container(
color: Colors.white24,
padding: EdgeInsets.all(10),
child: ListView(
children: snapshot.data!.docs.map((document) {
return Container(
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25),
side: BorderSide(
color: Colors.purple, width: 2)),
elevation: 4,
child: ListTile(
title: Text(document['title'],
style: TextStyle(fontSize: 16)),
subtitle: Text(
document['artist'],
style: TextStyle(color: Colors.purple),
),
onTap: () {
Get.to(() => DetailsPage(
piss: document,
post: document.id,
));
},
contentPadding: EdgeInsets.all(20),
leading: Image.asset('assets/logo.png'),
trailing: document['isNew'] == true
? Image.asset(
'assets/new.gif',
)
: null),
),
);
}).toList(),
),
);
}),
),
),
_banner == null
? Container()
: Container(
margin: const EdgeInsets.only(bottom: 12),
height: 52,
child: AdWidget(
ad: _banner!,
),
),
],
),
),
);
}
}
second page
FutureBuilder(
future: getData(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(),
);
} else {
return Expanded(
child: ListView.builder(
itemCount: widget.piss['tileHeaders'].length,
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
setState(() {
_index = index;
counter = counter + 1;
print('COUNTER: $counter');
if (counter == 3) {
_showRewardedAd();
_controller.play();
print("Counter is $counter");
counter = 0;
_createRewardedAd();
}
});
index > 0
? playIt(index)
: _controller
.load(widget.piss['videos'][index]);
},
child: Card(
elevation: 5,
child: Column(
children: [
Container(
height: 100,
child: Row(
children: [
Center(
child: Padding(
padding: EdgeInsets.all(10),
child: Expanded(
child: Image.asset(
"assets/logo.png"),
flex: 2,
// flex: 2,),
),
)),
Expanded(
child: Container(
alignment:
Alignment.topLeft,
child: Column(
children: [
Expanded(
flex: 5,
child: ListTile(
title: Text(
widget.piss[
'tileHeaders']
[index],
style: TextStyle(
fontSize:
26)),
),
),
Expanded(
flex: 5,
child: Row(
mainAxisAlignment:
MainAxisAlignment
.end,
children: [
Container(
child: widget
.piss[
'videos']
[
index]
.toString()
.contains(
'PL')
? Center(
child:
Container(child: playlist()),
)
: Center(
child:
Container(
child:
notPlaylist(),
),
),
),
],
))
],
)),
)
],
))
],
)),
);
}),
);
}
})
Please help

How can I use flutter hero with firebase?

return Padding(
padding: const EdgeInsets.only(top: 0.0),
child: Scaffold(
appBar: AppBar(title: const Text("Announcements")),
backgroundColor: Colors.blueGrey.shade100,
body: StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance.collection('announcement').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const Center(
child: CircularProgressIndicator(),
);
}
return ListView(
children: snapshot.data!.docs.map((DocumentSnapshot document) {
var docData = document.data() as Map;
return Stack(
children: [
Image.network(
docData['announcementURL'],
),
const SizedBox(
height: 20.0,
),
Text(
docData['description'],
style: const TextStyle(
fontSize: 15.0,
),
),
],
);
}).toList(),
);
},
),
),
);
I don't want to do it with the ListTile(). When i clicking on the image requires an explanation line to appear. I made my old project with the Hero() function. But I couldn't do this code. How can I do that?

How to code dynamic FlipCard List with FutureBuilder in Flutter

I am very new at flutter and I tried writing "body: new ListView.builder....." but it does not work, I am getting always red underline. Can you help me to fix this. I am getting the data to the flipcards from json albüm so I think I must use future builder
This is what it looks like, I want multiple cards according to the elements from json:
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
title: const Center(
child: Text(
"Main",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 22.0),
),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25.0),
),
backgroundColor: Colors.green[600],
),
body: Center(
child: FutureBuilder<Album>(
future: futureAlbum,
builder: (context, snapshot) {
if (snapshot.hasData) {
return ListView(
children: [
const SizedBox(height: 10),
Container(
margin: const EdgeInsets.all(15.0),
height: 200,
width: 350,
child: FlipCard(
direction: FlipDirection.HORIZONTAL,
front: Container(
....................
),
back: Container(
.......................
),
),
),
],
);
} else if (snapshot.hasError) {
return ListView(
children: [
SizedBox(height: 10),
Container(
margin: const EdgeInsets.all(15.0),
height: 200,
width: 350,
child: FlipCard(
direction: FlipDirection.HORIZONTAL,
front: Container(
back: Container(
),
),
),
],
);
}
},
),
),
),
);
}

Flutter - How to update single item in pagination list

https://github.com/vedartm/pagination_view
I use the above library for pagination in a flutter.
I want to update single item on tap on heart sign.(without refreshing all items.)
I used paginatio_view library it's work perfect. but i want change pericualr item on tap on heart icon without refresh all list.
https://i.stack.imgur.com/BVof0.png
Expanded(
flex: 1,
child: Padding(
padding: const EdgeInsets.all(5.0),
child: PaginationView < ProductList > (
key: key,
paginationViewType: PaginationViewType.gridView,
scrollDirection: Axis.vertical,
pageFetch: (page) => pageFetch(page),
pullToRefresh: true,
itemBuilder:
(BuildContext context, ProductList user, int index) {
return GridTile(
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: Column(
children: [
Align(
alignment: Alignment.topRight,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: InkWell(
onTap: () => {
controller.addToWishList({
"ProductId": user.productId
}),
key
},
child: Image.asset(
height: 20,
width: 20,
user.flag ?
"assets/images/ic_like_heart.png" :
"assets/images/ic_unlike_heart.png")),
),
),
Expanded(
flex: 1,
child: CachedNetworkImage(
imageUrl: user.image,
imageBuilder: (context, imageProvider) =>
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: imageProvider,
fit: BoxFit.contain,
),
),
),
progressIndicatorBuilder:
(context, url, progress) => Center(
child: CircularProgressIndicator(
value: progress.progress,
),
),
errorWidget: (context, url, error) =>
const Icon(Icons.warning_amber_rounded),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(user.productName),
)
],
),
),
);
},
onError: (dynamic error) =>
const Center(
child: Text(
'Some error occurred',
style: TextStyle(fontSize: 18),
),
),
onEmpty: const Center(
child: Text(
'Sorry! This is empty',
style: TextStyle(fontSize: 18),
),
),
bottomLoader: const Center( // optional
child: CircularProgressIndicator(),
),
initialLoader: const Padding(
padding: EdgeInsets.all(8.0),
child: Center(
child: CircularProgressIndicator(
backgroundColor: Colors.transparent),
),
),
),
),
)
Here is the method to get list.
Future < List < ProductList >> pageFetch(int offset) async {
page = (offset / 10).round() + 1;
_logger.d("Offset number::$offset Page number::$page");
var data = {
'Category': '',
'Search': _search,
'PageNumber': page,
'PageCount': 10
};
return await controller.getProductsList(data, page);
}