Text and Image Alignment in flutter - flutter

I want to keep a space between "Let your Style Speaks" and "Discover..." text. also want to align the image down from the top a little bit. here's my code and please help me to do those changes. I was trying but I'm unable to do this. can someone please send where want to be edited. I have attached UI for your reference. this is the current UI I want to be changed
import 'package:flutter/material.dart';
import 'home_page.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Auth Screen 1',
theme: ThemeData(
brightness: Brightness.light,
//primaryColor: kPrimaryColor,
// scaffoldBackgroundColor: kBackgroundColor,
textTheme: TextTheme(
headline4:
TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
// button: TextStyle(color: kPrimaryColor),
headline6:
TextStyle(color: Colors.white70, fontWeight: FontWeight.normal),
),
inputDecorationTheme: InputDecorationTheme(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.white.withOpacity(.2),
),
),
),
),
home: WelcomeScreen(),
);
}
}
class WelcomeScreen extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
// appBar: AppBar(
//
// backgroundColor: Color(0XFFd5ae48),
// ),
backgroundColor: Color(0XFFd5ae48),
body: Column(
children: <Widget>[
Expanded(
child: Container(
// height: MediaQuery.of(context).size.height * .4,
padding: EdgeInsets.only(top: 20),
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/girl.png"),
fit: BoxFit.cover,
),
),
),
flex: 2,
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 15,bottom:10),
child: RichText(
textAlign: TextAlign.left,
text: TextSpan(
children: [
TextSpan(
text: "Let Your\nStyles Speaks\n",
style: TextStyle( fontFamily: 'Sen',fontWeight: FontWeight.w700,fontSize: 30) ,
),
TextSpan(
text:
"Discover the latest trends in women fashion and explore your personality\n",
style: TextStyle( fontFamily: 'Sen',fontSize: 15) ,
)
],
),
),
),
FittedBox(
child: GestureDetector(
onTap: () {
Navigator.push(context, MaterialPageRoute(
builder: (context) {
return HomePage();
},
));
},
child: Container(
margin: EdgeInsets.only(bottom: 30),
padding: EdgeInsets.symmetric(horizontal: 26, vertical: 16),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25),
color: Colors.black,
),
child: Row(
children: <Widget>[
Text(
"Get started",
style: TextStyle(fontFamily:'sen',
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 20),
),
SizedBox(width: 10),
Icon(
Icons.arrow_forward,
color: Colors.white,
)
],
),
),
),
),
],
),
),
],
),
);
}
}

You can use SafeArea for the app bar and in RichText you can use text span as <InlineSpan> and then you can able to use WidgetSpan. That helps you to use space between two spans.
TextSpan Part
TextSpan(
children: <InlineSpan>[
TextSpan(
text: "Let Your\nStyles Speaks\n",
style: TextStyle(
fontFamily: 'Sen',
fontWeight: FontWeight.w700,
fontSize: 30),
),
WidgetSpan(
child: Container(
height: 30,
)),
TextSpan(
text:
"Discover the latest trends in women fashion and explore your personality\n",
style: TextStyle(fontFamily: 'Sen', fontSize: 15),
)
],
)
complete code
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Auth Screen 1',
theme: ThemeData(
brightness: Brightness.light,
//primaryColor: kPrimaryColor,
// scaffoldBackgroundColor: kBackgroundColor,
textTheme: TextTheme(
headline4:
TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
// button: TextStyle(color: kPrimaryColor),
headline6:
TextStyle(color: Colors.white70, fontWeight: FontWeight.normal),
),
inputDecorationTheme: InputDecorationTheme(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.white.withOpacity(.2),
),
),
),
),
home: WelcomeScreen(),
);
}
}
class WelcomeScreen extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
// appBar: AppBar(
//
// backgroundColor: Color(0XFFd5ae48),
// ),
backgroundColor: Color(0XFFd5ae48),
body: SafeArea(
child: Column(
children: <Widget>[
Expanded(
child: Container(
// height: MediaQuery.of(context).size.height * .4,
padding: EdgeInsets.only(top: 20),
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/test.jpg"),
fit: BoxFit.cover,
),
),
),
flex: 2,
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 15, bottom: 10),
child: RichText(
textAlign: TextAlign.left,
text: TextSpan(
children: <InlineSpan>[
TextSpan(
text: "Let Your\nStyles Speaks\n",
style: TextStyle(
fontFamily: 'Sen',
fontWeight: FontWeight.w700,
fontSize: 30),
),
WidgetSpan(
child: Container(
height: 30,
)),
TextSpan(
text:
"Discover the latest trends in women fashion and explore your personality\n",
style: TextStyle(fontFamily: 'Sen', fontSize: 15),
)
],
),
),
),
FittedBox(
child: GestureDetector(
onTap: () {
Navigator.push(context, MaterialPageRoute(
builder: (context) {
return Container();
},
));
},
child: Container(
margin: EdgeInsets.only(bottom: 30),
padding:
EdgeInsets.symmetric(horizontal: 26, vertical: 16),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25),
color: Colors.black,
),
child: Row(
children: <Widget>[
Text(
"Get started",
style: TextStyle(
fontFamily: 'sen',
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 20),
),
SizedBox(width: 10),
Icon(
Icons.arrow_forward,
color: Colors.white,
)
],
),
),
),
),
],
),
),
],
),
),
);
}
}

Related

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

I'm practising this code github to add a home screen with cards as pictures shown below. after the get started button clicks it should redirect to the home page with cards. cards are not still designed like the picture shows. the code I used to get cards is not working. can someone know how to fix this? no errors on main. dart. error is in home_page.dart. think I'm missing some codes.
error shows ----> Missing concrete implementation of 'StatefulWidget.createState'.
home_page.dart
import 'package:flutter/material.dart';
import 'package:fashion_app/color_filters.dart';
class HomePage extends StatefulWidget{
#override
_HomePageState createSatate ()=> _HomePageState();
}
class _HomePageState extends State <HomePage> {
final double _borderRadious = 24;
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Fashion store'),
),
body: ListView(
padding: EdgeInsets.all(16),
children: [
buildQuoteCard(),
buildRoundedCard(),
buildColoredCard(),
buildImageCard(),
buildImageInteractionCard(),
],
),
)
);
}
Widget buildQuoteCard() =>
Card(
child: Padding(
padding: EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'If life were predictable it would cease to be life,
and be without flavor.',
style: TextStyle(fontSize: 24),
),
const SizedBox(height: 12),
Text(
'Eleanor Roosevelt',
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
),
],
),
),
);
Widget buildRoundedCard() =>
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
child: Container(
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Rounded card',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 4),
Text(
'This card is rounded',
style: TextStyle(fontSize: 20),
),
],
),
),
);
Widget buildColoredCard() =>
Card(
shadowColor: Colors.red,
elevation: 8,
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.redAccent, Colors.red],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Colored card',
style: TextStyle(
fontSize: 20,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 4),
Text(
'This card is rounded and has a gradient',
style: TextStyle(
fontSize: 20,
color: Colors.white,
),
),
],
),
),
);
Widget buildImageCard() =>
Card(
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
),
child: Stack(
alignment: Alignment.center,
children: [
Ink.image(
image: NetworkImage(
'https://images.unsplash.com/photo-1514888286974-6c03e2ca1dba?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1327&q=80',
),
colorFilter: ColorFilters.greyscale,
child: InkWell(
onTap: () {},
),
height: 240,
fit: BoxFit.cover,
),
Text(
'Card With Splash',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 24,
),
),
],
),
);
Widget buildImageInteractionCard() =>
Card(
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
),
child: Column(
children: [
Stack(
children: [
Ink.image(
image: NetworkImage(
'https://images.unsplash.com/photo-1514888286974-6c03e2ca1dba?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1327&q=80',
),
height: 240,
fit: BoxFit.cover,
),
Positioned(
bottom: 16,
right: 16,
left: 16,
child: Text(
'Cats rule the world!',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 24,
),
),
),
],
),
Padding(
padding: EdgeInsets.all(16).copyWith(bottom: 0),
child: Text(
'The cat is the only domesticated species in the family Felidae and is often referred to as the domestic cat to distinguish it from the wild members of the family.',
style: TextStyle(fontSize: 16),
),
),
ButtonBar(
alignment: MainAxisAlignment.start,
children: [
FlatButton(
child: Text('Buy Cat'),
onPressed: () {},
),
FlatButton(
child: Text('Buy Cat Food'),
onPressed: () {},
)
],
)
],
),
);
}
> main. dart
import 'package:flutter/material.dart';
import 'constants.dart';
import 'home_page.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Auth Screen 1',
theme: ThemeData(
brightness: Brightness.light,
primaryColor: kPrimaryColor,
scaffoldBackgroundColor: kBackgroundColor,
textTheme: TextTheme(
headline4: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
button: TextStyle(color: kPrimaryColor),
headline6: TextStyle(color: Colors.white70, fontWeight: FontWeight.normal),
),
inputDecorationTheme: InputDecorationTheme(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.white.withOpacity(.2),
),
),
),
),
home: WelcomeScreen(),
);
}
}
class WelcomeScreen extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0XFFd5ae48),
body: Column(
children: <Widget>[
Expanded(
child: Container(
height: MediaQuery.of(context).size.height*.4,
padding: EdgeInsets.all(10.0),
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/girl.png"),
fit: BoxFit.cover,
),
),
),
flex: 3,
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
RichText(
textAlign: TextAlign.left,
text: TextSpan(
children: [
TextSpan(
text: "Let Your Styles Speaks\n",
style: Theme.of(context).textTheme.headline4,
),
TextSpan(
text: "Discover the latest trends in women fashion and explore your personality\n",
style: Theme.of(context).textTheme.headline6,
)
],
),
),
FittedBox(
child: GestureDetector(
onTap: () {
Navigator.push(context, MaterialPageRoute(
builder: (context) {
return HomePage();
},
));
},
child: Container(
margin: EdgeInsets.only(bottom: 25),
padding: EdgeInsets.symmetric(horizontal: 26, vertical: 16),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25),
color: Colors.black,
),
child: Row(
children: <Widget>[
Text(
"Get started",
style: Theme.of(context).textTheme.button?.copyWith(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 20
),
),
SizedBox(width: 10),
Icon(
Icons.arrow_forward,
color: Colors.white,
)
],
),
),
),
),
],
),
),
],
),
);
}
}
https://api.flutter.dev/flutter/widgets/StatefulWidget/createState.html
Change this,
class HomePage extends StatefulWidget{
#override
_HomePageState createSatate ()=> _HomePageState(); // change createSatate to createState
}
To,
class HomePage extends StatefulWidget{
#override
_HomePageState createState ()=> _HomePageState();
}
class HomePage extends StatefulWidget{
#override
_HomePageState createSatate ()=> _HomePageState();
}
It's because of a typo.
Change createSatate to createState.
Your Homepage class will look like
class HomePage extends StatefulWidget{
#override
_HomePageState createState ()=> _HomePageState();
}

How to align bottom container inside listview?

I wanted to aling a button to the bottom center of the listview.
Scaffold(
backgroundColor: Colors.white,
appBar: buildAppBar(context, ''),
body: ListView(
physics: ClampingScrollPhysics(),
children: [
Column(
children: [
Text(
'check up',
style: TextStyle(
fontSize: 35,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
SizedBox(height: 12),
Text(
'SachsenwaldStr. 3. 12157 Berlin',
style: TextStyle(
fontSize: 20,
color: Colors.black,
),
),
],
),
Spacer(),
buildNextButton(context),
],
),
I tried using Align, but it didn't work, and Spacer() didn't too:
Align(
alignment: Alignment.bottomCenter,
child: buildNextButton(context),
),
is there any way to align buildNextButton to the bottom?
return Scaffold(
body: Stack(
children: [
Positioned(
bottom: 0,
width: MediaQuery.of(context).size.width,
child: Center(
child: MaterialButton(
child: Text("My button"),
onPressed: () {},
color: Colors.red,
),
),
),
ListView(
children: [
Text(
'check up',
style: TextStyle(
fontSize: 35,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
SizedBox(height: 12),
Text(
'SachsenwaldStr. 3. 12157 Berlin',
style: TextStyle(
fontSize: 20,
color: Colors.black,
),
),
],
)
],
));
You can use Scaffold Properties to make a button centre at the bottom. Hope it would be helpful for you,Thanks
import 'package:flutter/material.dart';
class BottomButton extends StatefulWidget {
const BottomButton({Key? key}) : super(key: key);
#override
_BottomButtonState createState() => _BottomButtonState();
}
class _BottomButtonState extends State<BottomButton> {
#override
Widget build(BuildContext context) {
return Scaffold(
///you can make the centre button use floating action Button and
provide its location
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.transparent,
child: Container(
width: MediaQuery.of(context).size.width,
color: Colors.green,
child: Text(
"Button")),
onPressed: () {},
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
appBar: AppBar(
title: Text("MyAppBar"),
),
body: ListView(
physics: ClampingScrollPhysics(),
children: [
Column(
children: [
Text(
'check up',
style: TextStyle(
fontSize: 35,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
SizedBox(height: 12),
Text(
'SachsenwaldStr. 3. 12157 Berlin',
style: TextStyle(
fontSize: 20,
color: Colors.black,
),
),
],
),
],
),
///bottom sheet place button at bottom without using space
bottomSheet: Container(
width: MediaQuery.of(context).size.width,
color: Colors.green,
child: TextButton(onPressed: () {}, child: Text("Button"))),
);
}
}
You can wrap your Align widget with Expanded and in Align widget use alignment: FractionalOffset.bottomCenter .
Please find below link to get more clear idea - Button at bottom
I suggest to wrap ListView and builtNextButton with Stack Widget.
Because when ListView children is bigger than screen height, button can not be located bottom.
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
Widget buildNextButton(context) {
return Container(height: 40, color: Colors.green);
}
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: darkBlue,
),
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: Colors.white,
//appBar: buildAppBar(context, ''),
body: Stack(
children: [
ListView(
physics: const ClampingScrollPhysics(),
children: [
Column(
children: [
Text(
'check up',
style: TextStyle(
fontSize: 35,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
SizedBox(height: 12),
Text(
'SachsenwaldStr. 3. 12157 Berlin',
style: TextStyle(
fontSize: 20,
color: Colors.black,
),
),
],
),
],
),
Align(
alignment: Alignment.bottomCenter,
child: buildNextButton(context),
),
],
),
),
);
}
}
Now the only way you can use it in a list view is if you are to pas it in a column widget, so the order would become, column -> Expanded -> ListView andoutside the expanded, that is where you now pass the button. Just copy and paste my code here, Hopefully it works for you.
Scaffold(
body: Column(
children: [
Expanded(
child: ListView(
// physics: ClampingScrollPhysics(),
children: [
Column(
children: [
Text(
'check up',
style: TextStyle(
fontSize: 35,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
SizedBox(height: 12),
Text(
'SachsenwaldStr. 3. 12157 Berlin',
style: TextStyle(
fontSize: 20,
color: Colors.black,
),
),
],
),
// buildNextButton(context),
],
),
),
Container(
child: Center(
child: buildNextButton()
),
)
],
),
)
and then the buildNextButton code is
buildNextButton() {
return ElevatedButton(
style: ElevatedButton.styleFrom(textStyle: const TextStyle(fontSize: 20))
,
onPressed: () {},
child: const Text('Enabled'),
);
}
the moment you render a listview as aparent widget, automatically it renders all items in alist, one after the other.
anyquestions, am available to help you out
Good luck bro

How do i make background images in container widget change in flutter

I am a newbie to flutter, i am building a website with flutter, i want my container background image to be changing like a carousel. i have tried the carousel widget it works, but it doesnt allow my images to be full width and height. if i can get a way i can make the background image change while maintaining the full screen size, ill appreciate. thanks
here is my code.
import 'dart:ui';
//import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:hexcolor/hexcolor.dart';
void main() {
runApp(
MyApp(),
);
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Udos Computers',
home: Scaffold(
extendBodyBehindAppBar: true,
appBar: PreferredSize(
preferredSize: Size(double.infinity, 70.0),
child: ClipRRect(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
child: AppBar(
toolbarHeight: 70,
backgroundColor: Colors.black87.withOpacity(0.4),
leading: Image(
image: AssetImage('images/udx.jpg'),
),
title: Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
TextButton(
onPressed: () {},
child: Text(
'PC BUILDER',
style: GoogleFonts.lato(
fontWeight: FontWeight.w800,
color: Colors.white70,
),
),
),
SizedBox(
width: 24,
),
TextButton(
onPressed: () {},
child: Text(
'SHOP',
style: GoogleFonts.lato(
fontWeight: FontWeight.w800,
color: Colors.white70,
),
),
),
SizedBox(
width: 24,
),
TextButton(
onPressed: () {},
child: Text(
'ABOUT US',
style: GoogleFonts.lato(
fontWeight: FontWeight.w800,
color: Colors.white70,
),
),
),
SizedBox(
width: 24,
),
TextButton(
onPressed: () {},
child: Text(
'CONTACT',
style: GoogleFonts.lato(
fontWeight: FontWeight.w800,
color: Colors.white70,
),
),
),
SizedBox(
width: 24,
),
],
),
),
),
),
),
// backgroundColor: Colors.red,
body: Container(
// width: double.infinity,
decoration: BoxDecoration(
color: Colors.black,
image: DecorationImage(
colorFilter: new ColorFilter.mode(
Colors.black.withOpacity(0.4), BlendMode.dstATop),
image: AssetImage('images/udx.jpeg'),
fit: BoxFit.cover,
),
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'We Build Customized Gaming\n computers',
textAlign: TextAlign.center,
style: GoogleFonts.lato(
fontWeight: FontWeight.w900,
fontStyle: FontStyle.normal,
fontSize: 74,
color: Colors.white,
letterSpacing: -2,
),
),
Padding(
padding: const EdgeInsets.only(top: 24),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ButtonBar(
alignment: MainAxisAlignment.center,
children: [
SizedBox(
height: 50,
width: 150,
child: ElevatedButton(
style: TextButton.styleFrom(
backgroundColor: HexColor('#D91702'),
),
onPressed: () {},
child: Text(
'PC Builder',
style: GoogleFonts.lato(
fontSize: 16,
fontWeight: FontWeight.w500,
fontStyle: FontStyle.normal,
letterSpacing: 0.3),
),
),
),
SizedBox(
height: 50,
width: 150,
child: OutlinedButton(
style: OutlinedButton.styleFrom(
// backgroundColor: Colors.red
side: BorderSide(color: Colors.white),
),
onPressed: () {},
child: Text(
'Learn More',
style: GoogleFonts.lato(
fontWeight: FontWeight.w500,
fontSize: 16,
fontStyle: FontStyle.normal,
letterSpacing: 0.3,
color: Colors.white70,
),
),
),
),
],
)
],
),
)
],
),
),
),
),
);
}
}
Here you go, I think this is how you wanted it to be. All you have to do is, instead of using one Container() you need two Containers Stacked on top of each other using Stack() and the top container needs to be transparent with the Column() data and the bottom Container() can be a Carousel Slider with DecorationImage and colorFilter. I completed the code for you, you can test it out.
import 'dart:ui';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:hexcolor/hexcolor.dart';
void main() {
runApp(
const MyApp(),
);
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Udos Computers',
home: Scaffold(
extendBodyBehindAppBar: true,
appBar: PreferredSize(
preferredSize: const Size(double.infinity, 70.0),
child: ClipRRect(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
child: AppBar(
toolbarHeight: 70,
backgroundColor: Colors.black87.withOpacity(0.4),
leading: const Image(
image: AssetImage('images/udx.jpg'),
),
title: Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
TextButton(
onPressed: () {},
child: Text(
'PC BUILDER',
style: GoogleFonts.lato(
fontWeight: FontWeight.w800,
color: Colors.white70,
),
),
),
const SizedBox(
width: 24,
),
TextButton(
onPressed: () {},
child: Text(
'SHOP',
style: GoogleFonts.lato(
fontWeight: FontWeight.w800,
color: Colors.white70,
),
),
),
const SizedBox(
width: 24,
),
TextButton(
onPressed: () {},
child: Text(
'ABOUT US',
style: GoogleFonts.lato(
fontWeight: FontWeight.w800,
color: Colors.white70,
),
),
),
const SizedBox(
width: 24,
),
TextButton(
onPressed: () {},
child: Text(
'CONTACT',
style: GoogleFonts.lato(
fontWeight: FontWeight.w800,
color: Colors.white70,
),
),
),
const SizedBox(
width: 24,
),
],
),
),
),
),
),
body: Stack(children: [
CarouselSlider(
options: CarouselOptions(
autoPlay: true,
height: double.infinity,
viewportFraction: 1.0,
enlargeCenterPage: false,
),
items: [
Container(
decoration: BoxDecoration(
color: Colors.grey[900],
image: DecorationImage(
colorFilter: ColorFilter.mode(
Colors.black.withOpacity(0.4), BlendMode.dstATop),
image: const AssetImage('images/udx.jpg'),
fit: BoxFit.cover,
),
),
)
]),
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'We Build Customized Gaming\n computers',
textAlign: TextAlign.center,
style: GoogleFonts.lato(
fontWeight: FontWeight.w900,
fontStyle: FontStyle.normal,
fontSize: 74,
color: Colors.white,
letterSpacing: -2,
),
),
Padding(
padding: const EdgeInsets.only(top: 24),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ButtonBar(
alignment: MainAxisAlignment.center,
children: [
SizedBox(
height: 50,
width: 150,
child: ElevatedButton(
style: TextButton.styleFrom(
backgroundColor: HexColor('#D91702'),
),
onPressed: () {},
child: Text(
'PC Builder',
style: GoogleFonts.lato(
fontSize: 16,
fontWeight: FontWeight.w500,
fontStyle: FontStyle.normal,
letterSpacing: 0.3),
),
),
),
SizedBox(
height: 50,
width: 150,
child: OutlinedButton(
style: OutlinedButton.styleFrom(
// backgroundColor: Colors.red
side: const BorderSide(color: Colors.white),
),
onPressed: () {},
child: Text(
'Learn More',
style: GoogleFonts.lato(
fontWeight: FontWeight.w500,
fontSize: 16,
fontStyle: FontStyle.normal,
letterSpacing: 0.3,
color: Colors.white70,
),
),
),
),
],
)
],
),
)
],
),
),
]),
),
);
}
}

How can I parse the scanned result data received from my barcode scanner to a new screen or page in flutter

This is because I am trying to implement a bar a barcode reader to scan staff Id cards. so, all I want to achieve is when an agent assigned to scan the card performs a scan, it should display the scanned results in another page not the same screen or widget.
In simple terms just like you have todo list and when you click on a todo it will find the todo id and take you to a todo details page. That means a link to staff details page will be encoded into barcode so when you scan it would take you to the staff details page. But I don't know how to go about it.
This is what I have done below. This performs the scan quite ok but displaying the result is the problem.
import 'dart:async';
import 'package:erg_app/ScanPage.dart';
import 'package:erg_app/eops.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:barcode_scan/barcode_scan.dart';
import 'package:erg_app/Animations/FadeAnimation.dart';
import 'package:flutter/services.dart';
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: StartScanPage(),
)
);
}
class StartScanPage extends StatefulWidget {
#override
StartScanPageState createState() {
return StartScanPageState();
}
}
class StartScanPageState extends State<StartScanPage> {
String result = "Bio Data:";
Future _scanQR() async {
try {
String qrResult = await BarcodeScanner.scan();
setState(() {
result = qrResult;
});
} on PlatformException catch (ex) {
if (ex.code == BarcodeScanner.CameraAccessDenied) {
setState(() {
result = "Camera permission was denied";
});
} else {
setState(() {
result = "Unknown Error $ex";
});
}
} on FormatException {
setState(() {
result = "You pressed the back button before scanning anything";
});
} catch (ex) {
setState(() {
result = "Unknown Error $ex";
});
}
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
width: double.infinity,
height: MediaQuery.of(context).size.height,
padding: EdgeInsets.symmetric(horizontal: 30, vertical: 50),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Column(
children: <Widget>[
FadeAnimation(1, Text("Verify Farmer",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 30
),)),
SizedBox(height: 20,),
FadeAnimation(1.2, Text("Automatic identity verification which enables you to verify each farmer applicant",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.grey[700],
fontSize: 15
),)),
],
),
FadeAnimation(1.4, Container(
height: MediaQuery.of(context).size.height / 3,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/illustration1.png')
)
),
)),
Column(
children: <Widget>[
FadeAnimation(1.5, MaterialButton(
color: Colors.green,
minWidth: double.infinity,
height: 60,
onPressed: _scanQR,
// () {
// Navigator.push(context, MaterialPageRoute(builder: (context) => ScanPage()));
// },
shape: RoundedRectangleBorder(
side: BorderSide(
color: Colors.green
),
borderRadius: BorderRadius.circular(50)
),
child: Text("Start Scan", style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 18
),),
)),
SizedBox(height: 20,),
FadeAnimation(1.6, Container(
// padding: EdgeInsets.only(top: 3, left: 3),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50),
border: Border(
bottom: BorderSide(color: Colors.green),
top: BorderSide(color: Colors.green),
left: BorderSide(color: Colors.green),
right: BorderSide(color: Colors.green),
)
),
child: MaterialButton(
minWidth: double.infinity,
height: 60,
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => EopPage()));
},
color: Colors.white,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50)
),
child: Text("Cancel", style: TextStyle(
// color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 18
), ),
),
))
],
)
],
),
),
),
);
}
}
I want to display the result here:
import 'package:flutter/material.dart';
import 'package:erg_app/CaptureInputsPage.dart';
void main() {
runApp(ProfilePage());
}
class ProfilePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: new Center(child: Text('Farmers Data', textAlign: TextAlign.left)),
iconTheme: IconThemeData(color: Colors.white),
backgroundColor: Colors.green,
leading: IconButton(
icon: Icon(Icons.assignment_ind),
onPressed: () {},
),
),
body: Container(
child: ListView(
children: <Widget>[
Container(margin: EdgeInsets.only(top: 20),),
CircleAvatar(
radius: 80,
backgroundColor: Colors.grey,
),
Text(
'Yusuf Danladi',
style: TextStyle(
fontFamily: 'SourceSansPro',
fontSize: 25,
),
textAlign: TextAlign.center,
),
Text(
'Welcome',
style: TextStyle(
fontSize: 20,
fontFamily: 'SourceSansPro',
color: Colors.green[400],
letterSpacing: 2.5,
),
textAlign: TextAlign.center,
),
Container(margin: EdgeInsets.only(top: 20),),
SizedBox(
height: 20.0,
width: 200,
child: Divider(
color: Colors.teal[100],
),
),
Text(
'Farmer Details',
textAlign: TextAlign.center,
),
Card(
color: Colors.white,
margin:
EdgeInsets.symmetric(vertical: 10.0, horizontal: 25.0),
child: ListTile(
leading: Text(
'Phone:',
style: TextStyle(
fontSize: 20,
fontFamily: 'SourceSansPro',
color: Colors.green[700],
letterSpacing: 2.5,
),
),
title: Text(
'+234 801 000 4504',
style:
TextStyle(fontFamily: 'BalooBhai', fontSize: 20.0),
),
),
),
Card(
color: Colors.white,
margin:
EdgeInsets.symmetric(vertical: 10.0, horizontal: 25.0),
child: ListTile(
leading: Text(
'BVN:',
style: TextStyle(
fontSize: 20,
fontFamily: 'SourceSansPro',
color: Colors.green[700],
letterSpacing: 2.5,
),
),
title: Text(
'22108691911',
style:
TextStyle(fontFamily: 'BalooBhai', fontSize: 20.0),
),
),
),
Card(
color: Colors.white,
margin:
EdgeInsets.symmetric(vertical: 10.0, horizontal: 25.0),
child: ListTile(
leading: Text(
'Appicant ID:',
style: TextStyle(
fontSize: 20,
fontFamily: 'SourceSansPro',
color: Colors.green[700],
letterSpacing: 2.5,
),
),
title: Text(
'ERG-108691911',
style:
TextStyle(fontFamily: 'BalooBhai', fontSize: 20.0),
),
),
),
Card(
color: Colors.white,
margin:
EdgeInsets.symmetric(vertical: 10.0, horizontal: 25.0),
child: ListTile(
leading: Text(
'State/LGA:',
style: TextStyle(
fontSize: 20,
fontFamily: 'SourceSansPro',
color: Colors.green[700],
letterSpacing: 2.5,
),
),
title: Text(
'Taraba/Ussa',
style:
TextStyle(fontFamily: 'BalooBhai', fontSize: 20.0),
),
),
),
Card(
color: Colors.white,
margin:
EdgeInsets.symmetric(vertical: 10.0, horizontal: 25.0),
child: ListTile(
leading: Text(
'Farm Size:',
style: TextStyle(
fontSize: 20,
fontFamily: 'SourceSansPro',
color: Colors.green[700],
letterSpacing: 2.5,
),
),
title: Text(
'5000 meter sq',
style:
TextStyle(fontFamily: 'BalooBhai', fontSize: 20.0),
),
),
),
Card(
color: Colors.white,
margin:
EdgeInsets.symmetric(vertical: 10.0, horizontal: 25.0),
child: ListTile(
leading: Text(
'Geo Coord.:',
style: TextStyle(
fontSize: 20,
fontFamily: 'SourceSansPro',
color: Colors.green[700],
letterSpacing: 2.5,
),
),
title: Text(
'012350007, 038245543',
style:
TextStyle(fontFamily: 'BalooBhai', fontSize: 20.0),
),
),
),
Container(
margin: EdgeInsets.only(top: 20, bottom: 30),
child: Center(
child: RaisedButton(
padding: EdgeInsets.fromLTRB(80, 10, 80, 10),
color: Colors.green,
child: Text("Complete", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 14), ),
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(builder: (context) => CaptureInputsPage()));
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50),
),
),
),
),
],
),
),
),
);
}
}
After getting the result from qrcode, you can simply use MaterialPageRoute.
Future _scanQR() async {
try {
String qrResult = await BarcodeScanner.scan();
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ProfilePage(qrResult),
),
);
} on PlatformException catch (ex) {
....
}
}
Create ProfilePage as
class ProfilePage extends StatelessWidget {
final String result;
ProfilePage(this.result);
....
}

Flutter: How to set variable length string inside a row?

I am trying to set a string inside a row, but the length of the string is variable i.e data is fetched from API. Then it is set inside the row, but currently, as the length is greater it shows as A RenderFlex overflowed by 48 pixels on the right.
I am been trying to use expanded/flex/flexible but getting incorrect parent error. (Don't know how to as I am new to flutter)
So, please help in how to solve this problem of renderflex overflow.
Following is my method:
void confirmpayment(double amount, String description) {
final itemsSubmit = <Widget>[
Image.asset(
'images/payments.jpg',
width: MediaQuery.of(context).size.width,
fit: BoxFit.contain,
),
ListTile(
title: AutoSizeText(
'Confirmation',
style: TextStyle(fontSize: 20),
),
subtitle: AutoSizeText(
'Hey Gaurav, please confirm examination as payment once done will be irrevocable.',
style: TextStyle(color: Colors.grey),
),
// onTap: () {},
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 20,
),
Padding(
padding: EdgeInsets.only(top: 10),
child: AutoSizeText(
'Exam:',
textAlign: TextAlign.start,
style: TextStyle(
fontSize: 16,
),
),
),
Spacer(),
CheckboxGroup(
orientation: GroupedButtonsOrientation.VERTICAL,
labelStyle: TextStyle(fontSize: 15),
labels: [
...listexam.map((location) {
return location['name']; //this is where string is set from api data
}).toList()
],
checked: _checked,
),
SizedBox(
width: 20,
),
],
),
Divider(),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 20,
),
Padding(
padding: EdgeInsets.only(top: 1),
child: AutoSizeText(
'Plan',
textAlign: TextAlign.start,
style: TextStyle(
fontSize: 16,
),
),
),
Expanded(
child: Padding(
padding: EdgeInsets.only(top: 1),
child: AutoSizeText(
description,
textAlign: TextAlign.right,
textDirection: TextDirection.ltr,
style: TextStyle(
fontSize: 15,
),
),
),
),
SizedBox(
width: 20,
),
]),
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 20,
),
Padding(
padding: EdgeInsets.only(top: 1),
child: AutoSizeText(
'Amount',
textAlign: TextAlign.start,
style: TextStyle(
fontSize: 16,
),
)),
Expanded(
child: Padding(
padding: EdgeInsets.only(top: 1),
child: AutoSizeText(
'Rs. ' + amount.toString(),
textDirection: TextDirection.ltr,
textAlign: TextAlign.right,
style: TextStyle(
fontSize: 15,
// fontWeight: FontWeight.w500,
),
),
),
),
SizedBox(
width: 20,
),
]),
SizedBox(
height: 40,
),
Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: <Widget>[
RaisedButton(
elevation: 1,
// onPressed: _showSheetSubmit,
color: Colors.grey[200],
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(28.0),
side: BorderSide(color: Colors.grey[200])),
onPressed: null,
child: AutoSizeText(
"Cancel",
style: TextStyle(
fontSize: 16,
// fontFamily: 'lato',
letterSpacing: 1,
color: Colors.white,
),
)),
RaisedButton(
elevation: 1,
color: Colors.green,
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(28.0),
side: BorderSide(color: Colors.green)),
onPressed: () {
openCheckout(amount, description);
},
child: AutoSizeText(
"Buy",
style: TextStyle(
fontSize: 16,
// fontFamily: 'lato',
color: Colors.white,
letterSpacing: 1),
)),
]),
SizedBox(
height: MediaQuery.of(context).size.height / 12,
),
];
showModalBottomSheet(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
backgroundColor: Colors.white,
context: context,
builder: (BuildContext _) {
return Container(
// color: Colors.white,
child: Wrap(
children: itemsSubmit,
),
);
},
isScrollControlled: true,
// isDismissible: true
);
}
Following is the mock:
Instead of trying to trim the String data that will go into the Text widget, I would use a LayoutBuilder to get the available space that the Row widget could occupy. Then, I would wrap the Text in a SizedBox to limit the maximum width of the Text widget. Finally, I would set the overflow property of the Text widget, so that it shows an ellipsis when the text is longer than the available space.
Here is a little app I wrote for you to see how to do this. You can run it on DartPad to play around with it.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
LayoutBuilder(
builder: (context, constraints) {
return Row(
children: <Widget>[
SizedBox(
width: constraints.maxWidth,
child: Text(
'This is a very very long text that might overflow the available rendering space',
overflow: TextOverflow.ellipsis,
),
),
],
);
},
),
],
),
),
);
}
}