Why it is not changing the heigth and width of the button - flutter

InkWell(
borderRadius: BorderRadius.all(Radius.circular(5)),
onTap: () {},
child: SizedBox(
height: 25,
width: screenWidth *65,
child: Container(
color: Colors.blueAccent,
child: Text(
'Confirm',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
color: Color(0xff000000),
fontWeight: FontWeight.w500),
),
),
),
),

Is this what you are looking for?
Container(
padding: EdgeInsets.all(6),
width: double.infinity,
child: FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(5))
),
color: Colors.blueAccent,
onPressed: () => print('pressed'),
child: Text('Confirm',
style: TextStyle(
fontSize: 15,
color: Color(0xff000000),
fontWeight: FontWeight.w500
),
)
),
),

Remove SizedBox widget as it not of any issue in your current widget tree anyway as you are using container already
and use those height and width parameter inside container widget
try this
InkWell(
borderRadius: BorderRadius.all(Radius.circular(5)),
onTap: () {},
child: Container(
height: 25,
width: screenWidth *65,
color: Colors.blueAccent,
child: Text(
'Confirm',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
color: Color(0xff000000),
fontWeight: FontWeight.w500),
),
),
),

Related

Stack item are not positioned when the screen size changes Flutter

1-I am making a simple app where I am creating Profile section Where there is Stack at the top with two widgets
but the problem is when ever I test the app on different screen sizes the Stack item widgets are not at same position even i tried with MediaQuery
2-And the Second issue is I want the Circle Avatar to be place Half inside the Container And Half Out-side the Container.
Here is my Profile.dart class
class SettingsScreen extends StatelessWidget {
const SettingsScreen({super.key});
#override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Stack(
children: <Widget>[
Container(
// height: mediaQueryData.size.height * 0.4,
height: 300,
width: double.infinity,
decoration: const BoxDecoration(
gradient: LinearGradient(colors: [
Colors.black,
Color.fromRGBO(255, 243, 18, 3),
], begin: Alignment.topLeft, end: Alignment.bottomRight),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(50),
bottomRight: Radius.circular(50))),
),
const Padding(
padding: EdgeInsets.only(top: 240, left: 140),
child: CircleAvatar(
backgroundColor: Color.fromARGB(183, 40, 46, 3),
radius: 50,
child: Text(
"M-E",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 32),
),
),
),
Positioned(
top: 110,
left: 40,
child: Text(
"مثابة ايلاف",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 70),
),
),
//),
],
),
Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 0),
child: ListTile(
trailing: const Icon(
Icons.cast_for_education,
color: Colors.black,
),
title: const Text(
"Subjects (مضامین)",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 18),
),
onTap: () {},
),
),
const Divider(
color: Colors.black,
thickness: 0.5,
),
Padding(
padding: const EdgeInsets.only(top: 2),
child: ListTile(
trailing: const Icon(
Icons.contacts,
color: Colors.black,
),
title: const Text(
"Contact (رابطہ )",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 18),
),
onTap: () {},
),
),
const Divider(
color: Colors.black,
thickness: 0.5,
),
Padding(
padding: const EdgeInsets.only(top: 2),
child: ListTile(
trailing: const Icon(
Icons.settings,
color: Colors.black,
),
title: const Text(
"Setting (ترتیبات)",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 18),
),
onTap: () {},
),
),
const Divider(
color: Colors.black,
thickness: 0.5,
),
Padding(
padding: const EdgeInsets.only(top: 2),
child: ListTile(
trailing: const Icon(
Icons.logout,
color: Colors.black,
),
title: const Text(
"Logout (لاگ آوٹ)",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 18),
),
onTap: () {},
),
),
],
),
],
),
));
}
}
Here is the const result I want when the app run on different devices
Here is the result I don't want to be happens whenever the device size changes
Use this structure.
Positioned(
top: 110,
left: 1,
right:1
child: Text(
"مثابة ايلاف",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 70),
),
),

ripple effect in this container widget is not working

I am new to flutter and trying to apply the ripple effect on button press in this container widget through the documentation but unable to do
Padding(
padding: const EdgeInsets.symmetric(horizontal: 25.0),
child: GestureDetector(
onTap: signIn,
child: Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.deepPurple,
borderRadius: BorderRadius.circular(12)),
child: Center(
child: Text(
'Sign In',
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
),
),
),
Inner container color is over the splash color. And to have splash effect use InkWell instead of GestureDetector
Padding(
padding: const EdgeInsets.symmetric(horizontal: 25.0),
child: Material(
color: Colors.deepPurple,
child: InkWell(
onTap: () {},
splashColor: Colors.red,
child: Center(
child: Text(
'Sign In',
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
),
),
You can simply replace GestureDetector with InkWell widget as below.
InkWell(
onTap: signIn,
child: Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(color: Colors.deepPurple, borderRadius: BorderRadius.circular(12)),
child: Center(
child: Text(
'Sign In',
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
),
)
you can use InkWell and wrap it with Material with transparant color if your container has background color;
Material(
color: Colors.transparent,
child: InkWell(
splashColor: Colors.blue,
onTap: () {},
child: Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.deepPurple,
borderRadius: BorderRadius.circular(12)),
child: Center(
child: Text(
'Sign In',
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
),
))
Padding(
padding: const EdgeInsets.symmetric(horizontal: 25.0),
child: Material(
borderRadius: BorderRadius.circular(12),
color: Colors.deepPurple,
child: InkWell(
splashColor: Colors.white60,
borderRadius: BorderRadius.circular(12),
onTap: (() {}),
child: Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12)),
child: Center(
child: Text(
'Sign In',
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
),
),
),
),

The named parameter 'fontSize' isn't defined. in flutter code

want to add 5 box containers display xs, s, m, l, xl sizes. but the code throwing errors. where should I correct this? please refer to the image here. I add a container to create those. I'm new to flutter and can anyone please help how can I fix this.
error >> The named parameter 'fontSize' isn't defined. in flutter code
error>> The named parameter 'fontWeight' isn't defined.
import 'package:flutter/material.dart';
class DetailsScreen extends StatelessWidget {
const DetailsScreen({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
backgroundColor: Colors.pinkAccent,
),
body: Column(
children: <Widget>[
Expanded(
child: Container(height: MediaQuery.of(context).size.height*.8,
padding: EdgeInsets.all(10.0),
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/image23.png"),
//fit: BoxFit.fitHeight,
),
),
),
),
Stack(
alignment: Alignment.bottomRight,
children: <Widget>[
// Max Size
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
color: Colors.red.shade50,
),
alignment: const Alignment (1,1),
height: 400,
width: 350,
child: Column(
children: const [
Padding(
padding: const EdgeInsets.fromLTRB(10, 40, 100, 40),
child: Text(
"Summer Collections",
style: TextStyle(
fontSize: 24,
color: Color(0xff262626),
fontWeight: FontWeight.w700),
textAlign: TextAlign.left,
),
),
Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 270, 100),
child: Text(
"Sizes",
style: TextStyle(
fontSize: 12,
color: Color(0xff262626),
fontWeight: FontWeight.w700),
textAlign: TextAlign.left,
),
),
],
),
)
Container(
child: Row(
children: [
Container(
height:49, width: 49,
decoration: BoxDecoration(
color: Color.fromRGBO(228, 228, 228, 1),
borderRadius: BorderRadius.circular(10)
),
child:const Center(
child:Text("xs",
fontSize:20,
fontWeight:FontWeight.bold
),
),
)
],
)),
Padding(
padding: const EdgeInsets.fromLTRB(230, 110, 0, 40),
child: ElevatedButton(
onPressed: () {},
child: const Text(
"Add to Cart ",
),
style: ElevatedButton.styleFrom(
primary: Colors.black,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
bottomRight: Radius.circular(20))),
padding: const EdgeInsets.all(15)),
),
),
]
),
],
),
);
}
}
This is the correct way to use TextStyle. reference.
Text(
'text',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold),
),
You should use TextStyle :
Text(
"your text here" ,
style: TextStyle(
fontsize: ,
fontWeight:
),
)
You need TextStyle to change fontSize, color, fontWeight etc.
child: Text("xs", style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold
),
),
You have wrote a wrong code,Try below code hope its helpful to you.
Refer Text Class here
Refer TextStyle here
Center(
child: Text(
"xs",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
Your Reslt Screen->
Put the text styles in a TextStyle widget.
The problem here is pretty simple. The text widget does not have any attribute fontSize or font weight. Instead, it is the TextStyle widge.
This is how it works
const Center(
child: Text("xs",
style: TextStyle(
fontSize: 22,
fontWeight: FontWight.bold
)
)
This is the props of textStyle of Text widget, So first you have to give textstyle of Text widget, then set this.
Text(
"Helo world",
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.normal,
)),
used this:-
Center(
child: Text(
"xs",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),

Add image to listview from Gallery in Flutter/dart

This is currently what I have achived,
#override
Widget build(BuildContext context) {
_height = MediaQuery.of(context).size.height;
return Scaffold([![enter image description here][1]][1]
resizeToAvoidBottomInset: false,
extendBodyBehindAppBar: true,
appBar: AppBar(
leading: GestureDetector(
child: Image.asset('graphics/back_arrow.png'),
onTap: () {
Get.back();
},
),
backgroundColor: Colors.transparent,
elevation: 0,
title: Text(
'Ask The Internet',
style: GoogleFonts.montserrat(
fontSize: 20,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.bold,
color: Colors.white),
),
),
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("graphics/login.png"),
fit: BoxFit.cover,
),
),
child: Column(
children: [
Container(
width: double.infinity,
height: _height * 0.15,
),
Container(
padding:
EdgeInsets.only(top: 64, left: 16, right: 16, bottom: 16),
height: _height * 0.85,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(64),
topRight: Radius.circular(64),
),
),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Align(
alignment: Alignment.center,
child: Text(
'Ask The Internet',
style: GoogleFonts.montserrat(
fontSize: 16,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.w600,
color: loginPageTitleColor),
),
),
SizedBox(
height: _height * 0.04,
),
Text(
'Upload Content for UP',
style: GoogleFonts.montserrat(
fontSize: 14,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal,
color: askInternetPageTitleColor),
),
SizedBox(
height: _height * 0.01,
),
Row(
children: [
GestureDetector(
child: Image.asset('graphics/add.png'),
onTap: () {
_pickImages();
},
),
],
),
Align(
alignment: Alignment.center,
child: Image.asset('graphics/divider.png')),
SizedBox(
height: _height * 0.04,
),
Text(
'Upload Content for DOWN',
style: GoogleFonts.montserrat(
fontSize: 14,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal,
color: askInternetPageTitleColor),
),
SizedBox(
height: _height * 0.01,
),
Image.asset('graphics/add.png'),
Align(
alignment: Alignment.center,
child: Image.asset('graphics/divider.png')),
SizedBox(
height: _height * 0.06,
),
TextFieldInput(
titleText: 'Text up to 140 characters',
hintText: 'Enter Question',
inputType: TextInputType.visiblePassword,
textEditingController: controller.questionController,
titleTextStyle: GoogleFonts.montserrat(
fontSize: 15,
fontWeight: FontWeight.normal,
color: editProfivePageTitleColor),
),
SizedBox(
height: _height * 0.04,
),
Align(
alignment: Alignment.center,
child: Text(
'Ask The Community',
style: GoogleFonts.montserrat(
fontSize: 16,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.w600,
color: loginPageTitleColor),
),
),
SizedBox(
height: _height * 0.04,
),
Text(
'Select The Community',
style: TextStyle(fontSize: 20, color: Colors.black38),
),
Obx(
() => DropdownButton<CommunityItem>(
isExpanded: true,
value: controller.item.value,
items:
controller.communityRows.map((CommunityItem value) {
return DropdownMenuItem<CommunityItem>(
value: value,
child: Text(value!.name!),
);
}).toList(),
onChanged: (value) {
controller.item.value = value!;
},
),
),
SizedBox(
height: _height * 0.04,
),
GestureDetector(
child: Container(
width: double.maxFinite,
height: 55,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(4.0),
),
color: Colors.black,
image: DecorationImage(
image: AssetImage("graphics/btn.png"),
fit: BoxFit.cover),
),
child: Center(
child: Text(
"Save",
style: GoogleFonts.montserrat(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.white),
),
) // button text
),
onTap: () {
print("you clicked me");
},
),
],
),
),
),
],
),
),
);
}
I want when user click on plus icon he can add images from gallery, just like this.
I tried to use Listview builder but it was not prefect.

How to make text align to centre of a Sizedbox in Flutter

i use text inside a sizedbox in flutter and the text is sticked to the top of the box how can i put the text in the middle of the box.
child: Container(
width: 240.0,
height: 42.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(24.0),
color: const Color(0xff2c2c2c),
),
child: SizedBox(
child: Text(
'SIGN UP',
style: TextStyle(
fontFamily: 'Arial',
fontSize: 18,
color: Colors.white,
height: 1,
),
textAlign: TextAlign.center,
),
),
),
Wrap the Text in a Center widget
child: Container(
width: 240.0,
height: 42.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(24.0),
color: const Color(0xff2c2c2c),
),
child: Center(
child: Text(
'SIGN UP',
style: TextStyle(
fontFamily: 'Arial',
fontSize: 18,
color: Colors.white,
height: 1,
),
textAlign: TextAlign.center,
),
),
),
Also, as far I can tell, you can remove the SizedBox widget, This is the result