First Flutter Application and i got stuck with an error - file

i was trying to pickup image from gallery and update it to UI. But on performing this it shows an error in profile.dart file at line 56.
The error occurs at _image.
The argument type 'File(where File is defined in
D:\Softwares\flutter\bin\cache\pkg\sky_engine\lib\html\html_dart2js.dart)'
can't be assigned to the parameter type 'File(where File is defined in
D:\Softwares\flutter\bin\caches\pkg\sky_engine\lib\io\file.dart)'
the complete code.
Main.dart
import 'package:flutter/material.dart';
import 'package:udharibook/Screens/SplashScreen.dart';
import 'package:udharibook/Screens/UserProfile.dart';
void main(){
runApp(
MaterialApp(
title: 'Udhari Book',
home:UserProfile(),
debugShowCheckedModeBanner: false,
theme: ThemeData(
backgroundColor: Color.fromRGBO(242, 242, 242, 1.0)
),
)
);
}
ProfilePage
import 'dart:html';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:image_picker/image_picker.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:path/path.dart';
class UserProfile extends StatefulWidget {
#override
_UserProfileState createState() => _UserProfileState();
}
class _UserProfileState extends State<UserProfile> {
File _image;
TextEditingController nameController =TextEditingController()..text='Mehul Jain';
TextEditingController mobileController =TextEditingController()..text='8856061841';
TextEditingController emailController =TextEditingController()..text='mehuljain3698#gmail.com';
TextEditingController addressController =TextEditingController()..text='Maharashtra';
#override
Widget build(BuildContext context) {
Future getImage() async{
var image=await ImagePicker.pickImage(source: ImageSource.gallery);
setState(() {
_image=image as File;
print('Image Path $_image');
});
}
return Scaffold(
resizeToAvoidBottomPadding: false,
appBar: AppBar(
title: Text('User Profile'),
backgroundColor: Color.fromRGBO(162, 42, 43, 1.0),
),
body: Builder(
builder: (context) => Container(
child: Column(
children: <Widget>[
SizedBox(
height: 20.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Align(
alignment: Alignment.center,
child: CircleAvatar(
radius: 50,
backgroundColor: Color.fromRGBO(162, 42, 43, 1.0),
child: ClipOval(
child: SizedBox(
height: 180.0,
width: 180.0,
child:_image!=null?
Image.file(_image,fit: BoxFit.fill):
Image.network(
'https://randomwordgenerator.com/img/picture-generator/55e4d5464f5ba914f1dc8460962e33791c3ad6e04e5074417d2d73dc934bcd_640.jpg',
fit: BoxFit.fill,
)),
),
),
),
Padding(
padding: EdgeInsets.only(top: 60.0),
child: IconButton(
icon: Icon(Icons.camera_alt), onPressed: () {
getImage();
}),
)
],
),
Padding(
padding: EdgeInsets.only(top:20.0,left: 10.0,right: 10.0),
child:SizedBox(
height: 40.0,
child: TextField(
controller: nameController,
decoration: InputDecoration(
labelText: 'Full Name',
labelStyle:
TextStyle(fontFamily: 'Exo2', color: Colors.grey),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0)
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
borderSide: BorderSide(
color:
Color.fromRGBO(162, 42, 43, 1.0)
)
)
),
),
)),
Padding(
padding: EdgeInsets.only(top:15.0,left: 10.0,right: 10.0),
child:SizedBox(
height: 40.0,
child: TextField(
controller: mobileController,
enabled: false,
keyboardType:TextInputType.phone,
decoration: InputDecoration(
labelText: 'Mobile Number',
labelStyle:
TextStyle(fontFamily: 'Exo2', color: Colors.grey),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0)),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
borderSide: BorderSide(
color:
Color.fromRGBO(162, 42, 43, 1.0)
)
)
),
),
)),
Padding(
padding: EdgeInsets.only(top:15.0,left: 10.0,right: 10.0),
child:SizedBox(
height: 40.0,
child: TextField(
controller: emailController,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
labelText: 'Email (Optional)',
labelStyle:
TextStyle(fontFamily: 'Exo2', color: Colors.grey),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0)
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
borderSide: BorderSide(
color:
Color.fromRGBO(162, 42, 43, 1.0)
)
)
),
),
)),
Padding(
padding: EdgeInsets.only(top:15.0,left: 10.0,right: 10.0,bottom: 30.0),
child: TextField(
maxLines: 3,
maxLengthEnforced: true,
controller: addressController,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
labelText: 'Address (Optional)',
labelStyle:
TextStyle(fontFamily: 'Exo2', color: Colors.grey),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0)
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
borderSide: BorderSide(
color:
Color.fromRGBO(162, 42, 43, 1.0)
)
)
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
SizedBox(
width:130.0,
height: 50.0,
child:RaisedButton(
color: Color.fromRGBO(162, 42, 43, 1.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0)
),
onPressed: (){
Navigator.of(context).pop();
},
elevation: 4.0,
splashColor: Colors.blueGrey,
child: Text(
'Save',
style: TextStyle(
color:Colors.white,fontSize: 22.0,fontFamily: 'Exo2'
),
),
)),
SizedBox(
width:130.0,
height:50.0,
child:RaisedButton(
color: Color.fromRGBO(162, 42, 43, 1.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0)
),
onPressed: (){
Navigator.of(context).pop();
},
elevation: 4.0,
splashColor: Colors.blueGrey,
child: Text(
'Cancel',
style: TextStyle(
color:Colors.white,fontSize: 22.0,fontFamily: 'Exo2'
),
),
))
],
)
],
),
),
),
);
}
}

Welcome To Flutter. I am sorry that you are experiencing this error! Trust me, Flutter is really User friendly so soon you will get the hang of it :)
So it appears that this error is appearing due to a conflict within 2 or more imports that use File. Look at this thread: File cant be assigned with ImagePicker Flutter

Related

i can't display my data from the database

so this is the create quiz interface where the teacher can insert the title of the quiz , the question and the option
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:mr_quiz/DB_helper.dart';
import 'package:random_string/random_string.dart';
import 'DB_helper.dart';
import 'question.dart';
import 'qcm.dart';
import 'choix.dart';
import 'folder.dart';
class Create_Quiz extends StatefulWidget {
#override
_Create_QuizState createState() => _Create_QuizState();
}
class _Create_QuizState extends State<Create_Quiz> {
bool choix = false;
late String question;
late String option;
late String titre;
String qst_id=randomAlphaNumeric(16);
String op_id=randomAlphaNumeric(16);
String qcm_id=randomAlphaNumeric(16);
TextEditingController titre_ctrl=TextEditingController();
TextEditingController qst_ctrl=TextEditingController();
TextEditingController choix_ctrl=TextEditingController();
add_qst(Question question){
DB_helper.instance.insertquestion(question);
print('question ajoutée');
}
add_qcm(Qcm qcm){
DB_helper.instance.insertqcm(qcm);
print('qcm ajouté');
}
add_choix(Choix choix){
DB_helper.instance.insertchoix(choix);
print('choix ajouté');
}
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
fontFamily: 'HindGuntur',
),
debugShowCheckedModeBanner: false,
title: 'Mr.Quiz',
routes: {
'/folder': (BuildContext context) => Folder()},
home: Builder(builder: (context) => Scaffold(
backgroundColor: Colors.white,
resizeToAvoidBottomInset: false,
appBar: AppBar(
backgroundColor: Colors.white,
title: Text('QCM', style: TextStyle(
color: Colors.black, fontWeight: FontWeight.bold),),
centerTitle: true,
elevation: 0.0,
leading: IconButton(icon: Icon(Icons.arrow_back),
onPressed: () {},
color: Colors.deepPurple,),
),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Center(child: Container(
height: 160.0,
width: 650.0,
margin: EdgeInsets.fromLTRB(30, 15, 30, 15),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
color: Colors.deepPurple.shade50,),
child: Column(
children: <Widget>[
SizedBox(height: 15.0,),
Text("Entrez le titre du QCM:",
style: TextStyle(fontWeight: FontWeight.bold,),
),
Container(
width: 300.0,
child: TextFormField(
controller: titre_ctrl,
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
contentPadding: EdgeInsets.fromLTRB(20, 10, 5,
10),
hintText: 'Titre',
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.deepPurple,),
borderRadius: BorderRadius.circular(30.0),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.deepPurple.shade200,),
borderRadius: BorderRadius.circular(30.0),
),
),
),
),
],
),
),
),
SizedBox(height: 20.0,),
Container(
width: 350.0,
child: TextFormField(
controller: qst_ctrl,
decoration: InputDecoration(
contentPadding: EdgeInsets.fromLTRB(10, 10, 10, 10),
hintText: 'Question ',
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.deepPurple.shade100,),
borderRadius: BorderRadius.circular(30.0),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.deepPurple.shade200,),
borderRadius: BorderRadius.circular(30.0),
),
),
),
),
SizedBox(height: 20.0,),
Row(
children: [
Expanded(
flex: 6,
child: TextFormField(
controller: choix_ctrl,
decoration: InputDecoration(
hintText: "option ",
contentPadding: EdgeInsets.fromLTRB(20, 10, 10, 10),
),
),
),
Flexible(
child: SizedBox(
width: 5,
child: Checkbox(value: choix,
onChanged: (val) {
setState(() {
choix= val!;
});
},
activeColor: Colors.deepPurple,
checkColor: Colors.white,
),
),
)
],
),
Row(
children: <Widget>[
SizedBox(width: 120.0),
Icon(Icons.add_circle_outline, color: Colors.deepPurple,
size: 22.0,),
TextButton(
child: Text(
'ajouter un choix', textAlign: TextAlign.center,
style: TextStyle(
color: Colors.deepPurple, fontSize: 16.0),),
onPressed: () {setState(() {
option=choix_ctrl.text;
});
Choix choice =new Choix(op_id,option,choix);
add_choix(choice);
choix_ctrl.clear();},
),
],
),
SizedBox(height: 30.0,),
Column(
children: <Widget>[
ElevatedButton(style: ElevatedButton.styleFrom(
primary: Colors.deepPurple.shade200,
fixedSize: Size(300.0, 50.0),
elevation: 0.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0)),
),
child:
Text('Ajouter Question',
style: TextStyle(fontSize: 16.0),),
onPressed: () {setState(() {
question=qst_ctrl.text;
});
Question qst =new Question(qst_id,question);
add_qst(qst);
qst_ctrl.clear();},),
SizedBox(height: 20.0,),
ElevatedButton(style: ElevatedButton.styleFrom(
primary: Colors.indigo.shade400,
fixedSize: Size(250.0, 50.0),
elevation: 0.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0)),
),
child:
Text(
'valider mon QCM', style: TextStyle(fontSize: 16.0),),
onPressed: () {setState(() {
titre=titre_ctrl.text;
});
Qcm qcm =new Qcm(qcm_id,titre);
add_qcm(qcm);
Navigator.pushNamed(context, '/folder');
},),
],
),
SizedBox(height: 10.0,),
],),
),
),
)
);
}`
this is the folder interface where the quiz title is displayed
import 'package:flutter/material.dart';
import 'DB_helper.dart';
import'package:mr_quiz/createquiz.dart';
import 'qcm.dart';
import 'package:mr_quiz/question.dart';
import 'package:mr_quiz/choix.dart';
class Folder extends StatefulWidget {
const Folder({Key? key}) : super(key: key);
#override
_FolderState createState() => _FolderState();
}
class _FolderState extends State<Folder> {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
fontFamily: 'HindGuntur',
),
debugShowCheckedModeBanner: false,
title: 'Mes QCM',
home: Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: Colors.white,
appBar: AppBar(backgroundColor: Colors.deepPurple.shade200,
elevation: 0.0,
centerTitle: true,
title: Text(
"Mes QCM",
style:
TextStyle(
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
),
body:FutureBuilder<List<Qcm>>(
future : DB_helper.instance.qcms(),
builder: (BuildContext context, AsyncSnapshot<List<Qcm>> snapshot) {
if (snapshot.hasData) {
List<Qcm>? qcms = snapshot.data;
return ListView.builder(
itemCount: qcms?.length,
itemBuilder: (context, index){
final qcm = qcms![index];
return Dismissible(key: Key(qcm.qcm_id),
onDismissed: (direction){
setState(() {
DB_helper.instance.deleteprofil(qcm.qcm_id);
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("${qcm.titre} supprimé")));
},
background: Container(color: Colors.red),
child: ProfWidget(qcm: qcm, ));
},
);
} else {
return Center(child: CircularProgressIndicator());
}
}
),
)
);
}
}
class ProfWidget extends StatelessWidget {
const ProfWidget({Key? key, required this.qcm}) : super(key: key);
final Qcm qcm;
#override
Widget build(BuildContext context) {
return GestureDetector(
onTap: (){
},
child: Card(
margin: EdgeInsets.all(8),
elevation: 8,
child: Row(
children: [
Padding(
padding: EdgeInsets.all(8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.only(bottom: 8),
child: Text(qcm.titre,
style:
TextStyle(fontWeight: FontWeight.bold, fontSize: 20)),
),
],
),
)
],
),
),
);
}
}
only the loading indicator is showing could anyone please help me solve this problem , and also can anyone please tell me how to display the data in the playquiz interface , we have a table for each model and they're related to each other with foreign keys but i don't know how to display data from them like i want to display the questions that belong to the same quiz and the options for each question

List view using array list with name image date in flutter

How to get data from static or dynamic list and set to list view or grid view
If you want to convert your list of data into a ListView of widgets you can map the data list to your resultant widget list. Follow the code below:
class TestPage extends StatefulWidget {
#override
_TestPageState createState() => _TestPageState();
}
class _TestPageState extends State<TestPage> {
List<Data> dataList = [
Data(name: "Demo name",date: DateTime.now(),description: "Dummy long description",imageURL: 'https://m.files.bbci.co.uk/modules/bbc-morph-sport-seo-meta/1.20.8/images/bbc-sport-logo.png'),
Data(name: "Demo name",date: DateTime.now(),description: "Dummy long description",imageURL: 'https://m.files.bbci.co.uk/modules/bbc-morph-sport-seo-meta/1.20.8/images/bbc-sport-logo.png'),
Data(name: "Demo name",date: DateTime.now(),description: "Dummy long description",imageURL: 'https://m.files.bbci.co.uk/modules/bbc-morph-sport-seo-meta/1.20.8/images/bbc-sport-logo.png'),
Data(name: "Demo name",date: DateTime.now(),description: "Dummy long description",imageURL: 'https://m.files.bbci.co.uk/modules/bbc-morph-sport-seo-meta/1.20.8/images/bbc-sport-logo.png'),
];
#override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return Scaffold(
body: Container(
width: width,
height: height,
child: ListView(
scrollDirection: Axis.vertical,
children: dataList.map((data){
return Container(
width: width,height: 80,
decoration: BoxDecoration(border: Border(bottom: BorderSide(width: 1.5,color: Colors.black))),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(width: 50,height: 50,decoration: BoxDecoration(image: DecorationImage(image: NetworkImage(data.imageURL))),),
Column(
mainAxisSize: MainAxisSize.max,
children: [
Text(data.name),
Expanded(child: Text(data.description)),
],
),
Text(data.date.toString());
],
),
);
}).toList(),
),
),
);
}
}
class Data {
String name;
String imageURL;
String description;
DateTime date;
Data({this.name,this.imageURL,this.date,this.description});
}
Check the above code based on your requirement.
List dataList = [
Data(
name: "Title",date: "12/03/2021",description: "Description",imageURL:'https://m.files.bbci.co.uk/modules/bbc-morph-sport-seo-meta/1.20.8/images/bbc-sport-logo.png'),
];
#override
Widget build(BuildContext context) {
double width = MediaQuery
.of(context)
.size
.width;
double height = MediaQuery
.of(context)
.size
.height;
return Scaffold(
appBar: new AppBar(
bottomOpacity: 0.0,
elevation: 0.0,
backgroundColor: Color(0xFF104C57),
title: new Text("Notification"),
leading: new IconButton(
icon: new Icon(Icons.arrow_back),
onPressed: () => Navigator.of(context).pop(),
),
),
body: SingleChildScrollView(
child: Container(
child: Card(
margin: EdgeInsets.only(left: 7.0, right: 7.0),
child: Container(
width: width,
height: height,
child: ListView(
scrollDirection: Axis.vertical,
children: dataList.map((data) {
return Container(
margin: EdgeInsets.only(left: 6.0, right: 6.0, top: 10.0),
width: width,
height: 80,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5)),
border: Border.all(
color: Color(0xFFDCDADB),
width: 0.5,
),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
width: 10,
),
Container(
width: 65,
height: 65,
decoration: BoxDecoration(
image: DecorationImage(
image: ExactAssetImage(
'lib/images/notificationicon.png',
),
)),
),
SizedBox(
width: 10,
),
Container(
width: 145,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
SizedBox(
height: 20,
),
Text(
data.name,
style: TextStyle(
fontSize: 12.0,
//fontWeight: FontWeight.w700,
color: Color(0xFF75778A),
fontWeight: FontWeight.w500,
),
),
Expanded(
child: Text(
data.description,
style: TextStyle(
fontSize: 12.0,
//fontWeight: FontWeight.w700,
color: Color(0xFF868C9A),
),
)),
],
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
SizedBox(
height: 20,
),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text(
"Date : ",
style: TextStyle(
fontSize: 12.0,
color: Color(0xFF868C9A),
),
),
Text(
data.date,
style: TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.w500,
color: Color(0xFF6A7180),
),
),
],
),
],
),
],
),
);
}).toList(),
),
),
),
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(00)),
image: DecorationImage(
image: ExactAssetImage('lib/images/homebg.png'),
fit: BoxFit.fill,
),
),
),
),
);
}
class Data {
String name,imageURL,description,date;
Data({this.name, this.imageURL, this.date, this.description});
}

Flutter Chat Screen Textinputfield

I have create a Chat in my app. My problem is that when someone want to type in the Inputfield the Inputfield goes up because of the phone keyboard but my chat dont show the last message above the Inputfield. Does anyone know how to fix this? Chatscreen and Chatscreen with keyboard
class Chat extends StatefulWidget {
final String chatRoomId;
Chat({this.chatRoomId});
#override
_ChatState createState() => _ChatState();
}
class _ChatState extends State<Chat> {
Stream<QuerySnapshot> chats;
TextEditingController messageEditingController = new TextEditingController();
Stream chatRooms;
Widget chatMessages(){
return StreamBuilder(
stream: chats,
builder: (context, snapshot){
return snapshot.hasData ?
ListView.builder(
itemCount: snapshot.data.docs.length,
itemBuilder: (context, index){
return MessageTile(
message: snapshot.data.docs[index].data()["message"],
sendByMe: Constants.myName == snapshot.data.docs[index].data()["sendBy"],
time: snapshot.data.docs[index].data()["time"],
);
},
) : SpinKitFadingCircle(color: Colors.white, size: 20.0);
},
);
}
addMessage() {
if (messageEditingController.text.isNotEmpty) {
Map<String, dynamic> chatMessageMap = {
"sendBy": Constants.myName,
"message": messageEditingController.text,
'time': DateTime
.now()
.millisecondsSinceEpoch,
};
DatabaseService().addMessage(widget.chatRoomId, chatMessageMap);
setState(() {
messageEditingController.text = "";
});
}
}
#override
void initState() {
DatabaseService().getChats(widget.chatRoomId).then((val) {
setState(() {
chats = val;
});
});
super.initState();
}
Future<DocumentSnapshot> getUserInfo() async {
var firebaseUser = await FirebaseAuth.instance.currentUser;
return await FirebaseFirestore.instance.collection("SerX")
.doc(firebaseUser.uid)
.get();
}
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
backgroundColor: Colors.black,
bottom: PreferredSize(
child: Container(
color: Colors.blue,
height: 4.0,
),
preferredSize: Size.fromHeight(0)),
title:Text("Conversation",
style: TextStyle(
color: Colors.white,
fontFamily: 'Orbitron',
fontSize: 20.0,
fontWeight: FontWeight.bold,
letterSpacing: 2.2
),),
leading: IconButton(icon: Icon(Icons.arrow_back ,color: Colors.blue,),onPressed: (){
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context) => Search()));
},),
),
body: Container(
child: Stack(
children: [
Container(child: chatMessages(), height: 595),
Container(
alignment: Alignment.bottomCenter,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 25, vertical: 3),
color: Colors.white,
child: Row(
children: [
Expanded(
child: TextField(
controller: messageEditingController,
style: TextStyle(
color: Colors.white,
fontFamily: 'Orbitron',
fontSize: 12.0,
fontWeight: FontWeight.bold,
),
decoration: InputDecoration(
contentPadding: new EdgeInsets.symmetric(vertical: 7, horizontal: 15),
filled: true,
fillColor: Colors.black,
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(40),
borderSide: BorderSide(color: Colors.blue, width: 3)
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(40),
borderSide: BorderSide(color: Colors.blue, width: 3,)
),
border: InputBorder.none,
),
),
),
SizedBox(width: 20,),
GestureDetector(
onTap: () {
addMessage();
},
/*
child:Container(
height: 45,
width: 45,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
const Color(0xFF000000),
const Color(0xFF000000),
]
),
borderRadius: BorderRadius.circular(40),
border: Border.all(
width: 2,
color: Colors.blue
)
),
*/
child:Icon(Icons.send, color: Colors /// <--- Um den grauen script zu aktivieren hinter Icon eine klammer zu setzen!
.black, size: 35,),
),
],
),
),
),
],
),
),
);
}
}
class MessageTile extends StatelessWidget {
final String message;
final bool sendByMe;
final int time;
MessageTile({#required this.message, #required this.sendByMe, #required this.time});
#override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.only(
top: 3,
bottom: 3,
left: sendByMe ? 0 : 24,
right: sendByMe ? 24 : 0),
alignment: sendByMe ? Alignment.centerRight : Alignment.centerLeft,
child: Container(
margin: sendByMe
? EdgeInsets.only(left: 30)
: EdgeInsets.only(right: 30),
padding: EdgeInsets.only(
top: 17, bottom: 17, left: 20, right: 20),
decoration: BoxDecoration(
borderRadius: sendByMe ? BorderRadius.only(
topLeft: Radius.circular(9),
topRight: Radius.circular(9),
bottomLeft: Radius.circular(9),
) :
BorderRadius.only(
topLeft: Radius.circular(9),
topRight: Radius.circular(9),
bottomRight: Radius.circular(9)),
color: sendByMe ? Colors.blue : Colors.white
),
child: Text(message,
textAlign: TextAlign.start,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontFamily: 'Orbitron',
fontSize: 9.0,),),
),
);
}
}
The cause of the error is that you set 595 pixels as a fixed height for the Container your chatMessages widget is in.
Container(child: chatMessages(), height: 595),
An easy solution would be to calculate the height of the keyboard (see this question):
Container(child: chatMessages(), height: MediaQuery.of(context).size.height - 134 - MediaQuery.of(context).viewInsets.bottom),
This takes the actual height of your device and subtracts the height of appBar, textinputfield and keyboard.
However, it would be more efficient to use a widget tree that does not depend on pixel calculations. Especially the part with the keyboard may lead to lagging on slower devices.

Unable to create data tables dynamically using TextField input

I am trying out to create an invoice application, wherein the user is entering the data, and then it should come up listed as a table.
What I have achieved so far is just a single row with just a single user input detail like with errors in it as well...
I wanted the application to
HardCoded Code:
class Sixth extends StatefulWidget {
#override
State<StatefulWidget> createState() {
// TODO: implement createState
return SixthState();
}
}
class SixthState extends State<Sixth> {
final pdf = pw.Document();
String path;
share() async {
Share.shareFiles([path]);
}
create() async {
print('creating');
pdf.addPage(pw.MultiPage(
pageFormat: PdfPageFormat.a4,
margin: pw.EdgeInsets.all(12),
build: (pw.Context context) {
return <pw.Widget>[
pw.Paragraph(
text: 'SOLUTION HUB\nVENDORS',
style: pw.TextStyle(fontWeight: pw.FontWeight.bold)),
pw.Paragraph(
padding: pw.EdgeInsets.only(left: 450),
text: 'Billing Address:',
style: pw.TextStyle(fontWeight: pw.FontWeight.bold)),
pw.Row(children: [
pw.Paragraph(
text: 'wrqijwqiojqwoirjq\nirjorwiuroeriuwor\noerweo8rw',
padding: pw.EdgeInsets.only(top: 10)),
pw.SizedBox(width: 370),
pw.Paragraph(
text: 'wrqijwqiojqwoirjq\nirjorwiuroeriuwor\noerweo8rw',
padding: pw.EdgeInsets.only(top: 10))
]),
pw.Paragraph(
padding: pw.EdgeInsets.only(top: 15),
text: 'PAN No. ${panvalue}',
style: pw.TextStyle(fontWeight: pw.FontWeight.bold)),
pw.Paragraph(
padding: pw.EdgeInsets.only(top: 15),
text: 'GST Registration No. ${gstvalue}',
style: pw.TextStyle(fontWeight: pw.FontWeight.bold)),
pw.Paragraph(
padding: pw.EdgeInsets.only(top: 15),
text: 'Order No. ${ordernovalue}',
style: pw.TextStyle(fontWeight: pw.FontWeight.bold)),
pw.Paragraph(
padding: pw.EdgeInsets.only(top: 15),
text: 'Order Date. ${orderdatevalue}',
style: pw.TextStyle(fontWeight: pw.FontWeight.bold)),
pw.Paragraph(
padding: pw.EdgeInsets.only(left: 450),
text: 'INVOICE NUMBER\n03950234982042980',
style: pw.TextStyle(fontWeight: pw.FontWeight.bold)),
pw.SizedBox(height: 20),
pw.Table.fromTextArray(data: <List<String>>[
<String>[
'SI\nNo.',
'Description',
'Unit\nPrice',
'Qty',
'Net Amount',
'Tax\nRate',
'Tax\nType',
'Tax\nAmt',
'Total\nAmt'
],
<String>[
'1',
'${SecondState.descriptionController.text}',
'${ThirdState.unitpriceController.text}',
'1',
'500',
'${FourthState.taxrateController.text}',
'${FourthState.taxtypeController.text}',
'${FourthState.taxamountController.text}',
'276.6'
],
])
];
},
));
}
Future save() async {
print('sacing');
Directory directory = await getApplicationDocumentsDirectory();
String documentpath = directory.path;
File file = File("$documentpath/example.pdf");
setState(() {
path = "$documentpath/example.pdf";
});
file.writeAsBytesSync(pdf.save());
}
int _value = 1;
AnimationController animationController;
Animation<Offset> offset;
static var panvalue;
static var gstvalue;
static var ordernovalue;
static var orderdatevalue;
static var descriptionvalue;
static var unitpricevalue;
static var quantityvalue;
static var taxratevalue;
static var taxtypevalue;
static var taxamtvalue;
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
drawer: Drawer(),
appBar: AppBar(
centerTitle: true,
title: Text('ORDER DETAILS'),
backgroundColor: Colors.blueGrey,
actions: <Widget>[
Padding(
padding: EdgeInsets.all(2),
child: IconButton(
onPressed: () {}, //USER PROFILE
icon: Icon(Icons.supervised_user_circle),
iconSize: 30,
),
)
],
),
body: SingleChildScrollView(
child: SafeArea(
child: Column(children: <Widget>[
Container(
padding: EdgeInsets.only(right: 220, top: 20),
child: Text(
'SOLUTION HUB \n VENDORS',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
),
),
Container(
padding: EdgeInsets.only(left: 240),
child: Text(
'Billing Adress:',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
),
),
SizedBox(
height: 15,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
padding: EdgeInsets.only(left: 30),
child:
Text('Ubga wjpw wiqjoiw\n owqkdw qwok qoqkw \nojq vpoqk'),
),
Container(
padding: EdgeInsets.only(right: 15),
child: Text('oefkwpfoke 20-32 \n 032902 0239 \n 0392230'),
)
],
),
Container(
width: 800,
padding: EdgeInsets.only(left: 35, right: 10, top: 45),
child: Text(
"Pan No. ${panvalue}",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
Container(
width: 800,
padding: EdgeInsets.only(left: 35, right: 10, top: 25),
child: Text(
"GST REGISTRATION NO. ${gstvalue}",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
Container(
width: 800,
padding: EdgeInsets.only(left: 35, right: 10, top: 25),
child: Text(
"Order No. ${ordernovalue} ",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
Container(
width: 400,
padding: EdgeInsets.only(left: 35, right: 20, top: 25),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
"Order Date: ${orderdatevalue}",
style: TextStyle(fontWeight: FontWeight.bold),
),
Text(
'INVOICE NUMBER',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14),
)
],
),
),
Container(
padding: EdgeInsets.only(left: 250, top: 5),
child: Text('5920384283429')),
Row(
children: <Widget>[
Expanded(
child: SingleChildScrollView(
child: DataTable(columnSpacing: 4, columns: [
DataColumn(
label: Text(
'Si\nNo.',
textAlign: TextAlign.left,
)),
DataColumn(label: Text('Description')),
DataColumn(label: Text('Unit\nPrice')),
DataColumn(label: Text('Qty')),
DataColumn(label: Text('Net\namount')),
DataColumn(label: Text('Tax\nRate')),
DataColumn(label: Text('Tax\nType')),
DataColumn(label: Text('Tax\nAmt')),
DataColumn(label: Text('Total\nAmt'))
], rows: [
DataRow(cells: [
DataCell(Wrap(
children: <Widget>[
Text(
'1',
textAlign: TextAlign.start,
)
],
)),
DataCell(Text(
'${SecondState.descriptionController.text}',
textAlign: TextAlign.center,
)),
DataCell(Wrap(
children: <Widget>[
Text(
'${ThirdState.unitpriceController.text}',
textAlign: TextAlign.center,
)
],
)),
DataCell(Text('${ThirdState.quantityController.text}')),
DataCell(Text('500')),
DataCell(Text('${FourthState.taxrateController.text}')),
DataCell(Text('${FourthState.taxtypeController.text}')),
DataCell(Text('${FourthState.taxamountController.text}')),
DataCell(Text('500')),
])
]))),
],
),
SizedBox(
height: 150,
),
ButtonTheme(
minWidth: 110,
height: 50,
child: RaisedButton(
color: Colors.blue[300],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18)),
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text("COMPLETE ACTION USING"),
content: Container(
height: 150,
width: 100,
child: Column(
children: <Widget>[
FlatButton(
onPressed: () async {
create();
await save();
share();
},
child: Text('WhatsApp'),
),
FlatButton(
onPressed: () {},
child: Text('Gmail'),
),
FlatButton(
onPressed: () {},
child: Text("Download"),
)
],
),
),
);
});
},
child: Text('Share'),
),
)
]),
),
),
));
}
}
What I want to achieve is this
It should automatically add rows as user inputs enter details
Errors I have encountered:
Whenever I going to add more items the previous data are stored in the text fields.
There are more colors on the right side but am unable to view it.
Please help me solve this issue

How to scroll a text?

I have a text and I've tried a lot to make it scrollable, what I want is to make the postDesc text scrollable I've tried to wrap it with single child scroll view and listview and expanded but not worked.
please give me a solution
I want to make the screen or the container scrollable or to scroll the text only.
I've seen many solutions but it didn't work for me.
My project has been stopped because of that.
For any details you want please leave a comment.
thanks,
My Code:
#override
Widget build(BuildContext context) {
final userimage = InkWell(
child: Container(
margin: EdgeInsets.only(right: 10.0),
height: 40.0,
width: 40.0,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage('${widget.userPhoto}'),
fit: BoxFit.cover,
),
borderRadius: BorderRadius.circular(7.0),
),
),
);
final headerDesc = Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'${widget.writer}',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
Text(
'25 minutes ago',
style: TextStyle(
color: Colors.grey.withOpacity(0.6),
fontWeight: FontWeight.bold,
),
)
],
);
final header = Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[userimage, headerDesc],
);
final descriptionText = Text(
'${widget.postTitle}',
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Amiri',
color: Colors.black87,
fontWeight: FontWeight.w600,
fontSize: MediaQuery.of(context).size.width / 20,
),
);
final divider = Divider(
thickness: 0.5,
color: Colors.grey,
);
final footer = Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
onPressed: () {
print(null);
},
icon: Icon(
Icons.share,
color: Theme.of(context).primaryColor,
),
),
Row(
children: <Widget>[
SizedBox(
width: 30.0,
),
StreamBuilder<QuerySnapshot>(
stream: _firestore.collection('posts').snapshots(),
builder: (context, snapshot) {
var documents = snapshot.data.documents;
var likes;
for (var document in documents) {
if (document.documentID == widget.uid) {
likes = document['likes'];
}
}
return Text(
'$likes',
);
}),
SizedBox(
width: 3.0,
),
Icon(
Icons.favorite,
color: Colors.red,
),
],
),
],
);
return Scaffold(
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: MediaQuery.of(context).size.height,
child: Stack(
children: <Widget>[
GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ImagePreview(
image: widget.networkImage,
),
),
);
},
child: Material(
elevation: 5.0,
borderRadius: BorderRadius.circular(14.0),
child: Container(
height: MediaQuery.of(context).size.height / 5,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(14.0),
image: DecorationImage(
image: widget.networkImage.image,
fit: BoxFit.cover,
),
),
),
),
),
Positioned(
top: 90.0,
left: 0.0,
right: 0.0,
child: Padding(
padding: EdgeInsets.only(left: 10.0, right: 10.0),
child: Material(
elevation: 5.0,
shadowColor: Colors.white,
borderRadius: BorderRadius.circular(14.0),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(14.0),
),
child: Padding(
padding: EdgeInsets.only(
top: 20.0,
bottom: 00.0,
left: 20.0,
right: 20.0,
),
child: ListView(
shrinkWrap: true,
children: <Widget>[
header,
SizedBox(
height: 10.0,
),
descriptionText,
SizedBox(
height: 5,
),
divider,
Padding(
padding: const EdgeInsets.all(20),
child: SingleChildScrollView(
child: Text(
'${widget.postDesc}',
),
),
),
footer,
SizedBox(
height: 10,
),
],
),
),
),
),
),
)
],
),
),
),
),
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.red,
child: Icon(
Icons.favorite,
color: Colors.white,
),
onPressed: () async {
await likePost();
},
),
);
}
I might be wrong here, but I think the problem is that you have a SingleChildScrollView inside a ListView. If you just want to scroll the postDesc, you might want to add this to your ListView:
ListView(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
children: [...]
),

Resources