LinearGradient button figma to flutter - css

My CSS:
background: linear-gradient(91.97deg, #F8A170 14.73%, #FFCD61 97.52%);
border-radius: 10px;
I want to go with flutter but when I give these colors to the container widget with child elevated button, I can't get the result I want. I made the button style transparent, but still I couldn't solve it.

Based on your image and css, You can simply decorate the style of ElevatedButton.
DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
gradient: const LinearGradient(
colors: [
Color(0xFFF8A170),
Color(0xFFFFCD61),
],
),
),
child: SizedBox(
width: 400,
height: 75,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
elevation: 0,
primary: Colors.white.withOpacity(0),
padding: const EdgeInsets.all(0),
),
onPressed: () {},
child: const Text(
"Search a room",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 22,
),
),
),
),
),
More about
DecoratedBox and ElevatedButton

Please refer to below example code
Using Elevated Button
LinearGradient yellowLinearGradientValues() {
return LinearGradient(
colors: [Colors.orange, Color(0xffFFB800).withOpacity(0.65)],
);
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
elevation: 0.0,
padding: EdgeInsets.zero,
primary: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
side: BorderSide(
width: 0.0,
color: Colors.orange,
style: BorderStyle.none,
),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(8.0),
),
gradient: yellowLinearGradientValues(),
),
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 40.0,
vertical: 8.0,
),
child: Text(
"Search a Room" ?? "",
textAlign: TextAlign.start,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 24.0,
),
),
),
),
),
),
);
}
LinearGradient yellowLinearGradientValues() {
return LinearGradient(
colors: [Colors.orange, Color(0xffFFB800).withOpacity(0.7)],
);
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ElevatedButton(
onPressed: () {},
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.transparent),
elevation: MaterialStateProperty.all(0.0),
padding: MaterialStateProperty.all(EdgeInsets.zero),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(8.0),
),
gradient: yellowLinearGradientValues(),
),
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 40.0,
vertical: 8.0,
),
child: Text(
"Search a Room" ?? "",
textAlign: TextAlign.start,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 24.0,
),
),
),
),
),
),
);
}

Related

Retrieving Image from Firebase Realtime database

How do I retrieve a specific URL from the real-time database?
final database = FirebaseDatabase(
databaseURL:
"https://trackkit-a5cf3-default-rtdb.asia-southeast1.firebasedatabase.app")
.reference()
.child('NTU')
.child(widget.referenceName);
.
.
.
Widget _buildItem(String imgPath, String labName, int quantity, String expiry,
Function onAdd, Function onSubtract, Function onDelete) {
void _minusNum() {
onSubtract();
}
void _onAdd() {
onAdd();
}
void _onDelete() {
onDelete();
}
return Padding(
padding: const EdgeInsets.only(left: 0.0, right: 10, top: 0.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
GestureDetector(
onLongPress: _onDelete,
child: Row(children: [
Hero(
tag: imgPath,
child: const Image(
image: NetworkImage(''), <---THIS IS THE LINE
fit: BoxFit.cover,
height: 120.0,
width: 130.0)),
const SizedBox(width: 10.0),
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Text(
labName,
style: const TextStyle(
fontFamily: 'Montserrat',
fontSize: 12.0,
fontWeight: FontWeight.bold,
),
),
Text(
expiry,
style: const TextStyle(
fontFamily: 'Montserrat',
fontSize: 12.0,
fontWeight: FontWeight.bold,
),
),
Container(
width: 100.0,
height: 30.0,
margin: const EdgeInsets.only(left: 0.0, top: 5.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(17.0),
color: const Color(0xFF7A9BEE)),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
InkWell(
onTap: _minusNum,
child: Container(
height: 25.0,
width: 25.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(7.0),
color: const Color(0xFF7A9BEE)),
child: const Center(
child: Icon(
Icons.remove,
color: Colors.white,
size: 20.0,
),
),
),
),
Text(quantity.toString(),
style: const TextStyle(
color: Colors.white,
fontFamily: 'Montserrat',
fontSize: 15.0)),
InkWell(
onTap: _onAdd,
child: Container(
height: 25.0,
width: 25.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(7.0),
color: Colors.white),
child: const Center(
child: Icon(
Icons.add,
color: Color(0xFF7A9BEE),
size: 20.0,
),
),
),
),
],
),
)
]),
]),
),
],
));
}
.
.
.
tag: imgPath,
child: const Image(
image: NetworkImage(''),
fit: BoxFit.cover,
height: 120.0,
width: 130.0)
I am able to retrieve the rest of the item in the firebase, but I am unable to retrieve the Image.
The error appears:
======== Exception caught by image resource service ================================================
The following ArgumentError was thrown resolving an image codec:
Invalid argument(s): No host specified in URI file:///lists%5Bindex%5D%5B%22Image%22%5D
The question is not really clear, but This error is definitely happening because you're assigning an invalid image link '' to your NetworkImage.

Unable to update the data in flutter firebase - 2021

I am new to firebase. I started learning from YouTube and documents. As flutter updates changed this year there are not many YouTube videos or blogs that are helpful to me. In here I retrieved the data from firebase cloud and displayed in the textFormField like this. But I am unable to update the data. Can any one help me what is the issue and how I can resolve that.
child: StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection("personalDetail")
.snapshots(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return ListView.builder(
itemCount: 1,
itemBuilder: (context, index) {
QueryDocumentSnapshot x = snapshot.data!.docs[index];
return Container(
child: Column(
children: [
Center(
child: Stack(
children: [
Container(
width: 130,
height: 130,
decoration: BoxDecoration(
border: Border.all(
width: 4, color: Colors.white),
boxShadow: [
BoxShadow(
spreadRadius: 2,
blurRadius: 10,
color: Colors.black.withOpacity(0.1),
)
],
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage(
'assets/images/Profile.jpg'),
),
),
),
Positioned(
bottom: 0,
right: 0,
child: Container(
height: 40,
width: 40,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
width: 4,
color: Colors.white,
),
color: Colors.green.shade400),
child: Icon(
Icons.camera_alt,
color: Colors.white,
),
),
)
],
),
),
SizedBox(
height: 30,
),
TextFormField(
maxLength: 20,
style: TextStyle(
color: Colors.black,
fontSize: 15,
),
controller:
TextEditingController(text: x['firstName']),
decoration: InputDecoration(
labelText: "First Name",
labelStyle: TextStyle(
fontWeight: FontWeight.w800,
color: Colors.black,
fontSize: 23),
floatingLabelBehavior:
FloatingLabelBehavior.always,
),
),
TextFormField(
maxLength: 20,
style: TextStyle(
color: Colors.black,
fontSize: 15,
),
controller:
TextEditingController(text: x['lastName']),
decoration: InputDecoration(
labelText: "Last Name",
labelStyle: TextStyle(
fontWeight: FontWeight.w800,
color: Colors.black,
fontSize: 23),
floatingLabelBehavior:
FloatingLabelBehavior.always,
),
),
TextFormField(
maxLength: 15,
style:
TextStyle(color: Colors.black, fontSize: 15),
controller:
TextEditingController(text: x['middleName']),
decoration: InputDecoration(
labelText: "Middle Name",
labelStyle: TextStyle(
fontWeight: FontWeight.w800,
color: Colors.black,
fontSize: 23),
floatingLabelBehavior:
FloatingLabelBehavior.always,
),
),
TextFormField(
maxLength: 10,
keyboardType: TextInputType.phone,
inputFormatters: [
FilteringTextInputFormatter.digitsOnly
],
style:
TextStyle(color: Colors.black, fontSize: 15),
controller:
TextEditingController(text: x['phone']),
decoration: InputDecoration(
labelText: "Phone Number",
labelStyle: TextStyle(
fontWeight: FontWeight.w800,
color: Colors.black,
fontSize: 23),
floatingLabelBehavior:
FloatingLabelBehavior.always,
),
),
TextFormField(
initialValue: x['email'],
enabled: false,
style: TextStyle(
color: Colors.black,
fontSize: 15,
),
decoration: InputDecoration(
labelText: "Email",
labelStyle: TextStyle(
fontWeight: FontWeight.w800,
color: Colors.black,
fontSize: 23),
floatingLabelBehavior:
FloatingLabelBehavior.always,
),
),
SizedBox(
height: 30,
),
Align(
child: ElevatedButton(
onPressed: () {
FirebaseFirestore.instance
.collection('personalDetail')
.doc('pxylzgi6iaIdV3uswzzK')
.update({
"firstName": TextEditingController(text: x['firstName']),
"lastName": TextEditingController(text: x['lastName']),
"middleName":TextEditingController(text: x['middleName']),
"phone":TextEditingController(text: x['phone']),
});
Fluttertoast.showToast(
msg: "Profile updated Successfully",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
textColor: Colors.black,
backgroundColor: Colors.green.shade400,
);
Navigator.pushNamed(
context, "/profilePage");
},
child: Text(
"Save Details",
style: TextStyle(
fontSize: 15,
letterSpacing: 2,
color: Colors.black),
),
style: ElevatedButton.styleFrom(
fixedSize: Size(250, 40),
primary: Colors.green.shade500,
padding: EdgeInsets.symmetric(
horizontal: 50,
),
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(10))),
),
)
],
),
);
},
);
} else {
Center(
child: CircularProgressIndicator(),
);
}
throw "";
},
),
Please help, I am trying different YouTube videos but none are helping.
Have you checked Firebase Read and write permission?
Refer this documentation for further help
https://firebase.google.com/docs/database/web/read-and-write

How to create horizontal ListView.builder

Hey there i want to make horizontal ListView.builder but it shows error that 'BoxConstraints forces and infinite width'. Actually i want to make a 'Buyer Request' page like Fiverr.
I achieved my goal using PageView.builder but when i use
if(snapshot.connectionState == ConnectionState.waiting)
return SpinKitDoubleBounce(color: kPrimaryColor);
it brings me back to 1st index whenever i swipe to next index.
So i want to use ListView.builder instead. Here is my code: (Hope someone will solve my problem)
if (snapshot.hasData)
return SizedBox(
child: ListView.builder(
// scrollDirection: Axis.horizontal,
itemCount: indexLength,
controller: PageController(viewportFraction: 1.0),
// onPageChanged: (int index) => setState(() => _index = index),
itemBuilder: (_, i) {
return SingleChildScrollView(
child: Card(
margin: EdgeInsets.all(10),
child: Wrap(
children: <Widget>[
ListTile(
leading: CircleAvatar(
backgroundColor: kPrimaryColor.withOpacity(0.8),
backgroundImage: AssetImage('assets/images/nullUser.png'),
child: snapshot.data[i]['PhotoURL'] != null
? ClipRRect(
borderRadius: BorderRadius.circular(50),
child:
Image.network(snapshot.data[i]['PhotoURL'],
width: 50,
height: 50,
fit: BoxFit.cover,),
)
: ClipRRect(
borderRadius: BorderRadius.circular(50),
child:
Image.asset('assets/images/nullUser.png',
width: 50,
height: 50,
fit: BoxFit.cover,),
)
),
title: Text(
snapshot.data[i]['Email'],
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w700,
color: Colors.black.withOpacity(0.7),
),
),
subtitle: Text(
snapshot.data[i]['Time'],
style: TextStyle(
color: Colors.black.withOpacity(0.6)),
),
),
Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(5)),
color: Colors.grey[200],
),
padding: EdgeInsets.all(10),
child: Text(
snapshot.data[i]['Description'],
style: TextStyle(
color: Colors.black.withOpacity(0.6)),
),
),
SizedBox(
height: 8,
),
Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(5)),
border:
Border.all(color: Colors.grey[300])),
child: ListTile(
leading: Icon(Icons.category_outlined),
title: Text(
'Category : ${snapshot.data[i]['Category']}',
style: TextStyle(
fontSize: 14,
color: Colors.grey,
),
),
),
),
SizedBox(height: 8),
Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(5)),
border:
Border.all(color: Colors.grey[300])),
child: ListTile(
leading: Icon(Icons.location_pin),
title: Text(
snapshot.data[i]['Location'],
style: TextStyle(
fontSize: 14,
color: Colors.grey,
),
),
),
),
SizedBox(height: 8),
Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(5)),
border:
Border.all(color: Colors.grey[300])),
child: ListTile(
leading: Icon(
Icons.attach_money,
color: kGreenColor,
),
title: Text(
'Budget : Rs.${snapshot.data[i]['Budget']}',
style: TextStyle(
fontSize: 14,
color: kGreenColor,
),
),
),
),
SizedBox(height: 8),
Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(5)),
border:
Border.all(color: Colors.grey[300])),
child: ListTile(
leading: Icon(Icons.timer),
title: Text(
'Duration : ${snapshot.data[i]['Duration']}',
style: TextStyle(
fontSize: 14,
color: Colors.grey,
),
),
),
),
SizedBox(
height: 35,
),
sendOfferButton(),
SizedBox(
height: 15,
),
Center(
child: Text(
"${i + 1}/$indexLength",
style: TextStyle(fontSize: 13),
),
),
],
),
),
],
),
),
);
},
),
);
If anyone want to see full file.
Check it Here
Use pageview.builder instead :
Container(
height: MediaQuery.of(context).size.height / 3,
width: MediaQuery.of(context).size.width,
child: PageView.builder(
pageSnapping: false,
physics: PageScrollPhysics(),
controller: _pageController,
scrollDirection: Axis.horizontal,
itemCount:
_articleController.articleListDat.length,
itemBuilder: (context, index) {
return Container();
}
And pagecontroller
PageController _pageController =
PageController(initialPage: 2, viewportFraction: 0.9);
First wrap your ListView.builder into LimitedBox / container then set height on it. Then add
scrollDirection: Axis.horizontal,
It's Done

Loading PDF file from Firebase Storage in Flutter App

i'm working on app and i want to loading pdf from firebase storage to an flutter app i search a lot about this and i don't find anything can help me
for example like in the image i want when i click to cour or TD.. the pdf show in the screen
image
class Electro extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Electronique Analogique'),
backgroundColor: Colors.red,
actions: <Widget>[
IconButton(icon: Icon(Icons.search), onPressed: () {}),
],
),
body: GridView.count(
primary: false,
padding: const EdgeInsets.all(4),
crossAxisSpacing: 4,
mainAxisSpacing: 4,
crossAxisCount: 2,
children: [
GestureDetector(
onTap: () {
print("clicked"); //we put the function of pdf
},
child: Container(
padding: const EdgeInsets.all(20),
child: Center(
child: const Text(
'Cour',
style: TextStyle(
color: Color(0xfff2f2f2),
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat',
fontSize: 20,
),
),
),
color: Colors.red,
),
),
Container(
padding: const EdgeInsets.all(20),
child: Center(
child: const Text(
'TD',
style: TextStyle(
color: Color(0xfff2f2f2),
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat',
fontSize: 20,
),
),
),
color: Colors.indigo,
),
Container(
padding: const EdgeInsets.all(20),
child: Center(
child: const Text(
'Correction TD',
style: TextStyle(
color: Color(0xfff2f2f2),
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat',
fontSize: 20,
),
),
),
color: Colors.teal,
),
Container(
padding: const EdgeInsets.all(20),
child: Center(
child: const Text(
'Exam',
style: TextStyle(
color: Color(0xfff2f2f2),
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat',
fontSize: 20,
),
),
),
color: Colors.teal,
),
],
),
);
}
}
Use the flutter_pdf_viewer plugin for loading pdf files from URL
PDFDocument doc = await PDFDocument.fromURL('YOUR PDF URL');
see complete example here

Display Text from Firebase in a Textformfield?

I just wanted to display the Username from the User which is saved in the cloud Firestore. Does anyone know how to display the Username String in the cloud Firestore?
#override
Widget build(BuildContext context) {
lol()async{
var documents =
(await Firestore.instance.collection('SerX').get())
.docs;
}
return Scaffold(
appBar: AppBar(
bottom: PreferredSize(
child: Container(
color: Colors.blue,
height: 4.0,
),
preferredSize: Size.fromHeight(0)),
backgroundColor: Colors.black,
leading: IconButton(icon: Icon(Icons.arrow_back ,color: Colors.blue,),onPressed: (){
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context) => HomeScreen()));
},),
title: Text('Profile', style: TextStyle(
color:Colors.white,
fontSize: 25,
fontWeight: FontWeight.bold,
fontFamily: 'Orbitron',
),
textAlign: TextAlign.center,
),
),
body: Container(
color: Colors.black,
child: ListView(
children: [
Stack(
children: [
Container(
margin: EdgeInsets.fromLTRB(140,100,0,0),
width: 130,
height: 130,
decoration: BoxDecoration(
border: Border.all(
width: 3,
color: Colors.blue,
),
boxShadow: [BoxShadow(
spreadRadius: 2, blurRadius: 10,
color: Colors.white.withOpacity(0.1),
offset: Offset(0,10),
),
],
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.cover,
image: (_image != null) ? FileImage(
_image)
: NetworkImage("https://www.senertec.de/wp-content/uploads/2020/04/blank-profile-picture-973460_1280.png"),
)
),
),
Positioned(
bottom: 0,
right: 150,
child: Container(
height: 40,
width: 40,
decoration: BoxDecoration(
border: Border.all(width: 2, color: Colors.blue),
shape: BoxShape.circle,
color: Colors.white,
),
child: IconButton(icon: Icon(Icons.edit), color: Colors.blue, onPressed: (){
getImage(context);
},),
),
)
],
),
SizedBox(height: 40),
TextFormField(
style: TextStyle(
color: Colors.white,
fontSize: 15,
fontWeight: FontWeight.bold,
fontFamily: 'Orbitron',
),
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: const BorderSide(color: Colors.blue, width: 1.0),
borderRadius: BorderRadius.circular(25.0),
),
enabledBorder: OutlineInputBorder(
borderSide: const BorderSide(color: Colors.white, width: 1.0),
borderRadius: BorderRadius.circular(25.0),
),
icon: Icon(Icons.edit, color: Colors.blue,),
contentPadding: EdgeInsets.only(bottom: 3),
labelText: "Username",
labelStyle: TextStyle(color: Colors.white),
floatingLabelBehavior: FloatingLabelBehavior.always,
prefixIcon: Icon(Icons.account_circle, color: Colors.blue,),
-> hintText: snapshot.data.data()["Username"], <-
hintStyle: TextStyle(
color: Colors.white,
fontSize: 15,
fontWeight: FontWeight.bold,
fontFamily: 'Orbitron',
),
),
),
If you are using firebase user authentication then with the help of firebaseUser you can easily access the user username.
Else if you are using database like firestore then the data you get from that is in JSON format (like Maps).
String userName = firebaseData['userName'];

Resources