How to make icon button overlapping container widgets in Flutter? - flutter

I'm really new to Flutter. In the homepage, I intend to build the page something like this:
The other widgets are working pretty fine, but when I come to developing the double button like the design that overlapping the container widgets below, it's not working at all.
My first approach is using Stack which contain Positioned widgets (for the double button) and Container (for the other things). But, the Positioned widgets despite having a dummy child widget is not visible at all, whereas the Container is perfectly working. I don't know whether the Positioned is written in a wrong way, or else.
Here's the source code:
https://github.com/andre-nk23/packme/blob/master/lib/main.dart
Can anyone help me here? To make those two button overlapping the container? Thank you.
Note : I'm using several imported packages, please notify me if those packages affects the process of developing the overlap double button.

void main() => runApp(MaterialApp(
home: BottomNavBar(),
));
class BottomNavBar extends StatefulWidget {
#override
_BottomNavBarState createState() => _BottomNavBarState();
}
class _BottomNavBarState extends State<BottomNavBar> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
// ignore: unused_field
int _page = 0;
String tabAccent = '#B9EEDC';
String pinkAccent = '#FF8787';
String greenAccent = '#43D1A5';
String blueAccent = '#030835';
String buttonAccent = '#CDF0E0';
GlobalKey _bottomNavigationKey = GlobalKey();
#override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
drawer: new Drawer(
child: ListView(
children: [
Container(
height: 210,
child: DrawerHeader(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
CircleAvatar(
backgroundImage: AssetImage('assets/img.jpeg'),
maxRadius: 30,
),
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'Julian Casablancas',
textScaleFactor: 1.6,
),
Padding(
padding: EdgeInsets.fromLTRB(0, 5, 0, 0),
child: Text(
'julian.c#gmail.com',
textScaleFactor: 1.1,
),
)
],
)
]),
decoration: BoxDecoration(color: HexColor('#CDF0E0')),
),
),
ListTile(
leading: Icon(FeatherIcons.home, color: HexColor('#030835')),
title: Text('Beranda', textScaleFactor: 1.2),
tileColor: HexColor('#CDF0E0'),
selectedTileColor: HexColor('#A4E7CE'),
),
ListTile(
leading: Icon(Icons.person_outlined,
size: 25, color: HexColor('#030835')),
title: Text('Profil', textScaleFactor: 1.2),
tileColor: HexColor('#CDF0E0'),
selectedTileColor: HexColor('#A4E7CE')),
ListTile(
leading: Icon(FeatherIcons.clock, color: HexColor('#030835')),
title: Text('Riwayat', textScaleFactor: 1.2),
tileColor: HexColor('#CDF0E0'),
selectedTileColor: HexColor('#A4E7CE')),
ListTile(
leading: Icon(FeatherIcons.moon, color: HexColor('#030835')),
title: Text('Mode gelap', textScaleFactor: 1.2),
tileColor: HexColor('#CDF0E0'),
selectedTileColor: HexColor('#A4E7CE')),
ListTile(
leading: Icon(Icons.attach_money, color: HexColor('#030835')),
title: Text('Gabung kami', textScaleFactor: 1.2),
tileColor: HexColor('#CDF0E0'),
selectedTileColor: HexColor('#A4E7CE')),
ListTile(
leading: Icon(Icons.info_outline_rounded,
color: HexColor('#030835')),
title: Text('Informasi', textScaleFactor: 1.2),
tileColor: HexColor('#CDF0E0'),
selectedTileColor: HexColor('#A4E7CE')),
ListTile(
leading:
Icon(Icons.settings_outlined, color: HexColor('#030835')),
title: Text('Pengaturan', textScaleFactor: 1.2),
tileColor: HexColor('#CDF0E0'),
selectedTileColor: HexColor('#A4E7CE')),
ListTile(
leading: Icon(Icons.logout, color: HexColor('#030835')),
title: Text('Keluar', textScaleFactor: 1.2),
tileColor: HexColor('#CDF0E0'),
selectedTileColor: HexColor('#A4E7CE')),
],
),
),
appBar: PreferredSize(
preferredSize: Size.fromHeight(80.0),
child: AppBar(
centerTitle: true,
backgroundColor: Colors.transparent,
shadowColor: Colors.transparent,
leading: Padding(
padding: EdgeInsets.fromLTRB(20, 20, 0, 0),
child: new IconButton(
icon: new Icon(Icons.donut_large_rounded,
size: 25, color: HexColor('#030835')),
onPressed: () => _scaffoldKey.currentState.openDrawer(),
color: HexColor('#B9EEDC')),
),
actions: [
Padding(
padding: const EdgeInsets.fromLTRB(0, 20, 30, 0),
child: Image(
image: AssetImage('assets/img.jpeg'),
height: 40,
),
),
],
),
),
bottomNavigationBar: CurvedNavigationBar(
key: _bottomNavigationKey,
index: 0,
height: 60.0,
items: <Widget>[
Icon(Icons.qr_code_rounded, size: 30),
Icon(Icons.attach_money_rounded, size: 30),
Icon(FeatherIcons.box, size: 30),
],
color: HexColor('#B9EEDC'),
buttonBackgroundColor: HexColor('#B9EEDC'),
backgroundColor: HexColor('#ECFBF4'),
animationCurve: Curves.easeInOut,
animationDuration: Duration(milliseconds: 300),
onTap: (index) {
setState(() {
_page = index;
});
},
),
body: SafeArea(
child: Container(
color: Colors.red,
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Stack(overflow: Overflow.visible, children: <Widget>[
Container(
margin: EdgeInsets.only(top: 25.0),
width: 500,
color: HexColor('#ECFBF4'),
child: Padding(
padding: EdgeInsets.fromLTRB(30, 35, 30, 55),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Icon(FeatherIcons.info, size: 25),
Icon(FeatherIcons.clock, size: 25)
],
),
SizedBox(height: 10),
Text(
'Scan QR',
style: GoogleFonts.poppins(
textStyle: Theme.of(context).textTheme.headline1,
fontSize: 28,
fontWeight: FontWeight.w700,
color: HexColor('#030835'),
),
),
SizedBox(height: 2),
Text(
'di restoran / driver',
style: GoogleFonts.poppins(
textStyle: Theme.of(context).textTheme.headline1,
fontSize: 18,
fontWeight: FontWeight.w400,
color: HexColor('#030835'),
),
),
Text(
'untuk mulai meminjam',
style: GoogleFonts.poppins(
textStyle: Theme.of(context).textTheme.headline1,
fontSize: 18,
fontWeight: FontWeight.w400,
color: HexColor('#030835'),
),
),
],
),
),
),
/* Here are the changes */
Positioned(
left: 75,
child: FloatingActionButton(
onPressed: () {},
child: Icon(Icons.check_box),
),
),
Positioned(
right: 75,
child: FloatingActionButton(
onPressed: () {},
child: Icon(Icons.check_box),
),
),
]),
],
),
),
),
);
}
}
Hello Andrea, this is the necessary code which you can implement perfectly. Well, I have removed the redundant widgets which was been used to make the code cleaner.The stack was used by me to implement your question.

Have you tried Stack? You can approach this many ways, I just made this in a rush.have a look
Container(
height: 280,
width: 400,
child: Stack(
children: [
Positioned(
bottom: 0,
child: Container(
height: 250,
width: 400,
decoration: BoxDecoration(
color: Colors.pinkAccent,
borderRadius: BorderRadius.only(
topRight: Radius.circular(30),
topLeft: Radius.circular(30),
)
),
),
),
Positioned(
top: 0,
right: 100,
child: FloatingActionButton(
onPressed: (){},
child: Icon(
Icons.check_box
),
),
),
Positioned(
top: 0,
left: 100,
child: FloatingActionButton(
onPressed: (){},
child: Icon(
Icons.check_box
),
),
),
],
),
)

Use Row For Positioning both of the Buttons in container.
Container(
height: 280,
width: MediaQuery.of(context).size.width,
child: Stack(
children: [
Positioned(
bottom: 0,
child: Container(
height: 250,
width: 400,
decoration: BoxDecoration(
color: Colors.pinkAccent,
),
),
),
Positioned(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
FloatingActionButton(
onPressed: (){},
child: Icon(
Icons.person
),
),
FloatingActionButton(
onPressed: (){},
child: Icon(
Icons.face
),
),
],
),
),
],
),
)

Related

Need help for a showModalTopSheet

I would like to be able to implement a showModalTopSheet on the booking.com site
On the first image (img1), a search has already been performed. The search criteria are included in an input button.
By clicking on this button, I get a more detailed search.(img2)
img1
img2
Have you tried using stack widget as the parent and making a separate widget for the top search and filter section. And make a Boolean state for the filter. So the state will turn true when a search is made.
So try to use stack as the parent and make the list of hotels as the first child and make the search text box as the second child with container having padding and alignment property as Alignment.topCenter and make the stack fit property as StackFit.loose .
Below is the example code for implementing the above suggestion.
Link for the sample working images and video.
https://drive.google.com/drive/folders/1BrEtcQCg8VEN7WQgXUorBc34R04gipAA?usp=sharing
import 'package:flutter/material.dart';
class SampleWidget extends StatefulWidget {
const SampleWidget({Key? key}) : super(key: key);
#override
State<SampleWidget> createState() => _SampleWidgetState();
}
class _SampleWidgetState extends State<SampleWidget>
with TickerProviderStateMixin {
late TabController _tabController;
bool _isFilterEnabled = false;
#override
void initState() {
_tabController = new TabController(length: 3, vsync: this, initialIndex: 0);
super.initState();
}
TabBar getTabBar() {
return TabBar(
indicatorColor: Colors.white,
controller: _tabController,
tabs: [
Container(
padding: EdgeInsets.only(top: 20),
height: 65,
child: Tab(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: const [
Icon(
Icons.import_export,
color: Colors.grey,
),
Text(
"Trier",
style: TextStyle(
color: Colors.grey,
),
),
],
),
),
),
Container(
padding: const EdgeInsets.only(top: 20),
height: 50,
child: Tab(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: const [
Icon(
Icons.tune,
color: Colors.grey,
),
Text(
"Filter",
style: TextStyle(
color: Colors.grey,
),
),
],
),
),
),
Container(
padding: const EdgeInsets.only(top: 20),
height: 50,
child: Tab(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: const [
Icon(
Icons.map,
color: Colors.grey,
),
Text(
"Carte",
style: TextStyle(
color: Colors.grey,
),
),
],
),
),
),
],
);
}
#override
Widget build(BuildContext context) {
return Stack(
children: [
Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
backgroundColor: const Color(0xFF013580),
bottom: PreferredSize(
preferredSize: getTabBar().preferredSize,
child: ColoredBox(
color: Colors.white,
child: getTabBar(),
),
),
),
body: TabBarView(
controller: _tabController,
children: [
ListView.builder(
itemBuilder: (index, context) => const ListTile(
leading: Icon(Icons.abc),
),
itemCount: 20,
),
ListView.builder(
itemBuilder: (index, context) => const ListTile(
leading: Icon(Icons.access_alarm),
),
itemCount: 20,
),
ListView.builder(
itemBuilder: (index, context) => const ListTile(
leading: Icon(Icons.ac_unit),
),
itemCount: 20,
)
],
),
),
Material(
color: Colors.transparent,
child: InkWell(
splashColor: Colors.transparent,
onTap: () {
print("container is pressed");
setState(() {
_isFilterEnabled = !_isFilterEnabled;
});
},
child: Container(
height: 60,
child: Row(
children: const [
Icon(
Icons.chevron_left,
color: Colors.grey,
),
SizedBox(width: 20),
Text(
"Sample Text text",
style: TextStyle(
color: Colors.grey,
fontSize: 18,
decoration: TextDecoration.none,
),
)
],
),
margin: const EdgeInsets.only(
left: 20, right: 20, bottom: 20, top: 5),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(5),
border: Border.all(color: Colors.amber, width: 4),
),
),
),
),
if (_isFilterEnabled)
Material(
elevation: 5,
color: Colors.transparent,
child: Container(
color: Colors.white,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
InkWell(
onTap: () {
setState(() {
_isFilterEnabled = !_isFilterEnabled;
});
},
child: Icon(
Icons.close,
),
),
Text(
"Modifiez Votre recherche",
style: TextStyle(
color: Colors.black,
fontSize: 20,
decoration: TextDecoration.none,
fontWeight: FontWeight.w600),
)
],
),
const SizedBox(height: 10),
Container(
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(5),
border: Border.all(color: Colors.amber, width: 4),
),
child: Column(
children: [
Container(
padding: const EdgeInsets.only(
top: 8,
bottom: 5,
),
child: Row(
children: const [
SizedBox(width: 10),
Icon(Icons.search),
SizedBox(width: 10),
Text("France")
],
),
),
const Divider(color: Colors.black38),
Container(
padding: const EdgeInsets.only(
top: 8,
bottom: 5,
),
child: Row(
children: const [
SizedBox(width: 10),
Icon(Icons.search),
SizedBox(width: 10),
Text("France")
],
),
),
const Divider(color: Colors.black38),
Container(
padding: const EdgeInsets.only(
top: 8,
bottom: 8,
),
child: Row(
children: const [
SizedBox(width: 10),
Icon(Icons.search),
SizedBox(width: 10),
Text("France")
],
),
),
Container(
color: Color(0xFF0171c2),
height: 50,
width: double.infinity,
child: const Center(
child: Text(
" Recharge",
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
)
],
),
),
const SizedBox(height: 10),
],
),
),
)
],
);
}
}

Widget getting pushed behind Status Bar in Custom App Bar

I'm currently trying to make my appBar appear like the picture below but seem to be running into one particular issue every time I try doing so.
I have given the appBar a height of 100 and my idea was to distribute the height in a 40 60 ratio between the two Containers(amber and red). Things look fine when there's only the amber Container but as soon as I try adding the red Container, the amber Container somehow gets pushed up behind the status bar and I have no idea what is causing this.
This is till the point things look great with the amber Container
This is when the above anomaly occurs
This is my code. (the part commented out is the design for the Red Container)
import 'package:flutter/material.dart';
class HomeScreen extends StatefulWidget {
HomeScreenState createState() => HomeScreenState();
}
class HomeScreenState extends State<HomeScreen> {
bool _toggleDropDown = false;
#override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: PreferredSize(
preferredSize: const Size.fromHeight(100),
child: AppBar(
elevation: 0,
// backgroundColor: Theme.of(context).scaffoldBackgroundColor,
backgroundColor: Colors.green,
titleSpacing: 0,
title: Column(
children: [
Container( //Amber Container
width: double.infinity,
height: 40,
color: Colors.amber,
child: Column(
children: [
Container(
padding: const EdgeInsets.only(left: 5),
height: 15,
width: double.infinity,
// color: Colors.red,
child: const Text(
'Delivering To',
style: TextStyle(
color: Colors.grey,
fontWeight: FontWeight.bold,
fontSize: 15),
),
),
Container(
height: 25,
width: double.infinity,
padding: const EdgeInsets.only(left: 5),
// color: Colors.blue,
child: Row(
children: [
const Text(
'Current Location',
style: TextStyle(
color: Colors.grey,
fontWeight: FontWeight.bold),
),
const SizedBox(width: 20),
Container(
height: double.infinity,
width: 20,
// color: Colors.yellow,
child: InkWell(
onTap: () {
setState(() {
_toggleDropDown = !_toggleDropDown;
});
},
child: Icon(
!_toggleDropDown
? Icons.keyboard_arrow_down
: Icons.keyboard_arrow_up,
color: Colors.red,
),
))
],
),
),
],
),
),
// Container( //Red Container
// height: 60,
// width: double.infinity,
// color: Colors.red,
// padding: EdgeInsets.only(top: 8),
// child: Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// InkWell(
// onTap: () {},
// child: Icon(
// Icons.search,
// size: 25,
// )),
// Row(
// children: [
// InkWell(
// onTap: () {},
// child: const Icon(
// Icons.shopping_cart_outlined,
// color: Colors.white,
// size: 25,
// ),
// ),
// InkWell(
// onTap: () {},
// child: const Icon(
// Icons.notifications_none_outlined,
// color: Colors.white,
// size: 25,
// ),
// )
// ],
// )
// ],
// ),
// )
],
)),
),
);
}
}
FYI : I have also tried wrapping the Scaffold with SafeArea and the output that produces looks like this:
The issue is here AppBar is not getting height:100. While using PreferredSize you can just use Column or just using toolbarHeight: 100 on AppBar.
appBar: PreferredSize(
preferredSize: const Size.fromHeight(100),
child: AppBar(
elevation: 0,
// backgroundColor: Theme.of(context).scaffoldBackgroundColor,
backgroundColor: Colors.green,
titleSpacing: 0,
toolbarHeight: 100, //<this
Or just do
return Scaffold(
appBar: AppBar(
elevation: 0,
toolbarHeight: 100, //<this
The trick lies in wrapping your Scaffold() with a SafeArea() widget.
Scaffold represents the whole screen of a device, each and every pixel of your screen.
SafeArea takes into account notches, status bars, bottom navigation bars and bottom navigation buttons.
Here's a quick how-to:
class _MyScreenState extends State<DonationDetails> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(), //your ui components goes here
));
}
}
UPDATE TO YOUR USE CASE
import 'package:flutter/material.dart';
class HomeScreenTest extends StatefulWidget {
HomeScreenTestState createState() => HomeScreenTestState();
}
class HomeScreenTestState extends State<HomeScreenTest> {
bool _toggleDropDown = false;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: PreferredSize(
preferredSize: const Size.fromHeight(100),
child: AppBar(
elevation: 0,
automaticallyImplyLeading: false,
leading: null,
backgroundColor: Colors.green,
titleSpacing: 0,
title: Container(
width: double.infinity,
height: 40,
color: Colors.amber,
child: Column(
children: [
Container(
padding: const EdgeInsets.only(left: 5),
height: 15,
width: double.infinity,
// color: Colors.red,
child: const Text(
'Delivering To',
style: TextStyle(
color: Colors.grey,
fontWeight: FontWeight.bold,
fontSize: 15),
),
),
Container(
height: 25,
width: double.infinity,
padding: const EdgeInsets.only(left: 5),
// color: Colors.blue,
child: Row(
children: [
const Text(
'Current Location',
style: TextStyle(
color: Colors.grey, fontWeight: FontWeight.bold),
),
const SizedBox(width: 20),
Container(
height: double.infinity,
width: 20,
// color: Colors.yellow,
child: InkWell(
onTap: () {
setState(() {
_toggleDropDown = !_toggleDropDown;
});
},
child: Icon(
!_toggleDropDown
? Icons.keyboard_arrow_down
: Icons.keyboard_arrow_up,
color: Colors.red,
),
))
],
),
),
],
),
),
bottom: PreferredSize(
preferredSize: const Size.fromHeight(80),
child: Container(
//Red Container
height: 60,
width: double.infinity,
color: Colors.red,
padding: EdgeInsets.only(top: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
IconButton(
onPressed: () {},
icon: Icon(
Icons.shopping_cart_outlined,
color: Colors.white,
size: 25,
),
),
Row(
children: [
IconButton(
onPressed: () {},
icon: Icon(
Icons.shopping_cart_outlined,
color: Colors.white,
size: 25,
),
),
IconButton(
onPressed: () {},
icon: Icon(
Icons.notifications_none_outlined,
color: Colors.white,
size: 25,
),
),
],
)
],
),
),
),
),
),
);
}
}
You can use bottom in 'AppBar'.
Move the red Container to bottom with PreferredSize widget as parent. like this.
return Scaffold(
appBar: PreferredSize(
preferredSize: const Size.fromHeight(100),
child: AppBar(
elevation: 0,
// backgroundColor: Theme.of(context).scaffoldBackgroundColor,
backgroundColor: Colors.green,
titleSpacing: 0,
title: Container(
//Amber Container
width: double.infinity,
height: 40,
color: Colors.amber,
child: Column(
children: [
Container(
padding: const EdgeInsets.only(left: 5),
height: 15,
width: double.infinity,
// color: Colors.red,
child: const Text(
'Delivering To',
style: TextStyle(
color: Colors.grey,
fontWeight: FontWeight.bold,
fontSize: 15),
),
),
Container(
height: 25,
width: double.infinity,
padding: const EdgeInsets.only(left: 5),
// color: Colors.blue,
child: Row(
children: [
const Text(
'Current Location',
style: TextStyle(
color: Colors.grey, fontWeight: FontWeight.bold),
),
const SizedBox(width: 20),
Container(
height: double.infinity,
width: 20,
// color: Colors.yellow,
child: InkWell(
onTap: () {
setState(() {
_toggleDropDown = !_toggleDropDown;
});
},
child: Icon(
!_toggleDropDown
? Icons.keyboard_arrow_down
: Icons.keyboard_arrow_up,
color: Colors.red,
),
))
],
),
),
],
),
),
bottom: PreferredSize(
preferredSize: const Size.fromHeight(80),
child: Container(
//Red Container
height: 60,
width: double.infinity,
color: Colors.red,
padding: EdgeInsets.only(top: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
InkWell(
onTap: () {},
child: Icon(
Icons.search,
size: 25,
)),
Row(
children: [
InkWell(
onTap: () {},
child: const Icon(
Icons.shopping_cart_outlined,
color: Colors.white,
size: 25,
),
),
InkWell(
onTap: () {},
child: const Icon(
Icons.notifications_none_outlined,
color: Colors.white,
size: 25,
),
)
],
)
],
),
),
),
),
),
);

Autospace with ListView

I'm creating a listView inside a Flexible, but the listView is adding an autospace and I can't get it out. The space is the one in blue below the name Mais saúde e Segurança
enter image description here
Flexible(
flex: 7,
child: ListView(
children: [
ListTile(
leading: Icon(Icons.map),
title: Text("data"),
),
ListTile(
leading: Icon(Icons.map),
title: Text("data"),
),
ListTile(
leading: Icon(Icons.map),
title: Text("data"),
),
ListTile(
leading: Icon(Icons.map),
title: Text("data"),
),
ListTile(
leading: Icon(Icons.map),
title: Text("data"),
),
ListTile(
leading: Icon(Icons.map),
title: Text("data"),
),
ListTile(
leading: Icon(Icons.map),
title: Text("data"),
),
],
),
),
All code
import 'package:flutter/material.dart';
import 'package:guardacorpo/outras_paginas/consulta_ca.dart';
import 'package:guardacorpo/outras_paginas/dds_estac.dart';
import 'package:guardacorpo/outras_paginas/treinamentos.dart';
import 'package:guardacorpo/pag_normas_estac/nr_estacionario.dart';
class Base extends StatelessWidget {
const Base({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Flexible(
flex: 6,
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/menu.jpg'),
fit: BoxFit.cover,
),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(20),
bottomRight: Radius.circular(20),
)),
child: Column(
children: [
Row(),
SizedBox(height: 40),
Image(
height: 100,
width: MediaQuery.of(context).size.width,
image: AssetImage('assets/images/logo.png'),
),
Text(
'Guarda Corpo',
style: TextStyle(
color: Colors.white,
fontFamily: 'Segoe Black',
fontSize: 40,
),
),
Text(
'Um app sobre saúde e segurança do trabalho',
style: TextStyle(
color: Colors.white, fontFamily: 'Segoe Light'),
),
],
),
),
),
// SizedBox(height: 1),
Flexible(
flex: 4,
child: Container(
width: double.infinity,
margin: EdgeInsets.only(top: 5),
padding: EdgeInsets.symmetric(horizontal: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
RichText(
text: TextSpan(
text: 'Mais Buscados'.toUpperCase(),
style: TextStyle(
fontFamily: 'Segoe Bold',
color: Color(0xFF0C5422),
fontSize: 19,
),
)),
Container(
margin: EdgeInsets.only(top: 5, left: 0),
child: SingleChildScrollView(
child: Column(
children: [
Container(
height: 120,
child: ListView(
scrollDirection: Axis.horizontal,
children: [
MaterialButton(
padding: EdgeInsets.only(left: 0, right: 8),
onPressed: () {
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) =>
NormasEstacionariosAll()));
},
child: Container(
width: 320,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(18),
),
image: DecorationImage(
image: ExactAssetImage(
'assets/images/menu.jpg'),
fit: BoxFit.cover,
),
),
child: Container(
alignment:
AlignmentDirectional.bottomStart,
margin:
EdgeInsets.only(left: 12, bottom: 8),
child: Text(
'Normas Regulamentadoras'.toUpperCase(),
style: TextStyle(
color: Colors.white,
fontFamily: 'Segoe Bold',
fontSize: 16,
),
),
),
),
),
MaterialButton(
padding: EdgeInsets.only(left: 0, right: 8),
onPressed: () {
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) =>
ConsultaCa()));
},
child: Container(
width: 320,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(18),
),
image: DecorationImage(
image: ExactAssetImage(
'assets/images/menu.jpg'),
fit: BoxFit.cover,
),
),
child: Container(
alignment:
AlignmentDirectional.bottomStart,
margin:
EdgeInsets.only(left: 12, bottom: 8),
child: Text(
'Consulta de c.a'.toUpperCase(),
style: TextStyle(
color: Colors.white,
fontFamily: 'Segoe Bold',
fontSize: 16,
),
),
),
),
),
MaterialButton(
padding: EdgeInsets.only(left: 0, right: 8),
onPressed: () {
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) =>
Treinamentos()));
},
child: Container(
width: 320,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(18),
),
image: DecorationImage(
image: ExactAssetImage(
'assets/images/menu.jpg'),
fit: BoxFit.cover,
),
),
child: Container(
alignment:
AlignmentDirectional.bottomStart,
margin:
EdgeInsets.only(left: 12, bottom: 8),
child: Text(
'Treinamentos'.toUpperCase(),
style: TextStyle(
color: Colors.white,
fontFamily: 'Segoe Bold',
fontSize: 16,
),
),
),
),
),
MaterialButton(
padding: EdgeInsets.only(left: 0, right: 0),
onPressed: () {
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) =>
DdsEstacionario()));
},
child: Container(
width: 320,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(18),
),
image: DecorationImage(
image: ExactAssetImage(
'assets/images/menu.jpg'),
fit: BoxFit.cover,
),
),
child: Container(
alignment:
AlignmentDirectional.bottomStart,
margin:
EdgeInsets.only(left: 12, bottom: 8),
child: Text(
'temas de d.d.s'.toUpperCase(),
style: TextStyle(
color: Colors.white,
fontFamily: 'Segoe Bold',
fontSize: 16,
),
),
),
),
)
],
),
),
],
),
),
)
],
),
),
),
Flexible(
flex: 1,
child: Container(
width: double.infinity,
padding: EdgeInsets.symmetric(horizontal: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 5),
RichText(
text: TextSpan(
text: 'Mais saúde e segurança'.toUpperCase(),
style: TextStyle(
fontFamily: 'Segoe Bold',
color: Color(0xFF0C5422),
fontSize: 19,
),
)),
],
),
),
),
Flexible(
flex: 7,
child: ListView(
children: [
ListTile(
leading: Icon(Icons.map),
title: Text("data"),
),
ListTile(
leading: Icon(Icons.map),
title: Text("data"),
),
ListTile(
leading: Icon(Icons.map),
title: Text("data"),
),
ListTile(
leading: Icon(Icons.map),
title: Text("data"),
),
ListTile(
leading: Icon(Icons.map),
title: Text("data"),
),
ListTile(
leading: Icon(Icons.map),
title: Text("data"),
),
ListTile(
leading: Icon(Icons.map),
title: Text("data"),
),
],
),
),
Flexible(
flex: 2,
child: Container(
color: Colors.indigo,
),
),
],
),
);
}
}
Wrap your list with MediaQuery.removePadding with removeTop set to true
MediaQuery.removePadding(
context: context,
removeTop: true,
child: ListView.builder(
itemCount: list.length,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: EdgeInsets.only(
left: 8.0,
right: 8,
bottom: index == list!.length - 1 ? 20 : 8),
child: ...,
);
},
),
)

How to increment for a specific in Flutter?

enter image description here Like in my sample image, below, I want to increase or decrease the quantity by clicking the button for a single list item. If I increase the counter in setState (), its increment in each item in the list. I need help with this, especially managing a specific list item in Flutter Flutter.
Container(
height: 500.0,
width: double.infinity,
child: GridView.count(
crossAxisCount: 2,
children:
List.generate(userData == null ? 0 : userData.length, (index) {
return Container(
child: SizedBox(
width: 700,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Image.network(
"${userData[index]["image"]}",
width: 300,
height: 100,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
child: IconButton(
color: Colors.blue,
icon: const Icon(Icons.remove_circle,
size: 35.0),
onPressed: _decrementCount),
),
Container(
child: CircleAvatar(
radius: 20.0,
backgroundColor: Colors.white,
child: Text(
_counter.toString(),
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
),
),
Container(
child: IconButton(
color: Colors.orange,
icon: const Icon(Icons.add_circle,
size: 35.0),
onPressed: () {
_incrementCount(userData[index]);
},
),
),
],
),
Container(
height: 20.0,
child: Text(
"${userData[index]["libelle"]}",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.0,
color: Colors.orange,
),
),
),
],
))),
);
})),
)
Make a separate Stateful class for your List item.
Like this
List.generate(2, (index) => MyCustomWidget(
user[index]
))
class MyCustomWidget extends StatefulWidget {
final user;
const MyCustomWidget({Key? key,required this.user}) : super(key:key);
#override
_MyCustomWidgetState createState() => _MyCustomWidgetState();
}
class _MyCustomWidgetState extends State<MyCustomWidget> {
#override
Widget build(BuildContext context) {
return Container(
child: SizedBox(
width: 700,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Image.network(
"${widget.user["image"]}",
width: 300,
height: 100,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
child: IconButton(
color: Colors.blue,
icon: const Icon(Icons.remove_circle,
size: 35.0),
onPressed: _decrementCount),
),
Container(
child: CircleAvatar(
radius: 20.0,
backgroundColor: Colors.white,
child: Text(
_counter.toString(),
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
),
),
Container(
child: IconButton(
color: Colors.orange,
icon: const Icon(Icons.add_circle,
size: 35.0),
onPressed: () {
_incrementCount(userData[index]);
},
),
),
],
),
Container(
height: 20.0,
child: Text(
"${widget.user["libelle"]}",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.0,
color: Colors.orange,
),
),
),
],
))),
);
}
}
set some
conditions ? Image.network(
"${userData[index]["image"]}",
width: 300,
height: 100,
), : Image.network(
"${userData[index]["image"]}",
width: 400,
height: 250,
),
So if condition true then it's display like first one other wise take second one

Flutter appbar left actions

I am trying to align the Top AppBar Actions to the left but I failed
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
titleSpacing: 0.0,
elevation: 5.0,
backgroundColor: Color(0xff201F23),
title: Icon(
Icons.polymer,
color: Colors.orange,
size: 30.0,
),
actions: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(0, 8, 10, 8),
child: CircleAvatar(
backgroundImage: ExactAssetImage('assets/Bronze.jpg'),
),
decoration: new BoxDecoration(
border: new Border.all(
color: Colors.orange,
width: 1.0,
),
borderRadius: new BorderRadius.all(new Radius.circular(50.0)),
)),
Container(
//margin: EdgeInsets.fromLTRB(0, 0, 130, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
child: Text(
'Ov3rControl',
style: TextStyle(fontSize: 12.0),
),
),
SizedBox(height: 4.0),
Row(
children: <Widget>[
Icon(
Icons.trip_origin,
color: Colors.orange,
size: 12.0,
),
SizedBox(width: 4.0),
Text('1000', style: TextStyle(fontSize: 12.0))
],
),
]),
)
],
),
drawer: Drawer());
}
I want the items to be next to the Logo. how can I achieve that?
I Tried putting left margin to the container but the design break when the name of the user gets bigger
Also, I am new to flutter is there is any way to make this code better?
Is this what you are looking for?
Find the changes in the code below:
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
titleSpacing: 0.0,
elevation: 5.0,
backgroundColor: Color(0xff201F23),
title: Row(
children: <Widget>[
Icon(
Icons.polymer,
color: Colors.orange,
size: 30.0,
),
SizedBox(width: 15,),
Container(
margin: EdgeInsets.fromLTRB(0, 8, 10, 8),
child: CircleAvatar(
backgroundImage: ExactAssetImage('assets/Bronze.jpg'),
),
decoration: new BoxDecoration(
border: new Border.all(
color: Colors.orange,
width: 1.0,
),
borderRadius: new BorderRadius.all(new Radius.circular(50.0)),
)),
Container(
//margin: EdgeInsets.fromLTRB(0, 0, 130, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
child: Text(
'Ov3rControl',
style: TextStyle(fontSize: 12.0),
),
),
SizedBox(height: 4.0),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Icon(
Icons.trip_origin,
color: Colors.orange,
size: 12.0,
),
SizedBox(width: 4.0),
Text('1000', style: TextStyle(fontSize: 12.0))
],
),
]
),
)
],
),
),
drawer: Drawer()
);
}
You can also use the leading property in the AppBar and pass your widget to it
leading: IconButton(
icon: Icon(Icons.shopping_cart),
tooltip: 'Open shopping cart',
onPressed: () {
// handle the press
},
),