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

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,
),
),
),

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),
),
),

Flutter App Screen is appearing weird on Samsung S8

Image is here
Flutter app screen and text is appearing weird in Samsung S8 mobile
but tested in Other Samsung devises and its working fine, you can see how its supposed to work on the other devices on the above image
any one know why is this screen issue is happening only on samsung s8 ,only this image is here no log is getting so it is hard to resolve , is anyone faced this issue before,
minimumSdk is 21
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
import 'package:splink/src/constants/app_colors.dart';
import 'package:splink/src/controllers/login_view_controllers.dart';
import 'package:splink/src/view/login_view/login_welcome_view.dart';
import 'package:splink/src/view/signup_view/signup_welcome_view.dart';
class LandingView extends StatefulWidget {
const LandingView({Key? key}) : super(key: key);
#override
State<LandingView> createState() => _LandingViewState();
}
class _LandingViewState extends State<LandingView> {
final signLoginController = Get.find<LoginViewController>();
final controller = PageController(
viewportFraction: 1,
keepPage: true,
);
List items = [
"assets/images/6D2Lmtv_X8A.png",
"assets/images/secondimage.png",
"assets/images/thirdImage.png"
];
List textItems = [
//first page of intro
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: const [
Text(
"Find and play sports at",
style: TextStyle(
fontSize: 28, color: Colors.white, fontWeight: FontWeight.bold),
),
Text(
"anywhere, anytime",
style: TextStyle(
fontSize: 28, color: Colors.white, fontWeight: FontWeight.bold),
),
SizedBox(
height: 25,
),
Text(
"splink helps you find, connect and organise activities",
style: TextStyle(
color: Colors.white,
),
),
Text(
"with other sports players easily at anywhere, anytime",
style: TextStyle(
color: Colors.white,
),
),
],
),
//second page of intro
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: const [
Text(
"Organise and manage",
style: TextStyle(
fontSize: 28, color: Colors.white, fontWeight: FontWeight.bold),
),
Text(
"activties easily",
style: TextStyle(
fontSize: 28, color: Colors.white, fontWeight: FontWeight.bold),
),
SizedBox(
height: 25,
),
Text(
"no more messy groups and missed activities.",
style: TextStyle(
color: Colors.white,
),
),
Text(
"Activity creation and RSVPs, calendar-tracking",
style: TextStyle(
color: Colors.white,
),
),
Text(
"or notifications, everything doe easily in-app",
style: TextStyle(
color: Colors.white,
),
),
],
),
//third page of intro
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: const [
Text(
"Meet, play and endorse",
style: TextStyle(
fontSize: 28, color: Colors.white, fontWeight: FontWeight.bold),
),
Text(
"one another",
style: TextStyle(
fontSize: 28, color: Colors.white, fontWeight: FontWeight.bold),
),
SizedBox(
height: 25,
),
Text(
"Have fun, encourage one another by exchanging medals,",
style: TextStyle(
color: Colors.white,
),
),
Text(
"track sports statistics and keep on playing!",
style: TextStyle(
color: Colors.white,
),
),
],
),
];
#override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
final pages = List.generate(
3,
(index) => Image.asset(
items[index],
fit: BoxFit.cover,
),
);
final pages2 = List.generate(3, (index) => textItems[index]);
return Scaffold(
backgroundColor: primaryColor,
body: Column(
children: [
Expanded(
child: ClipPath(
clipper: ClipPathClass(),
child: PageView.builder(
controller: controller,
padEnds: false,
// itemCount: pages.length,
itemBuilder: (_, index) {
return SizedBox(
height: size.height,
width: size.width,
child: pages[index % pages.length]);
},
onPageChanged: (value) {
signLoginController.curouselIndex(value % pages.length);
},
),
),
),
Expanded(
child: Container(
color: primaryColor,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
child: SmoothPageIndicator(
controller: controller,
count: 3,
effect: const ExpandingDotsEffect(
strokeWidth: 2.0,
dotColor: Colors.white,
activeDotColor: Colors.white,
dotHeight: 6,
dotWidth: 6,
),
),
),
const SizedBox(
height: 15,
),
Obx(
() => textItems[signLoginController.curouselIndex.value],
),
const SizedBox(
height: 70,
),
Padding(
padding: const EdgeInsets.only(right: 15, left: 15),
child: Material(
color: Colors.white,
borderRadius: BorderRadius.circular(15),
child: InkWell(
onTap: () {
Get.to(SignupWelcomeView());
},
borderRadius: BorderRadius.circular(15),
child: Container(
width: size.width,
height: 50,
alignment: Alignment.center,
child: Text(
'Sign Up',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w600,
color: primaryColor),
),
),
),
),
),
const SizedBox(
height: 20,
),
Padding(
padding: const EdgeInsets.only(right: 15, left: 15),
child: InkWell(
onTap: () {
Get.to(LoginWelcomeView());
},
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
border: Border.all(color: Colors.white),
),
width: size.width,
height: 50,
alignment: Alignment.center,
child: const Text(
'Login',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w600,
color: Colors.white),
),
),
),
),
],
),
),
)
],
),
);
}
}
class ClipPathClass extends CustomClipper<Path> {
#override
Path getClip(Size size) {
Path path = Path();
path.addOval(Rect.fromCircle(
center: Offset(size.width * 0.5, -10),
radius: size.height - 20,
));
return path;
}
#override
bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}
I mean, the "issue" is that the width/pixel density of the device is causing the text to overflow to the next line. You can either use a FittedBox, or tweak the fontSize to optimize it depending on the width (using MediaQuery or LayoutBuilder), both sould work.
You can also align the text on the center, instead of to the right, and I'd add some padding to ensure the text doesn't go right up to the screen border.
How do I auto scale down a font in a Text widget to fit the max number of lines?

Move elements in ConstrainedBox

I have a code that is responsible for displaying the characteristics of the device.
I put these characteristics in Column, wrapped Card, and listed everything.
I am attaching a short code example.
Container(
constraints: const BoxConstraints(maxWidth: 800),
decoration: BoxDecoration(
color: Colors.transparent,
borderRadius: BorderRadius.circular(5.0),
border: Border.all(
color: Colors.black,
width: 2,
),
),
child: Card(
child: Column(
children: [
Text(
'Location:',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
Text(
device.location,
style: const TextStyle(
fontSize: 18, fontWeight: FontWeight.w500),
),
const Divider(
color: Colors.black, endIndent: 10, indent: 10),
Text(
'Status:',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 250),
child: Padding(
padding:
const EdgeInsets.fromLTRB(30, 0, 0, 0),
child: Row(children: [
Expanded(
child: Text(
device.status.toString().substring(7),
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500),
),
),
Expanded(
child: (device.status == Status.booked)
? OutlinedButton(
onPressed: () async {
final user = await user_api
.getUser(device.userId);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
const UserCard(),
settings: RouteSettings(
arguments:
user, //TODO: check route
),
),
);
},
child: const Text("User",
style: TextStyle(
fontSize: 15,
color: Colors.black,
)),
style: OutlinedButton.styleFrom(
fixedSize: const Size(100, 15),
side: BorderSide(
width: 1.0,
color: Colors.black),
backgroundColor:
Colors.yellow[600],
),
)
: Text(''),
),
]))),
const Divider(
color: Colors.black, endIndent: 10, indent: 10),
],
),
),
),
const SizedBox(
height: 5,
),
Photo how it looks
But I would like to move the "User" button in the status column to the right. Tell me how can I do this?
The barrier is coming from BoxConstraints(maxWidth: 250). To handle view in row, we can use Row with mainAxisAlignment: MainAxisAlignment.spaceBetween, with Expanded 3 children for separation, also while using padding, provide save value on both side.
ConstrainedBox(
constraints:
const BoxConstraints(), //remove width, you can remove ConstrainedBox widget
child: Padding(
padding: const EdgeInsets.fromLTRB(
30, 0, 30, 0), // prvide same padding
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Expanded(
child: SizedBox()), //handle left sepration
const Expanded(
child: Text(
"device",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18, fontWeight: FontWeight.w500),
),
),
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: OutlinedButton(
onPressed: () async {},
child: const Text("User",
style: TextStyle(
fontSize: 15,
color: Colors.black,
)),
style: OutlinedButton.styleFrom(
fixedSize: const Size(100, 15),
side: BorderSide(
width: 1.0, color: Colors.black),
backgroundColor: Colors.yellow[600],
),
),
),
)
]))),

Column widget not positioning widgets properly when using Stack widget-Flutter

The first image is the design of the app from Figma. While the next image is the one which I am getting though I am using simple stack and columns. I am not being able to understand why it is coming out as such. The Text Widgets must be under the picture but they are going right at the bottom of the screen. Can anyone help me out with this one?
My code:
import 'package:flutter/material.dart';
import '../../app_theme.dart';
class ProfileScreen extends StatefulWidget {
const ProfileScreen({Key? key}) : super(key: key);
#override
_ProfileScreenState createState() => _ProfileScreenState();
}
class _ProfileScreenState extends State<ProfileScreen> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: AppTheme.lightBlue,
title: Text(
'Profile',
style: TextStyle(color: AppTheme.black100),
),
elevation: 0,
),
body: Column(
children: [
SizedBox(
height: 50,
),
Stack(
alignment: Alignment.center,
clipBehavior: Clip.none,
children: [
Container(
width: double.infinity,
height: 150,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(16),
topLeft: Radius.circular(16),
),
color: AppTheme.lightGrey),
),
Positioned(
top: -50,
child: _buildProfileDetails(),
),
],
)
],
),
backgroundColor: AppTheme.lightBlue,
drawer: Drawer(),
);
}
Widget _buildProfileDetails() {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Stack(
clipBehavior: Clip.none,
children: [
CircleAvatar(
radius: 50,
backgroundImage: AssetImage('assets/images/profile_photo.jpg'),
),
Positioned(
left: 78,
top: 60,
child: CircleAvatar(
radius: 14,
backgroundColor: AppTheme.blue,
child: Icon(Icons.camera_alt_outlined),
),
),
],
),
Text(
'Alexis Sanchez',
style: TextStyle(
color: AppTheme.black100,
fontSize: 22,
fontWeight: FontWeight.w600,
fontStyle: FontStyle.normal,
fontFamily: 'Poppins',
height: 33,
),
textAlign: TextAlign.center,
),
Text(
'Alexis Sanchez',
style: TextStyle(
color: AppTheme.black80,
fontSize: 12,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
fontFamily: 'Poppins',
height: 18,
),
textAlign: TextAlign.center,
),
Text(
'Alexis Sanchez',
style: TextStyle(
color: AppTheme.black80,
fontSize: 12,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
fontFamily: 'Poppins',
height: 18,
),
textAlign: TextAlign.center,
),
],
);
}
}
Stack widget extends and fills all the available space. if you want your stack to be smaller than all available space. wrap it inside a SizedBox widget.
If you need to control height, do like height: 1.2. and use mainAxisSize: MainAxisSize.min, on Column.
I am using different approach to gain this and will contain some extra widget for future purpose. Mostly describe on code-comment. If you face any issue while scaling/increasing size, adjust the parent Container size. Used demo color for design purpose.
Run on dartPad.
Result will be:
body: LayoutBuilder(
builder: (context, constraints) {
return Column(
children: [
/// header Part: Name, logo, info
Container(
color: Colors.grey,
height: kToolbarHeight * 3, //adjust box Stack size
child: Stack(
children: [
/// bottom Half background
Align(
alignment: Alignment.bottomCenter,
child: Container(
height: kToolbarHeight * 2,
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topRight: Radius.circular(16),
topLeft: Radius.circular(16),
),
),
),
),
/// center logo with info
Positioned(
bottom: 10,
left: 0,
right: 0,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(
height: 50 * 2, // from your logo radius
width: 50 * 2 +
7, //7 is from `camera_alt_outlined` to align
child: Stack(
children: const [
CircleAvatar(
radius: 50,
backgroundColor: Colors.deepPurple,
// backgroundImage: AssetImage(
// 'assets/images/profile_photo.jpg'),
),
Positioned(
bottom: 7,
right: 0,
child: CircleAvatar(
radius: 14,
backgroundColor: Colors.blue,
child: Icon(Icons.camera_alt_outlined),
),
)
],
),
),
///now rest of Text
const Text(
'Alexis Sanchez',
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.w600,
fontStyle: FontStyle.normal,
fontFamily: 'Poppins',
height: 1.2),
textAlign: TextAlign.center,
),
const Text(
'Alexis Sanchez',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
fontFamily: 'Poppins',
),
textAlign: TextAlign.center,
),
const Text(
'Alexis Sanchez',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
fontFamily: 'Poppins',
),
textAlign: TextAlign.center,
),
],
),
),
],
),
)
],
);
},
));
I would have put child in this container and put everything that I want on this background
Must use screenutil helps for different screen sizes
Container(
width: double.infinity,
height: 150,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(16.sp),
topLeft: Radius.circular(16.sp),
),
color: AppTheme.lightGrey),
),

Text widget with circular background in flutter

How can I get this type of rounded background in Text widget?
You can achieve it by
CircleAvatar(
backgroundColor: Colors.grey,
child: Center(
child: Text(
"B",
style: TextStyle(color: Colors.black),
),
),
)
Screenshot:
You can also use ClipOval
ClipOval(
child: Container(
color: Colors.grey,
padding: EdgeInsets.symmetric(horizontal: 30),
child: Text(
"B",
style: TextStyle(color: Colors.black, fontSize: 90),
),
),
)
Just use a FAB:
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.grey,
child: Text(
"A",
style: TextStyle(
fontSize: 20,
fontStyle: FontStyle.italic,
),
),
)