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,
),
),
),
),
],
)
],
),
)
],
),
),
]),
),
);
}
}
Related
I have a ListView.builder wrapped with a SingleChildScrollView, and each has its scroll, so when I click at the ListView it only scroll the ListView without Scroll the SingleChildScrollView, and my ListView is dynamic so I can't use physics: const NeverScrollableScrollPhysics() because it disable my ListVeiw.builder
I want to Scroll the main screen which has some widgets and the ListView, builder in the middle and in last has a bottom
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"Carrinho",
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 18,
fontFamily: 'Inter'),
),
),
body: SingleChildScrollView(
child: Column(
children: [
Stack(
children: <Widget>[
Container(
width: 400,
child: Image.asset('assets/images/cover.jpg'),
),
Center(
child: Column(
children: [
SizedBox(height: 60),
Text(
"MEU CESTO",
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 30,
fontFamily: 'Inter'),
),
],
),
),
],
),
Container(
height: 80,
padding: const EdgeInsets.all(15),
decoration: BoxDecoration(
color: sGreenColour,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10),
),
),
child: Container(
child: Column(
children: [
Row(children: [
Text(
"ITENS: ",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 16),
),
Text("$itemsQtd",
style: TextStyle(color: Colors.white, fontSize: 16))
]),
Row(children: [
Text("TOTAL: ",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 18)),
Text("$totalValue MT",
style: TextStyle(color: Colors.white, fontSize: 18))
])
],
),
),
),
Container(
height: MediaQuery.of(context).size.height,
// HERE MY ListView.buider
child: CartProducts(
cart_list: cart_list,
),
),
SizedBox(height: 40),
Container(
width: MediaQuery.of(context).size.width - 30,
child: Row(
children: [
Container(
height: 50,
width: (MediaQuery.of(context).size.width / 2) - 15,
child: ElevatedButton(
onPressed: () {},
child: Text("$totalValue MT",
style: TextStyle(color: sGreenColour)),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(
sGreenLightColour),
shape:
MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
),
),
),
),
),
Container(
height: 50,
width: (MediaQuery.of(context).size.width / 2) - 15,
child: ElevatedButton(
onPressed: () {},
child: Text(
"TERMINAR",
style: TextStyle(color: Colors.white),
),
style: ButtonStyle(
shape:
MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
side: BorderSide(color: sGreenColour),
),
),
),
),
)
],
),
),
SizedBox(height: 10),
],
),
));
}
}
and my ListView.builder
class _CartProductsState extends State<CartProducts> {
#override
Widget build(BuildContext context) {
return ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(), // Disable Scroll
itemCount: widget.cart_list.length,
itemBuilder: (BuildContext context, int index) {
return SigleProduct(
name: widget.cart_list[index]["name"],
picture: widget.cart_list[index]["picture"],
price: widget.cart_list[index]["price"],
unit: widget.cart_list[index]["unit"],
);
});
}
}
// THE ELEMENT OF THE GRIDVIEW
class SigleProduct extends StatelessWidget {
SigleProduct({this.name, this.picture, this.price, this.unit})
: super(key: null);
final name;
final picture;
final price;
final unit;
showAlertDialog(BuildContext context, int id) {
// set up the buttons
Widget cancelButton = TextButton(
child: Text("Não"),
onPressed: () {
Navigator.of(context).pop(); // dismiss dialog
},
);
Widget continueButton = TextButton(
child: Text(
"Sim",
style: TextStyle(color: Colors.red),
),
onPressed: () {
Navigator.of(context).pop(); // dismiss dialog
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text("Producto Removido!"),
));
},
);
// set up the AlertDialog
AlertDialog alert = AlertDialog(
title: Center(child: Text("Alerta!")),
content: Text("Gostaria de Remover o producto do carrinho?"),
actions: [
cancelButton,
continueButton,
],
);
// show the dialog
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
#override
Widget build(BuildContext context) {
return Container(
child: Card(
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
),
child: ListTile(
onTap: () {},
leading: Container(
width: 80,
//color: Colors.amber,
child: Image.asset(picture),
),
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(name,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black,
fontSize: 14)),
Text("$price MT",
style: TextStyle(
fontWeight: FontWeight.bold,
color: sGreenColour,
fontSize: 14)),
],
),
subtitle: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('Unit: $price MT/$unit',
style: TextStyle(color: Colors.black45)),
Text('Qtd: 2/$unit', style: TextStyle(color: Colors.black45)),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
height: 25,
width: 110,
child: ElevatedButton(
onPressed: () {
showAlertDialog(context, 1);
},
child: Text(
"REMOVER",
style: TextStyle(fontSize: 10, color: Colors.white),
),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(Colors.red)),
),
),
Container(
height: 25,
width: 110,
child: ElevatedButton(
onPressed: () {},
child: Text("ACTUALIZAR",
style:
TextStyle(fontSize: 10, color: Colors.white))),
),
],
)
],
),
selected: false,
),
),
);
}
}
Please Help
I build a drawer as in the image using Flutter, but the elements of the drawer are showed in the left side and its not beautiful like this. I would like to show them in the center of the drawer or at least a little more to the right. Below you can find my code as a reference. It would be great if someone here can give a little help.
img
return Scaffold(
endDrawer: Drawer(backgroundColor: const Color(0xFF262533),
elevation: 10,
child: ListView(
children: [
PopupMenuButton(
tooltip: '',
child: Text(
'Escorts',
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontFamily: 'Poppins',
),
),
itemBuilder: (BuildContext context) =>
<PopupMenuEntry>[]),
Padding(padding: EdgeInsets.all(10.0)),
PopupMenuButton(
tooltip: '',
color: Color(0xFF262533),
position: PopupMenuPosition.under,
child: Text(
'Agenturen & Clubs',
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontFamily: 'Poppins',
),
),
itemBuilder: (BuildContext context) =>
<PopupMenuEntry>[
const PopupMenuItem(
child: ListTile(
title: Text(
'Escortagenturen',
style:
TextStyle(color: Colors.white),
),
),
),
const PopupMenuItem(
child: ListTile(
title: Text(
'Bordelle',
style:
TextStyle(color: Colors.white),
),
),
),
const PopupMenuItem(
child: ListTile(
title: Text(
'Laufhauser',
style:
TextStyle(color: Colors.white),
),
),
),
const PopupMenuItem(
child: ListTile(
title: Text(
'Saunaclubs',
style:
TextStyle(color: Colors.white),
),
),
),
const PopupMenuItem(
child: ListTile(
title: Text(
'Domina & BDSM-Studios',
style:
TextStyle(color: Colors.white),
),
),
),
const PopupMenuItem(
child: ListTile(
title: Text(
'Tantra & Massaage-Studios',
style:
TextStyle(color: Colors.white),
),
),
),
]),
PopupMenuButton(
tooltip: '',
child: Text(
'Inserieren',
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontFamily: 'Poppins',
),
),
itemBuilder: (BuildContext context) =>
<PopupMenuEntry>[]),
Padding(padding: EdgeInsets.all(10.0)),
PopupMenuButton(
tooltip: '',
color: Color(0xFF262533),
position: PopupMenuPosition.under,
child: Text(
'Werben',
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontFamily: 'Poppins',
),
),
itemBuilder: (BuildContext context) =>
<PopupMenuEntry>[
const PopupMenuItem(
child: ListTile(
title: Text(
'Werbenformate',
style:
TextStyle(color: Colors.white),
),
),
),
const PopupMenuItem(
child: ListTile(
title: Text(
'Preise',
style:
TextStyle(color: Colors.white),
),
),
),
]),
Padding(padding: EdgeInsets.all(10.0)),
PopupMenuButton(
tooltip: '',
color: Color(0xFF262533),
position: PopupMenuPosition.under,
child: Text(
'Blog',
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontFamily: 'Poppins',
),
),
itemBuilder: (BuildContext context) =>
<PopupMenuEntry>[
const PopupMenuItem(
child: ListTile(
title: Text(
'Archiv',
style:
TextStyle(color: Colors.white),
),
),
),
]),
const Padding(
padding: EdgeInsets.all(10.0),
),
PopupMenuButton(
position: PopupMenuPosition.under,
tooltip: '',
child: const Text(
'Kontakt',
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontFamily: 'Poppins',
),
),
itemBuilder: (BuildContext context) =>
<PopupMenuEntry>[]),
],
),
),
replace ListView with Column widget
and inside Column make
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
code:
endDrawer: Drawer(
backgroundColor: const Color(0xFF262533),
elevation: 10,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
//todo
]
))
you can align your element by use Container or Column in my case I build drawer like this
Drawer(
backgroundColor: black,
child: Column(
children: [
SizedBox(
child: Container(
width: double.infinity,
decoration: BoxDecoration(
color: black,
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: accent,
width: 0.5,
),
),
height: MediaQuery.of(context).size.width / 2,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
"assets/logs.png",
height: 80,
width: 80,
),
const Text(
"Name App",
style: TextStyle(
color: grey,
fontSize: 25,
fontWeight: FontWeight.bold,
),
),
const Text(
"some body text",
style: TextStyle(
color: white,
fontSize: 14,
),
),
],
)),
),
const SizedBox(
height: 10,
),
Expanded(
child: ListView(
children: [
const Padding(
padding: EdgeInsets.only(right: 10),
child: Text(
"body text",
style: TextStyle(
color: white,
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
Padding(
padding: const EdgeInsets.only(right: 15),
child: Row(
children: const [
Icon(
Icons.check_circle_outline_outlined,
size: 20,
color: accent,
),
SizedBox(
width: 10,
),
Text(
"some body text",
style: TextStyle(
color: grey,
fontSize: 14,
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(right: 15, top: 4),
child: Row(
children: const [
Icon(
Icons.check_circle_outline_outlined,
color: accent,
size: 20,
),
SizedBox(
width: 10,
),
Text(
"some body text",
style: TextStyle(
color: grey,
fontSize: 14,
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(right: 15, top: 4),
child: Row(
children: const [
Icon(
Icons.check_circle_outline_outlined,
size: 20,
color: accent,
),
SizedBox(
width: 10,
),
Text(
"some body text",
style: TextStyle(
color: grey,
fontSize: 14,
),
),
],
),
),
const Divider(
endIndent: 10,
indent: 10,
color: grey,
),
ListTile(
dense: true,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const AboutPage()));
},
leading: const Icon(
Icons.info_outlined,
color: accent,
),
title: const Text(
"About App",
style: TextStyle(
color: white,
fontSize: 14,
),
),
trailing: const Icon(
Icons.arrow_back_ios_new,
color: grey,
size: 15,
),
),
ListTile(
dense: true,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const AboutMe()));
},
leading: const Icon(
Icons.engineering,
color: accent,
),
title: const Text(
"About",
style: TextStyle(
color: white,
fontSize: 14,
),
),
trailing: const Icon(
Icons.arrow_back_ios_new,
color: grey,
size: 15,
),
),
],
),
),
Container(
padding: const EdgeInsets.only(left: 8, right: 8),
child: const Text(
"Folow me Now !",
style: TextStyle(fontSize: 12, color: grey),
textAlign: TextAlign.center,
)),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: black,
),
margin: const EdgeInsets.all(10),
child: Row(
children: [
const Spacer(),
IconButton(
onPressed: () {
},
icon: const Icon(
FontAwesomeIcons.facebook,
color: accent,
),
),
IconButton(
onPressed: () {
},
icon: const Icon(
FontAwesomeIcons.instagram,
color: accent,
),
),
IconButton(
onPressed: () {},
icon: const Icon(
FontAwesomeIcons.whatsapp,
color: accent,
),
),
IconButton(
onPressed: () {},
icon: const Icon(
FontAwesomeIcons.telegram,
color: accent,
),
),
const Spacer(),
],
),
),
],
),
),
The code below (I shortened the code for simplicity) displays the characteristics of the device. I placed all the characteristics in the body and displayed them in a certain way. Tell me how I can make two buttons (marked in red in the photo) under the body. Or put them in the body? tell me the best way to do it.
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
),
body: Align(
alignment: Alignment.topCenter,
child: Container(
constraints: const BoxConstraints(maxWidth: 800, maxHeight: 400),
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(5.0),),
child: SingleChildScrollView(
child: Card(
child: Column(
children: [
ListTile(
title: const Text('Brand:', style: TextStyle(fontWeight: FontWeight.w400, fontSize: 25)),
trailing: Text('${device.brand} ', style: const TextStyle(fontWeight: FontWeight.w400, fontSize: 20 ))),
const Divider(color: Colors.black, endIndent: 10, indent: 10),
ListTile(
title: const Text('Operation system:', style: TextStyle(fontWeight: FontWeight.w400, fontSize: 25)),
trailing: Text('${device.operation_system} ', style: const TextStyle(fontWeight: FontWeight.w400, fontSize: 20 ))),
],
),
),
)
),
));
You can use bottomNavigationBar on Scaffold
Scaffold(
bottomNavigationBar: Padding(
padding: const EdgeInsets.all(8.0), //the one you prefer
child: Row(
children: [
Expanded(
child: OutlinedButton(
onPressed: () {},
child: Text("NNNNNN"),
),
),
SizedBox(
//space between button
width: 16,
),
Expanded(
child: OutlinedButton(
onPressed: () {},
child: Text("NNNNNN"),
),
),
],
),
),
Also, you can wrap Container with Column widget
body: Column(
children: [
Container(...)//your widget
Padding(
padding: const EdgeInsets.all(8.0), //the one you prefer
child: Row(
children: [
Expanded(child: OutlinedButton(...)),
SizedBox(width:x),
Expanded(child: OutlinedButton(...)),
Full snippet on second approach
return Scaffold(
body: Column(
children: [
Container(
constraints: const BoxConstraints(maxWidth: 800, maxHeight: 400),
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(5.0),
),
child: SingleChildScrollView(
child: Card(
child: Column(
children: [
ListTile(
title: const Text('Brand:',
style: TextStyle(
fontWeight: FontWeight.w400, fontSize: 25)),
trailing: Text('${device.brand} ',
style: const TextStyle(
fontWeight: FontWeight.w400, fontSize: 20))),
const Divider(
color: Colors.black, endIndent: 10, indent: 10),
ListTile(
title: const Text('Operation system:',
style: TextStyle(
fontWeight: FontWeight.w400, fontSize: 25)),
trailing: Text('${device.operation_system} ',
style: const TextStyle(
fontWeight: FontWeight.w400, fontSize: 20))),
],
),
),
)),
// Spacer(), /// you you want at the bottom
Padding(
padding: const EdgeInsets.all(8.0), //the one you prefer
child: Row(
children: [
Expanded(
child: OutlinedButton(
onPressed: () {},
child: Text("NNNNNN"),
),
),
SizedBox(
//space between button
width: 16,
),
Expanded(
child: OutlinedButton(
onPressed: () {},
child: Text("NNNNNN"),
),
),
],
),
)
],
),
);
You can check more about widgets, Column and layout.
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,
)
],
),
),
),
),
],
),
),
],
),
),
);
}
}
I have added two card widgets in a row enclosed in a columnCode:
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: MyApp(),
));
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
children: [
Padding(
padding: EdgeInsets.fromLTRB(0.0, 10, 0.0, 0.0),
child: Row(
children: [
Expanded(
child: SizedBox(
height: 70,
child: Card(
color: Colors.orange[500],
child: ListTile(
leading: CircleAvatar(
backgroundImage:
AssetImage('assets/card_photo.png'),
),
title: Text(
'Teacher of the month',
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
fontFamily: 'Poppins-Bold'),
),
subtitle: Text(
'MAY 2020',
style: TextStyle(
fontSize: 8,
fontWeight: FontWeight.bold,
color: Colors.white,
fontFamily: 'Poppins-Bold'),
),
onTap: () {},
),
),
),
),
Expanded(
child: SizedBox(
height: 70,
child: Card(
color: Colors.orange[500],
child: ListTile(
leading: CircleAvatar(
backgroundImage:
AssetImage('assets/card_photo.png'),
),
title: Text(
'Teacher of the month',
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
fontFamily: 'Poppins-Bold'),
),
subtitle: Text(
'CLASS NAME',
style: TextStyle(
fontSize: 8,
fontWeight: FontWeight.bold,
color: Colors.white,
fontFamily: 'Poppins-Bold'),
),
onTap: () {},
),
),
),
),
],
),
),
],
),
),
);
}
}
This is the output:Output Image
However I want this row to be scrollabe widgets of cards. But even after using expanded, I am getting 'RenderBox was not laid out' error.
Here is the code for it:
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: MyApp(),
));
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
children: [
Padding(
padding: EdgeInsets.fromLTRB(0.0, 10, 0.0, 0.0),
child: SingleChildScrollView(//added scrollview widget
scrollDirection: Axis.horizontal,
child: Row(
children: [
Expanded(
child: SizedBox(
height: 70,
child: Card(
color: Colors.orange[500],
child: ListTile(
leading: CircleAvatar(
backgroundImage:
AssetImage('assets/card_photo.png'),
),
title: Text(
'Teacher of the month',
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
fontFamily: 'Poppins-Bold'),
),
subtitle: Text(
'MAY 2020',
style: TextStyle(
fontSize: 8,
fontWeight: FontWeight.bold,
color: Colors.white,
fontFamily: 'Poppins-Bold'),
),
onTap: () {},
),
),
),
),
Expanded(
child: SizedBox(
height: 70,
child: Card(
color: Colors.orange[500],
child: ListTile(
leading: CircleAvatar(
backgroundImage:
AssetImage('assets/card_photo.png'),
),
title: Text(
'Teacher of the month',
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
fontFamily: 'Poppins-Bold'),
),
subtitle: Text(
'CLASS NAME',
style: TextStyle(
fontSize: 8,
fontWeight: FontWeight.bold,
color: Colors.white,
fontFamily: 'Poppins-Bold'),
),
onTap: () {},
),
),
),
),
],
),
),
),
],
),
),
);
}
}
Edit: I also want text below the icon. If someone could help me with that also. Sample image name icon
Check if this works
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class something extends StatelessWidget {
#override
Widget build(BuildContext context) {
var appBar = AppBar();
return Container(
height: MediaQuery.of(context).size.height / 3,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 6,
itemExtent: MediaQuery.of(context).size.height / 3,
itemBuilder: (context, index) {
return _cards(context, appBar);
},
),
);
}
}
Widget _cards(BuildContext context, AppBar appBar) {
return Align(
child: Container(
height: 100,
child: Card(
semanticContainer: true,
clipBehavior: Clip.antiAliasWithSaveLayer,
elevation: 5,
margin: EdgeInsets.all(10),
color: Colors.orange[500],
child: ListTile(
leading: Column(
children: [
CircleAvatar(
backgroundImage: NetworkImage(
'https://flutter.github.io/assets-for-api-docs/assets/widgets/owl.jpg'),
),
Text("Name"),
],
),
title: Text('Teacher of the month', style: _textStyle(10)),
subtitle: Text('MAY 2020', style: _textStyle(8)),
onTap: () {},
),
),
),
);
}
_textStyle(double size) {
return TextStyle(
fontSize: size,
fontWeight: FontWeight.bold,
color: Colors.white,
fontFamily: 'Poppins-Bold');
}
It gives me output like this
You should use listView widget.
ListView(
children: <Widget>[
ItemOne(),
ItemTwo(),
ItemThree(),
],
),
and to change the scroll physics use:
scrollDirection: Axis.horizontal,