Trouble connecting Flutter frontend with Django backend through API - django

I am working on the frontend project using Flutter, and I am trying to connect it to the Django backend using API, I am completely lost on how to do that, can anyone help me, I would appreciate your help. I am very new to Flutter. We have implemented all the APIs with the Django REST framework.
Here is my front-end code for the register page, this code is using Dart language.
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:flutter/src/foundation/key.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import './register2.dart';
class MyClip extends CustomClipper<Rect> {
Rect getClip(Size size) {
return Rect.fromLTWH(0, 0, 100, 100);
}
bool shouldReclip(oldClipper) {
return false;
}
}
class Avatar extends StatefulWidget {
#override
State<Avatar> createState() => _AvatarState();
}
class _AvatarState extends State<Avatar> {
File? image;
Future pickImage() async {
try {
final image = await ImagePicker().pickImage(source: ImageSource.gallery);
if (image == null) return;
final imageTemp = File(image.path);
setState(() => this.image = imageTemp);
} on PlatformException catch (e) {
print('Failed: $e');
}
}
#override
Widget build(BuildContext context) {
return Container(
child: image != null
? ClipOval(
child: Image.file(
image!,
width: 100,
height: 100,
fit: BoxFit.cover,
),
)
: Image.asset('assets/images/icon_sample.jpeg'),
);
}
}
class Regfirst extends StatelessWidget {
#override
Widget build(BuildContext context) {
var bg = 'assets/images/bg.jpeg';
return Material(
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(bg),
fit: BoxFit.cover,
),
),
child: Container(
child: Stack(
alignment: Alignment.center,
children: [
Positioned(
top: 0,
height: 400,
width: 330,
child: Avatar(),
),
Positioned(
top: 350,
height: 300,
width: 330,
child: Column(
//mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Expanded(
child: Row(
children: [
Expanded(
flex: 3,
child: TextField(
decoration: InputDecoration(
hintText: "First name",
hintStyle: TextStyle(
color: Colors.white,
fontSize: 25,
),
labelStyle: TextStyle(
fontSize: 24, color: Colors.white),
border: UnderlineInputBorder(),
),
),
),
SizedBox(width: 40),
Expanded(
flex: 3,
child: TextField(
decoration: InputDecoration(
hintText: "Last name",
hintStyle: TextStyle(
color: Colors.white,
fontSize: 25,
),
labelStyle: TextStyle(
fontSize: 24, color: Colors.white),
border: UnderlineInputBorder(),
),
),
),
],
),
),
Expanded(
child: Row(
children: [
Expanded(
flex: 3,
child: TextField(
decoration: InputDecoration(
hintText: "Email",
hintStyle: TextStyle(
color: Colors.white,
fontSize: 25,
),
labelStyle: TextStyle(
fontSize: 24, color: Colors.white),
border: UnderlineInputBorder(),
),
),
),
SizedBox(width: 40),
Expanded(
flex: 3,
child: TextField(
decoration: InputDecoration(
hintText: "Phone number",
hintStyle: TextStyle(
color: Colors.white,
fontSize: 25,
),
labelStyle: TextStyle(
fontSize: 24, color: Colors.white),
border: UnderlineInputBorder(),
),
),
),
],
),
),
Expanded(
child: Row(
children: [
Expanded(
flex: 3,
child: TextField(
decoration: InputDecoration(
hintText: "Password",
hintStyle: TextStyle(
color: Colors.white,
fontSize: 25,
),
labelStyle: TextStyle(
fontSize: 24, color: Colors.white),
border: UnderlineInputBorder(),
),
),
),
],
),
),
Expanded(
child: Row(
children: [
Expanded(
flex: 3,
child: TextField(
decoration: InputDecoration(
hintText: "Confirm Password",
hintStyle: TextStyle(
color: Colors.white,
fontSize: 25,
),
labelStyle: TextStyle(
fontSize: 24, color: Colors.white),
border: UnderlineInputBorder(),
),
),
),
],
),
),
],
),
),
Positioned(
top: 680,
height: 45,
width: 250,
child: ElevatedButton(
// color: Colors.blueAccent,
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => Regsec()));
},
child: Text(
'Next',
style: TextStyle(fontSize: 30),
),
),
),
],
),
),
),
);
}
}

Related

How to implement a list of markers using Flutter Map?

I have a doubt about how I suppose to implement a list of markers? Or other things? Like, separate this code into a different file to solve this problem. I'm using Flutter Map on my app.
Here's my code with only two markers:
Code
MarkerLayerOptions(
markers: [
Marker(
width: 96,
height: 96,
point: mainPoint,
builder: (ctx) => Container(
child: Column(
children: [
Text(
'IFCE Campus Acaraú',
textAlign: TextAlign.center,
style: TextStyle(color: Colors.pink.shade700),
),
IconButton(
icon: Icon(Icons.location_on),
color: Colors.pink.shade700,
onPressed: () {
showModalBottomSheet(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
context: context,
backgroundColor: Colors.transparent,
builder: (context) => BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20)),
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: <Color>[
Color(0XFFFAEBE8),
Colors.green.shade100
])),
height: 480,
width: MediaQuery.of(context).size.width,
child: SingleChildScrollView(
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Container(
margin: EdgeInsets.only(
bottom: 1, top: 4),
height: 300,
width: 300,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
'https://images.even3.com.br/wtw3LCAjTLmxbRQwr6KI2H-FIKw=/1300x536/smart/even3.blob.core.windows.net/banner/fachadavalendo.a060ab6b7f8d4bf2a52c.jpg'),
fit: BoxFit.cover,
),
borderRadius:
BorderRadius.circular(20),
),
),
SizedBox(
height: 10,
),
Text(
'IFCE Campus Acaraú \nlaboratório do Ecomangueando',
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.green,
fontSize: 15),
),
SizedBox(
height: 10,
),
Text(
'Alguma descrição sobre',
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.normal,
color: Colors.green.shade300),
),
SizedBox(
height: 10,
),
Container(
margin: EdgeInsets.only(
bottom: 4, top: 4),
height: 300,
width: 300,
decoration: BoxDecoration(
color: Colors.black,
borderRadius:
BorderRadius.circular(20),
),
),
],
),
),
)
],
),
),
);
},
),
],
)),
),
Marker(
width: 96,
height: 96,
point: LatLng(-9.83284607465564, -35.90767696029337),
builder: (ctx) => Container(
child: Column(
children: [
Text(
'Reserva Ecológica \ndos Manguezais \nda Lagoa do Roteiro',
textAlign: TextAlign.center,
style: TextStyle(color: Colors.pink.shade700),
),
IconButton(
icon: Icon(Icons.location_on),
color: Colors.pink.shade700,
onPressed: () {
showModalBottomSheet(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
context: context,
backgroundColor: Colors.transparent,
builder: (context) => BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20)),
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: <Color>[
Color(0XFFFAEBE8),
Colors.green.shade100
])),
height: 480,
width: MediaQuery.of(context).size.width,
child: SingleChildScrollView(
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Container(
margin: EdgeInsets.only(
bottom: 1, top: 4),
height: 300,
width: 300,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
'https://images.even3.com.br/wtw3LCAjTLmxbRQwr6KI2H-FIKw=/1300x536/smart/even3.blob.core.windows.net/banner/fachadavalendo.a060ab6b7f8d4bf2a52c.jpg'),
fit: BoxFit.cover,
),
borderRadius:
BorderRadius.circular(20),
),
),
SizedBox(
height: 10,
),
Text(
'IFCE Campus Acaraú \nlaboratório do Ecomangueando',
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.green,
fontSize: 15),
),
SizedBox(
height: 10,
),
Text(
'Alguma descrição sobre',
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.normal,
color: Colors.green.shade300),
),
SizedBox(
height: 10,
),
Container(
margin: EdgeInsets.only(
bottom: 4, top: 4),
height: 300,
width: 300,
decoration: BoxDecoration(
color: Colors.black,
borderRadius:
BorderRadius.circular(20),
),
),
],
),
),
)
],
),
),
);
},
),
],
),
),
),
],
),
See the problem? I have to make almost 20 markers. And only 2 of them is this big. Besides in some point even myself will be confused. What the solution you guys recommend? Thanks in advance who answer me.

Slidable ListTile overlays parent in Flutter

It has some good features that I was looking for, and works with my code
I'm trying to make ToDo app, and I have problem with slidable widget. I'm putting Slidable inside the ListTile element, and it appears to overlay the parent. Actually, if I specify height of the parent list, it doesn't happen, but I can't specify the height of parent list, because it needs to be set automatically as new element is added to the list, this is why I use shrinkWrap property.
EDIT: I found package that does exactly what I need. It has some iOS-like slide features, and even some animations.
https://pub.dev/packages/flutter_swipe_action_cell
Widget build(BuildContext context) {
return Column(
children: [
Container(
margin: EdgeInsets.only(bottom: 20),
child: Container(
child: ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: this.widget.listNotes.length,
itemBuilder: (context, index) {
var content = this.widget.listNotes[index];
return Column(
children: [
Align(
alignment: Alignment.centerLeft,
child: ListTile(
title: Container(
child: Slidable(
controller: slidableController,
actionPane: SlidableStrechActionPane(),
actionExtentRatio: 0.4,
secondaryActions: <Widget>[
SlideAction(
color: Colors.red,
child: Text(
'Delete',
style: TextStyle(
fontSize: 15, color: Colors.white),
maxLines: 1,
),
onTap: () => deleteNote(index),
),
],
child: Row(
children: [
Container(
child: Transform.scale(
scale: 1.7,
child: Radio(
toggleable: true,
value: '${index}' + 'ok',
groupValue: groupVal,
onChanged: (value) {
setState(() {
groupVal = value;
});
},
activeColor: Color(0xffFFBD11),
),
),
),
InkWell(
onTap: () {
print('object');
},
child: Container(
width: 230,
padding:
EdgeInsets.fromLTRB(0, 10, 12, 12),
margin: EdgeInsets.only(left: 5),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Color(0xFFBABABA),
width: 0.5))),
child: Text(
content.note,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w300,
fontSize: 18),
),
),
),
],
),
),
),
),
),
],
);
}),
),
),
Hi #XRSIL your code is wrong, because the slidable widget must be the widget that contains the ListTile, like this example:
ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: this.widget.listNotes.length,
itemBuilder: (context, index) {
return Slidable(
actionPane: SlidableDrawerActionPane(),
child: Container(
child: ListTile(title: Text('Title'),
),
));
}
)

I can't transfer data from a screen to a list, I tried hive, but I was unable to compose the data structure, as it did not generate the g.dart file

family of programmers. I'm new to programming, I'm having a hard time transferring data from a screen to a list, where the user can review the messages sent. Sorry for this one with a silly question like that, but I already tried it in the library, videos and etc. But I did not find the solution, please, could someone help me with this? Thanks! (I've been stuck on this issue for days).
My code:
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:animated_text_kit/animated_text_kit.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:animated_button/animated_button.dart';
import 'package:giffy_dialog/giffy_dialog.dart';
import 'package:mailer/mailer.dart';
import 'package:mailer/smtp_server/gmail.dart';
import 'package:ouvidoria_mvl/main.dart';
// ignore: must_be_immutable
class PaginadeBoasVindasAN extends StatelessWidget {
String _localAn;
String _problemaAn;
File _imagemAn;
File _imagemGaleriaAn;
PaginadeBoasVindasAN(
this._localAn,
this._problemaAn,
this._imagemAn,
this._imagemGaleriaAn,
);
final _formKey = GlobalKey<FormState>();
// Aqui vamos criar o e-mail - smtp
enviarMensagem() async {
String username = '#gmail.com';
String password = '4#';
final smtpServer = gmail(username, password);
// Use the SmtpServer class to configure an SMTP server:
// final smtpServer = SmtpServer('smtp.domain.com');
// See the named arguments of SmtpServer for further configuration
// options.
// Create our message.
final message = Message()
..from = Address('', '')
..recipients.add('#gmail.com')
..ccRecipients.addAll(['destCc1#gmail.com', 'destCc1#gmail.com'])
..bccRecipients.add(Address('destCc1#gmail.com'))
..subject = '$_localAn :: ${DateTime.now()}'
..text = 'LOCAL DA OCORRÊNCIA: $_localAn,n\ OCORRÊNCIA: $_problemaAn';
if ((_imagemAn != null) && (_imagemAn != ""))
message.attachments.add(FileAttachment(_imagemAn,));
if ((_imagemGaleriaAn!= null) && (_imagemGaleriaAn!= ""))
message.attachments.add(FileAttachment(_imagemGaleriaAn,));
try {
final sendReport = await send(message, smtpServer);
print('Mensagem enviada: ' + sendReport.toString());
} on MailerException catch (e) {
print('Mensagem não enviada.');
for (var p in e.problems) {
print('Problema: ${p.code}: ${p.msg}');
}
}
var connection = PersistentConnection(smtpServer);
await connection.send(message);
await connection.close();
}
// HERE THE APP CONFIGURATION IS ENDED
// The Function below blocks the screen rotation, thus allowing the app to stay in vertical mode
void blockgiro() {
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitDown, DeviceOrientation.portraitUp]);
}
#override
Widget build(BuildContext context) {
blockgiro();
return Stack(children: <Widget>[
Scaffold(
backgroundColor: Colors.white,
body: SingleChildScrollView(
padding: EdgeInsets.only(bottom: 20),
child: Container(
margin: EdgeInsets.all(10),
color: Colors.transparent,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
margin: EdgeInsets.only(
left: 1,
bottom: 10,
top: 10,
),
padding: EdgeInsets.all(10),
height: 200,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
blurRadius: 0,
color: Colors.white,
offset: Offset(0, 0))
],
borderRadius: BorderRadius.circular(13),
color: Colors.white),
child:
Image.asset("Assets/image/enviando-loading.gif")),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding: EdgeInsets.only(
bottom: 30, right: 1, left: 1, top: 20),
),
Container(
margin: EdgeInsets.only(
left: 1,
bottom: 10,
top: 5,
),
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
blurRadius: 2,
color: Colors.black54,
offset: Offset(1, 1))
],
borderRadius: BorderRadius.circular(13),
color: Colors.white),
child: Align(
alignment: Alignment.topLeft,
child: SizedBox(
width: 250.0,
child: TypewriterAnimatedTextKit(
pause: Duration(minutes: 10),
speed: Duration(milliseconds: 100),
onTap: () {
print("Tap Event");
},
text: ['The location is this: $_localAn'],
textStyle: TextStyle(
color: Colors.black,
fontSize: 20.0,
fontFamily: "Agne"),
textAlign: TextAlign.start,
),
),
),
),
Container(
margin: EdgeInsets.only(
left: 1,
bottom: 10,
top: 10,
),
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
blurRadius: 4,
color: Colors.black54,
offset: Offset(2, 2))
],
borderRadius: BorderRadius.circular(13),
color: Colors.white),
child: Align(
alignment: Alignment.topLeft,
child: SizedBox(
width: 1000.0,
child: TypewriterAnimatedTextKit(
pause: Duration(minutes: 10),
onTap: () {
print("Tap Event");
},
text: [
'Its occurrence: $_problemaAn',
],
textStyle: TextStyle(
color: Colors.black,
fontSize: 20.0,
fontFamily: "Agne"),
textAlign: TextAlign.justify,
curve: Curves.linear),
),
)),
Container(
margin: EdgeInsets.all(10),
padding: EdgeInsets.all(10),
child: _imagemAn != null
? Image.file(
_imagemAn,
fit: BoxFit.scaleDown,
)
: Center(
child: Text(
'',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w400),
),
),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
blurRadius: 1,
color: Colors.transparent,
offset: Offset(1, 1))
],
borderRadius: BorderRadius.circular(30),
color: Colors.transparent),
),Container(
margin: EdgeInsets.all(10),
padding: EdgeInsets.all(10),
child: _imagemGaleriaAn != null
? Image.file(
_imagemGaleriaAn,
fit: BoxFit.scaleDown,
)
: Center(
child: Text(
'Capture a photo',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w400),
),
),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
blurRadius: 1,
color: Colors.transparent,
offset: Offset(1, 1))
],
borderRadius: BorderRadius.circular(30),
color: Colors.transparent),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TypewriterAnimatedTextKit(
pause: Duration(minutes: 10),
onTap: () {
print("Select below");
},
text: [
'Need to edit your message?',
],
textStyle: TextStyle(
fontWeight: FontWeight.w600,
color: Colors.lightBlueAccent,
fontSize: 20.0,
fontFamily: "Agne"),
textAlign: TextAlign.center,
curve: Curves.linear),
],
),
//INICIO DOS BOTOES SIM E NAO
Container(
padding: EdgeInsets.only(bottom: 50),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
margin: EdgeInsets.only(
bottom: 2, top: 2, right: 55),
alignment: Alignment.centerLeft,
child: AnimatedButton(
shape: BoxShape.rectangle,
child: Text(
'Edit',
style: TextStyle(
fontSize: 15,
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
onPressed: () {
Navigator.pop(context);
},
width: 70,
height: 40,
color: Theme.of(context).primaryColor,
shadowDegree: ShadowDegree.dark,
enabled: true,
),
),
//ACIMA SIM, ABAIXO NÃO
Container(
margin: EdgeInsets.only(
bottom: 2, top: 2, left: 55),
alignment: Alignment.centerRight,
child: AnimatedButton(
child: const Text(
'Send',
style: TextStyle(
fontSize: 19,
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
onPressed: () {
enviarMensagem();
showDialog(
context: context,
builder: (_) => AssetGiffyDialog(
image: Image.asset(
'Assets/image/Correta.gif'),
title: Text(
'Success',
style: TextStyle(
fontSize: 22.0,
fontWeight:
FontWeight.w600),
),
description: Text(
'Hi, we received your message',
style: TextStyle(),
),
entryAnimation:
EntryAnimation.BOTTOM_RIGHT,
onlyCancelButton: false,
onOkButtonPressed: () async {
final result =
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
splashScreen()));
},
onlyOkButton: true,
));
},
width: 70,
height: 40,
color: Theme.of(context).primaryColor,
shadowDegree: ShadowDegree.dark,
enabled: true,
),
)
],
),
],
),
Container(
padding: EdgeInsets.only(bottom: 50),
),
]))),
)
]);
}
}

Flutter show a specific list of items intto different profile pages

I created 2 classes in dart, to use in flutter, the first is used to a list and a profile page for a trainer, the second class is for the training.
if I want to show the instructor's training list in his profilepage what can I do?
for example the train "Ciccio" has only a Traing and i want see only that traing.
class IstruttoreClasse{
int idIstruttore;
String nome;
List allenamento;
IstruttoreClasse({
this.idIstruttore,this.nome, this.allenamento});
}
List<IstruttoreClasse> istruttori =[
IstruttoreClasse(
idIstruttore: 1,
nome: "Ciccio", ),
IstruttoreClasse(
idIstruttore: 2,
nome: "Valeria",
),
];
class Traing extends IstruttoreClasse{
String nomeTraing;
int idTraing ,numEsercizi, calorie, minuti, numSet ;
Traing({this.calorie,this.idTraing,this.minuti,this.nomeTraing,this.numEsercizi, this.numSet, int idIstruttore, String nome});
}
List<Traing> allenamentoList =[
Traing(
idIstruttore: 1,
nome: "Ciccio",
idTraing: 1,
calorie: 200,
minuti: 45,
numEsercizi: 12,
numSet: 2,
nomeTraing: "Totalbody"
),
Traing(
idIstruttore: 2,
nome: "Valeria",
idTraing: 2,
calorie: 200,
minuti: 45,
numEsercizi: 12,
numSet: 2,
nomeTraing: "Zumba"
),
];
this is the profile page code
import 'package:flutter/material.dart';
import 'package:tesiapp/src/models/classeIstruttore.dart';
import 'package:tesiapp/theme/costanti.dart';
class ProfiloTrainer extends StatelessWidget {
final IstruttoreClasse istruttoreClasse;
const ProfiloTrainer({Key key, this.istruttoreClasse}) : super(key: key);
#override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Scaffold(
backgroundColor: Colors.grey,
body: SafeArea(
child: Stack(
children: <Widget>[
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Colors.grey[300], Colors.grey[700]],
),
),
),
Positioned(
top: 0,
left: 0,
right: 0,
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: size.height * 0.06,
width: size.width * 1,
color: Colors.transparent,
child: Row(
children: [
InkWell(
onTap: () {
Navigator.pop(context);
},
child: Container(
child: Icon(Icons.arrow_back),
),
),
],
),
),
),
Padding(
padding:
const EdgeInsets.only(right: 8.0, left: 8.0, top: 45.0),
child: Container(
height: size.height * 0.3,
width: size.width * 1,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30),
bottomLeft: Radius.circular(30),
bottomRight: Radius.circular(30),
),
color: Colors.transparent,
),
// color: Color.fromRGBO(255, 255, 255, 0.4)),
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(istruttoreClasse.nome,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 30)),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text("Guarino",
style: TextStyle(fontSize: 30)),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"lore ipsum bio del trainer chi sono io e cosa faccio dove lavoro"),
)
],
),
),
),
],
),
),
),
),
Padding(
padding:
const EdgeInsets.only(top: 10.0, left: 8.0, right: 8.0),
child: Container(
height: size.height * 0.45,
width: size.width * 1,
decoration: BoxDecoration(
color: Colors.transparent,
// color: Color.fromRGBO(255, 255, 255, 0.4),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(25),
topRight: Radius.circular(25),
bottomLeft: Radius.circular(25),
bottomRight: Radius.circular(25),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Text("Allenemanti",
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 20)),
),
Expanded(
child: ListView.builder(
itemCount: allenamentoList.length,
itemBuilder: (context, index) =>
CasellaAllenamenti(size: size),
),
),
],
),
),
)
],
),
),
],
),
),
);
}
}
class CasellaAllenamenti extends StatelessWidget {
const CasellaAllenamenti({
Key key,
#required this.size,
}) : super(key: key);
final Size size;
#override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Container(
decoration: BoxDecoration(
color: Colors.transparent,
),
width: size.width * 0.65,
height: size.height * 0.20,
child: Stack(
children: [
Container(
decoration: BoxDecoration(
boxShadow: [kDefaultShadow],
color: Colors.blue,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(25),
topRight: Radius.circular(25),
bottomLeft: Radius.circular(25),
bottomRight: Radius.circular(25),
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
alignment: Alignment.bottomLeft,
child: Text(
"Totalbody",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 18),
),
),
),
],
),
),
Container(
height: size.height * 0.05,
width: size.width * 0.65,
decoration: BoxDecoration(
color: Colors.transparent,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text(
"Tempo: m.45",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
),
Text(
"calorie: 350",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
)
],
),
),
],
),
);
}
}
Try this
// ...
ListView.builder(
itemCount: allenamentoList.length,
itebrmBuilder: (context, index) {
return ListTile(
title: Text(allenamentoList[index].nome),
);
},
),
// ...
Edit
If you want to access specific item of your List, provide it's index like this
Text(allenamentoList[0].nome),

How can I assign any iterable to a widget?

error: The element type 'List' can't be assigned to the list type 'Widget'.
I am learning to make flutter apps and this same code is illustrated by other person who is teaching me in that video and it works fine. Maybe its a version problem.
return Card(
margin: EdgeInsets.all(10),
child: Column(
children: [
ListTile(
title: Text('₹${widget.order.amount}'),
subtitle: Text(DateFormat('dd/MM/yyyy hh:mm').format(widget.order.dateTime)),
trailing: IconButton(icon: Icon(_expanded ? Icons.expand_less :Icons.expand_more),
onPressed: (){
setState(() {
_expanded = !_expanded;
});
}),
),
if(_expanded)
Container(
height: min(widget.order.products.length * 20.0 + 10, 100),
child: ListView(
children: [
widget.order.products.map((prod) => Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(prod.title,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold
),
),
Text('₹${prod.quantity}x ₹${prod.price}',
style: TextStyle(
fontSize: 18,
color: Colors.grey
),
)
],
),).toList()
],
),
)
],
),
);
You should remove [ ] while mapping, check below
ListView(
children: widget.order.products.map((prod) => Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
prod.title,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold
),
),
Text(
'₹${prod.quantity}x ₹${prod.price}',
style: TextStyle(
fontSize: 18,
color: Colors.grey
),
)
],
),).toList(),
),
just remove the [] of the children of the ListView
Your code should be as follows:
return Card(
margin: EdgeInsets.all(10),
child: Column(
children: [
ListTile(
title: Text('₹${widget.order.amount}'),
subtitle: Text(DateFormat('dd/MM/yyyy hh:mm').format(widget.order.dateTime)),
trailing: IconButton(icon: Icon(_expanded ? Icons.expand_less :Icons.expand_more),
onPressed: (){
setState(() {
_expanded = !_expanded;
});
}),
),
if(_expanded)
Container(
height: min(widget.order.products.length * 20.0 + 10, 100),
child: ListView(
children:
widget.order.products.map((prod) => Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(prod.title,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold
),
),
Text('₹${prod.quantity}x ₹${prod.price}',
style: TextStyle(
fontSize: 18,
color: Colors.grey
),
)
],
),).toList()
,
),
)
],
),
);
Since you are already creating the list of widgets in the .toList(), it shouldn't be surrounded by []
The ListView widget requires 'List of Widgets', however, you're providing it with nested list of widgets as you're using map and returning 'Rows' while converting them into a list. So, in short ListView renders list of rows inside another list.
You may use the 'Spread Operator' to resolve the issue. It will take the each Row widget in nested list and place it as a direct child of 'ListView'.
Using three dots '...' before mapping the product will resolve the error. Like this;
"...widget.order.products.map((prod) => Row("
OR
just remove the [] of the children of the ListView. It will do the same trick.