How to code dynamic FlipCard List with FutureBuilder in Flutter - 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(
),
),
),
],
);
}
},
),
),
),
);
}

Related

How to Create This Tab View in Flutter with SyncFusion? What is the Name of the Widget?

I am trying to create this kind of tab view but I am so confused what the name of the widget is in Flutter and SyncFusion. I want to create this chart with 2 tab, the first tab is voltage chart and the second one is current chart. Thank you.
Here's the picture:
Here's my current code:
#override
Widget build(BuildContext context) {
return Scaffold(
drawer: const SideMenu(),
body: FutureBuilder(
future: getData2(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Loading();
} else if (snapshot.hasError) {
return Text(snapshot.hasError.toString());
} else {
final themeChange = Provider.of<DarkThemeProvider>(context);
return SafeArea(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (Responsive.isDesktop(context))
const Expanded(
child: SideMenu(),
),
Expanded(
flex: 5,
child: SingleChildScrollView(
primary: false,
padding: const EdgeInsets.all(defaultPadding),
child: Column(
children: [
Container(
padding: const EdgeInsets.all(defaultPadding),
child: const Header(),
),
const SizedBox(height: defaultPadding),
Container(
decoration: BoxDecoration(
color: themeChange.darkTheme
? secondaryColor
: quarterColor,
borderRadius:
const BorderRadius.all(Radius.circular(10)),
),
padding: const EdgeInsets.all(defaultPadding),
child: DefaultTabController(
length: 2,
child: Column(
children: [
SizedBox(
height: 40.0,
child: TabBar(
controller: _tabController,
indicator: const UnderlineTabIndicator(
borderSide: BorderSide(
color: Colors.yellow,
width: 3.0,
),
),
indicatorPadding:
const EdgeInsets.all(2.0),
tabs: const [
Text(
'Voltages Chart',
),
Text(
'Currents Chart',
),
],
),
),
],
),
),
),
Expanded(
child: TabBarView(
controller: _tabController,
children: <Widget>[
ListView.builder(
itemCount: 100,
itemBuilder: (context, int index) {
return const DwpVoltageCharts();
},
),
ListView.builder(
itemCount: 100,
itemBuilder: (context, int index) {
return const DwpCurrentCharts();
},
),
],
),
),
const SizedBox(height: defaultPadding),
Container(
padding: const EdgeInsets.all(defaultPadding),
decoration: BoxDecoration(
color: themeChange.darkTheme
? secondaryColor
: quarterColor,
borderRadius:
const BorderRadius.all(Radius.circular(10)),
),
child: const Center(
child: PowerChart(),
),
),
],
),
),
)
],
),
);
}
}),
);
}
}
Please this is my currents code and I don't know how to make it works because I am really new about it. Thank You.
You can achieve your requirement using the DefaultTabController, TabBar and TabBarView widgets available in the flutter framework. We have created a simple sample in which we have achieved your requirement to switch between two tabs to view the voltage and current chart and attached the sample below for reference.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/i407342-45112383

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?

I want to get a download URL from firebase Storage

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

Draggable object cannot be moved in DragTarget widget flutter

I am trying to move/drag drop widget inside DragTarget but don't know what is the issue. Here is my code:
return Scaffold(
drawer: DrawerWidget(),
appBar: AppBar(
backgroundColor: Colors.white,
title: Text(
'Table Layout',
style: Theme.of(context).textTheme.title.merge(
TextStyle(letterSpacing: 1.3),
),
),
centerTitle: true,
elevation: 0,
),
body: Container(
child: Row(
children: [
Container(
color: Colors.blue[100],
width: MediaQuery.of(context).size.width * 0.30,
child: ListView.separated(
padding: const EdgeInsets.all(16.0),
itemCount: 3,
separatorBuilder: (context, index) {
return const SizedBox(
height: 12.0,
);
},
itemBuilder: (context, index) {
return Draggable<String>(
data: images[index],
dragAnchor: DragAnchor.pointer,
feedback: MenuListItem(
photoProvider: images[index],
),
child: MenuListItem(
photoProvider: images[index],
),
);
},
),
),
Expanded(
child: Container(
height: double.infinity,
width: double.infinity,
color: Colors.grey,
child: DragTarget<String>(
builder: (context, candidateItems, rejectedItems) {
return Stack(
children: targetList.map((image) {
return Draggable<String>(
data: image,
dragAnchor: DragAnchor.pointer,
childWhenDragging: Container(),
feedback: MenuListItem(
photoProvider: image,
),
child: MenuListItem(
photoProvider: image,
),
);
}).toList(),
);
},
onWillAccept: (data) {
return true;
},
onAccept: (item) {
},
),
),
),
],
),
),
);
When I run the app the element appears at the top left corner. I am trying to place that widget anywhere inside DragTarget by dragging but after dragging it return to its original place.
Can anyone help me please.
Thanks

How to Flutter Background Image Positioning

When I write the Background Image codes in the main.dart file that I shared with you below, the data I want to use remains under Image. How can I solve this problem? I am aware that I wrote the part about Background in the wrong place, but I didn't know where to write it. Thank you for your help.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Weather App',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
backgroundColor: Colors.tealAccent,
appBar: AppBar(
title: Text('Flutter Weather App'),
),
body: Center(
child: Column(children: <Widget>[
//WEATHER DATA
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: weatherData != null
? Weather(weather: weatherData)
: Container(),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: isLoading
? CircularProgressIndicator(
strokeWidth: 2.0,
valueColor:
new AlwaysStoppedAnimation(Colors.black),
)
: IconButton(
icon: new Icon(Icons.refresh),
tooltip: 'Refresh',
onPressed: () async {
await loadWeather();
},
color: Colors.black,
),
),
],
),
),
//BACKGROUND IMAGE
Container(
height: 501.7,
width: 420.0,
decoration: BoxDecoration(
image: DecorationImage(
image: isweatherDataLoaded //this
? HandleError()
: images["clear"],
fit: BoxFit.fill,
),
shape: BoxShape.rectangle,
),
),
//FUTURE FORECAST WEATHER DATA
SafeArea(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: 200.0,
child: forecastData != null
? ListView.builder(
itemCount: forecastData.list.length,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) => WeatherItem(
weather: forecastData.list.elementAt(index)))
: Container(),
),
),
)
]))),
);
}
Wherever I write, it just didn't work. I want you to show me a way. If you want, I can share the rest of my codes with you. Happy Codding! Thanks..
I'd suggest moving the container with the background image up in the hierarchy, like this:
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Weather App',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
backgroundColor: Colors.tealAccent,
appBar: AppBar(
title: Text('Flutter Weather App'),
),
body: Container(
height: 501.7,
width: 420.0,
decoration: BoxDecoration(
image: DecorationImage(
image: isweatherDataLoaded //this
? HandleError()
: images["clear"],
fit: BoxFit.fill,
),
shape: BoxShape.rectangle,
),
child: Center(
child: Column(children: <Widget>[
//WEATHER DATA
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: weatherData != null
? Weather(weather: weatherData)
: Container(),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: isLoading
? CircularProgressIndicator(
strokeWidth: 2.0,
valueColor:
new AlwaysStoppedAnimation(Colors.black),
)
: IconButton(
icon: new Icon(Icons.refresh),
tooltip: 'Refresh',
onPressed: () async {
await loadWeather();
},
color: Colors.black,
),
),
],
),
),
//FUTURE FORECAST WEATHER DATA
SafeArea(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: 200.0,
child: forecastData != null
? ListView.builder(
itemCount: forecastData.list.length,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) => WeatherItem(
weather: forecastData.list.elementAt(index)))
: Container(),
),
),
)
])),
)),
);
}