Flutter: Positioned inside stack cuts off my widget - flutter

I am using stuck to overlapping my widget. this is my widget:
#override
Widget build(BuildContext context) {
return SingleChildScrollView(
controller: controller,
child: SizedBox(
height: double.maxFinite,
child: Column(
children: [
Container(
width: double.maxFinite,
constraints: BoxConstraints(maxHeight: 200),
color: Colors.blue,
child: Stack(
// clipBehavior: Clip.none,
children: [
Positioned(
bottom: -25,
left: 0,
right: 0,
child: Container(
width: 60,
height: 60,
padding: EdgeInsets.all(8),
color: Colors.blue,
child: CircleAvatar(
backgroundColor: Colors.white,
child: Icon(Icons.mail)),
),
),
],
),
)
],
),
),
);
}
this is an image :
as you can see my image was cut off.I added clipBehavior: Clip.none, to stack but it just increase the height of stack :
I want the button to come down from the blue container. Like all the pictures I took, without cut off.

#override
Widget build(BuildContext context) {
return SingleChildScrollView(
controller: controller,
child: SizedBox(
height: double.maxFinite,
child: Column(
children: [
Container(
width: double.maxFinite,
constraints: BoxConstraints(maxHeight: 200),
color: Colors.blue,
child: Stack(
// clipBehavior: Clip.none,
children: [
Container(
width: MediaQuery of(context).size.width,
height : 300,
margin : EdgeInsets.only(bottom: 50),
color: Colors.blue,
),
Positioned(
bottom : 0,
left:0, right:0,
child: Container (height : 300, width: MediaQuery.of(context).width,
child: CircleAvatar())
)
],
),
)
],
),
),
);
}

I fix this issue :
#override
Widget build(BuildContext context) {
return SingleChildScrollView(
controller: controller,
child: SizedBox(
height: double.maxFinite,
child: Column(
children: [
Container(
width: double.maxFinite,
height: 200,
color: Colors.blue,
child: Stack(
clipBehavior: Clip.none,
children: [
Align(
alignment: Alignment.center,
child: Container(
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("test",
style:
TextStyle(fontSize: 25, color: Colors.white)),
],
),
),
),
Positioned(
bottom: -25,
left: 0,
right: 0,
child: CircleAvatar(
backgroundColor: Colors.white,
child: Icon(Icons.campaign)),
),
],
),
)
],
),
),
);
}
}
result:

Related

Flutter Images Layout

I have several images that I need to display on the screen, the first image is center screen and then 3 at the bottom, the layout of the 3 at the bottom is a single image, and 2 below that.
Using Stack and Align Widgets I have gotten the main image center, but the other images are aligning to the top of the screen and not the bottom even though I am specifying it in the Align Widget.
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Stack(
alignment: Alignment.center,
children: <Widget>[
const Align(
alignment: Alignment.center,
child: Image(
image: AssetImage("assets/imgs/logo.png"),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.only(bottom: 40),
child: Column(
children: [
SizedBox(
width: MediaQuery.of(context).size.width / 2.5,
child: Image(
image: const AssetImage("assets/imgs/logo1.png"),
width: MediaQuery.of(context).size.width / 2.5,
),
),
Flex(
direction: Axis.horizontal,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
width: MediaQuery.of(context).size.width / 4,
child: const Image(
image: AssetImage("assets/imgs/square_logo.jpg"),
),
),
const Padding(
padding: EdgeInsets.all(10),
),
SizedBox(
width: MediaQuery.of(context).size.width / 4,
child: const Image(
image: AssetImage("assets/imgs/square_logo1.png"),
),
),
],
),
],
),
),
),
],
),
);
}
Checkout this one:
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Stack(
children: <Widget>[
Align(
alignment: Alignment.center,
child: Image(
image: AssetImage("assets/imgs/logo.png"),
),
),
Positioned(
bottom: 0,
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: MediaQuery.of(context).size.width / 4,
child: Image(
image: AssetImage("assets/imgs/square_logo.jpg"),
),
),
SizedBox(
width: MediaQuery.of(context).size.width / 4,
child: Image(
image: AssetImage("assets/imgs/square_logo1.png"),
),
),
],
),
SizedBox(
width: MediaQuery.of(context).size.width / 2.5,
child: Image(
image: AssetImage("assets/imgs/logo1.png"),
),
),
],
),
),
],
),
);
}
Default Column's mainAxisSize: MainAxisSize.max,,, you can use
mainAxisSize: MainAxisSize.min,

Neither Positioned's width or SizedBox's width works inside a stack widget - Flutter

#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Title Text'),
),
body: SafeArea(
child: Stack(children: [
Column(
children: const [
Text('short content'),
],
),
const Positioned(
top: 100,
width: 320,
child: SizedBox(
width: 320,
height: 50,
child: ColoredBox(color: Colors.red),
))
])),
);
I need the red box taking almost the entire screen with, but it flows the text width. How should I make this work?
Wrap your Stack with SizedBox:
SizedBox(
width: double.infinity,
child: Stack(
clipBehavior: Clip.none,
children: [
SizedBox(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: const [
Text('short content'),
],
),
),
Positioned(
top: 100,
right: 0,
left: 0,
child: Container(
height: 50,
color: Colors.red,
))
],
),
),
You can wrap all children of the stack with either Align or Positioned so that the Stack can properly lay them out.
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Title Text'),
),
body: SafeArea(
child: Stack(
children: [
/// The column is now positioned.
Positioned(
top: .0,
left: .0,
child: Column(
children: const [
ColoredBox(color: Colors.amber, child: Text('short content'))
],
),
),
const Positioned(
top: 100.0,
width: 320.0,
height: 50.0,
child: ColoredBox(color: Colors.red),
)
],
),
),
);
}
Output:

How to change the button position and make the design button flutter?

A design like I want:
This is the current design:
Hello. How to change the position of the button and make the button design like the picture I show. I have tried to make it myself but still failed to get the design as in the picture I showed. I am new to flutter. Please guide me and hope someone is willing to help me.
This is my current code:
Container(
padding: const EdgeInsets.symmetric(horizontal: 150),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(height: 35),
Container(
margin: EdgeInsets.fromLTRB(10, 0, 10, 10),
padding: EdgeInsets.all(15),
decoration: BoxDecoration(
border: Border.all(
color: Colors.transparent,
width: 1.0,
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
flex: 1,
child: Center(
child: FutureBuilder(
future:
_getSignedURL(widget.patientProfile.avatar),
builder: (BuildContext context,
AsyncSnapshot snapshot) {
if (snapshot.data == null) {
return Container(
color: Colors.white,
child: Container(
width: 200,
height: 200,
decoration: BoxDecoration(
color:
Color.fromRGBO(255, 255, 255, 0.3),
border: Border.all(
color: Colors.black12,
width: 1.0,
),
borderRadius: BorderRadius.all(
Radius.circular(200.0)),
),
),
);
} else {
return CircleAvatar(
radius: 100,
backgroundImage:
NetworkImage(snapshot.data),
);
}
},
),
),
),
],
),
),
Container(
margin: EdgeInsets.fromLTRB(10, 0, 10, 10),
padding: EdgeInsets.all(15),
decoration: BoxDecoration(
border: Border.all(
color: Colors.transparent,
width: 1.0,
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
child: Padding(
padding: EdgeInsets.only(top: 10),
child: Align(
alignment: Alignment.centerRight,
child: ButtonTheme(
minWidth: 100.0,
height: 38.0,
buttonColor: mainColor,
// ignore: deprecated_member_use
child: RaisedButton(
padding: EdgeInsets.fromLTRB(30, 0, 30, 0),
textColor: Colors.white,
color: mainColor,
child: Text('Save'),
onPressed: () => _updatePatientProfile(),
),
),
)),
),
],
),
),
],
),
),
Play with Stack widget, there are others way of doing this.
class B extends StatefulWidget {
B({Key? key}) : super(key: key);
#override
State<B> createState() => _BState();
}
class _BState extends State<B> {
Color mainColor = Colors.blue;
#override
Widget build(BuildContext context) {
return Scaffold(
body: LayoutBuilder(
builder: (context, constraints) => Column(
children: [
Column(
children: [
Container(
color: Colors.cyanAccent,
height: 200 + 70 + 60, // based on circle+ text space
child: Stack(
clipBehavior: Clip.none,
children: <Widget>[
// divider
Align(
alignment: Alignment(0, -.35),
child: Container(
width: constraints.maxWidth,
height: 8,
color: mainColor,
)),
Positioned(
top: 40,
left: 100,
child: Column(
children: [
CircleAvatar(
radius: 100,
),
SizedBox(
height: 70,
),
Text(
"Dumasd Text A",
textAlign: TextAlign.center,
),
],
),
),
Align(
alignment: Alignment(.7, .25),
child: saveProfile(),
)
],
),
),
],
),
],
),
),
);
}
ButtonTheme saveProfile() {
return ButtonTheme(
minWidth: 100.0,
height: 38.0,
buttonColor: mainColor,
// ignore: deprecated_member_use
child: RaisedButton(
padding: EdgeInsets.fromLTRB(30, 0, 30, 0),
textColor: Colors.white,
color: mainColor,
child: Text('Save'),
onPressed: () {}),
);
}
}
Play with Positioned and Alignment

Flutter show icon overlap with column

I need to show the avatar and a column in a row which look like overlapping each other.
Something like this
I have done with the left side but don't know how can I add this type of icon which seems like overlapping with my column here is my code
Widget build(BuildContext context) {
double statusBarHeight = MediaQuery.of(context).padding.top;
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return Scaffold(
body: Container(
width: double.infinity,
color: Color(0xff1b4881),
child: Column(
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
height: height * 0.05,
),
Container(
padding: EdgeInsets.only(left: 10),
alignment: Alignment.topLeft,
child: new SizedBox(
child: FloatingActionButton(
backgroundColor: Colors.white,
child: Icon(Icons.arrow_back_ios, color: Color(0xff1b4881),),
onPressed: () {
Navigator.pop(context);
},
))),
SizedBox(
height: height * 0.03,
),
Container(
padding: EdgeInsets.only(right: 20),
color: Colors.white,
width: width * 0.7,
height: height * 0.1,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Rtn.XYZZ',
style: TextStyle(fontSize: 22),
),
Text(
'President',
style: TextStyle(fontSize: 22),
)
],
),
),
],
),
],
)),
);
}
Try this
Container(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 20),
child: Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Container(
height: 60,
width: MediaQuery.of(context).size.width,
margin: const EdgeInsets.only(top: 20, bottom: 20, right: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('AskNilesh'),
Text('AskNilesh'),
],
),
decoration: BoxDecoration(
color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(20.0))),
),
Positioned(
right: 0,
top: 0,
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(50.0)),
child: Container(
height: 100,
width: 100,
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.all(Radius.circular(50.0))),
),
),
)
],
),
)
OUTPUT
you can the Stack Widget to overlap widgets:
Stack(
children: <Widget>[
Column(
children: <Widget>[
Text('Rtn.xxx'),
Text('secretory'),
],
),
Positioned(
left: 10,
right: 10,
top: 10,
bottom: 10,
child: CircleAvatar(
child: Image.asset('blablabla.png'),
),
)
],
)
then play with values of top, left, right, button in the Positioned widget to align the item exactly as you want it.

Getting Vertical viewport was given unbounded height using ListView inside Column

I want to add a list of Container inside a Column widget.
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
fixedContainer(context),
),
Widget fixedContainer(BuildContext context) {
return ListView(
children: <Widget>[
FutureBuilder<List<AddCash>>(
future: future,
builder: (context, snapshot) {
if (snapshot.hasData) {
return Column(
children:
snapshot.data.map((todo) => nameColumn(todo)).toList());
} else {
return SizedBox();
}
},
),
],
);
}
Widget nameColumn(AddCash addCash) {
return Container(
alignment: Alignment.center,
width: 120.0,
height: 60.0,
color: Colors.white,
margin: EdgeInsets.all(4.0),
child: Text(
'name: ${addCash.name}',
),
);
}
It's getting an error saying Vertical viewport was given unbounded height. Do I need to set the height? I didn't set the height because I need to add the Container dynamically.
Entire Code
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import '../data/repository_service_addcash.dart';
import '../models/addcash.dart';
class CalendarPage extends StatefulWidget {
#override
_CalendarPageState createState() => _CalendarPageState();
}
class _CalendarPageState extends State<CalendarPage> {
Future<List<AddCash>> future;
int id;
#override
initState() {
super.initState();
future = RepositoryServiceAddCash.getAllAddCash();
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
//THE FIRST COLUMN NEEDS TO BY DYNAMICALLY PRODUCDED
// nameColumnContainer(context),
Container(
alignment: Alignment.center,
width: 120.0,
height: 60.0,
color: Colors.white,
margin: EdgeInsets.all(4.0),
child: Text(
"ONE",
),
),
Container(
alignment: Alignment.center,
width: 120.0,
height: 60.0,
color: Colors.white,
margin: EdgeInsets.all(4.0),
child: Text(
"TWO",
),
),
Container(
alignment: Alignment.center,
width: 120.0,
height: 60.0,
color: Colors.white,
margin: EdgeInsets.all(4.0),
child: Text(
"THREE",
),
),
],
),
Flexible(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
child: Row(
// children: getDaysInWeek(),
children: <Widget>[
Container(
alignment: Alignment.center,
width: 120.0,
height: 60.0,
color: Colors.white,
margin: EdgeInsets.all(4.0),
child: Text(
"A",
),
),
Container(
alignment: Alignment.center,
width: 120.0,
height: 60.0,
color: Colors.white,
margin: EdgeInsets.all(4.0),
child: Text(
"B",
),
),
Container(
alignment: Alignment.center,
width: 120.0,
height: 60.0,
color: Colors.white,
margin: EdgeInsets.all(4.0),
child: Text(
"C",
),
),
Container(
alignment: Alignment.center,
width: 120.0,
height: 60.0,
color: Colors.white,
margin: EdgeInsets.all(4.0),
child: Text(
"D",
),
),
],
),
),
Container(
child: Row(
children: <Widget>[
Container(
alignment: Alignment.center,
width: 120.0,
height: 60.0,
color: Colors.white,
margin: EdgeInsets.all(4.0),
child: Text(
"H",
),
),
Container(
alignment: Alignment.center,
width: 120.0,
height: 60.0,
color: Colors.white,
margin: EdgeInsets.all(4.0),
child: Text(
"F",
),
),
Container(
alignment: Alignment.center,
width: 120.0,
height: 60.0,
color: Colors.white,
margin: EdgeInsets.all(4.0),
child: Text(
"3000",
),
),
Container(
alignment: Alignment.center,
width: 120.0,
height: 60.0,
color: Colors.white,
margin: EdgeInsets.all(4.0),
child: Text(
"4000",
),
),
],
),
),
Container(
alignment: Alignment.center,
width: 120.0,
height: 60.0,
color: Colors.white,
margin: EdgeInsets.all(4.0),
child: Text(
"two",
),
),
],
),
),
)
],
),
),
);
}
Widget nameColumnContainer(BuildContext context) {
return ListView(
shrinkWrap: true,
children: <Widget>[
FutureBuilder<List<AddCash>>(
future: future,
builder: (context, snapshot) {
if (snapshot.hasData) {
return Column(
children:
snapshot.data.map((todo) => nameColumn(todo)).toList());
} else {
return SizedBox();
}
},
),
],
);
}
Widget nameColumn(AddCash addCash) {
return Container(
alignment: Alignment.center,
width: 120.0,
height: 60.0,
color: Colors.white,
margin: EdgeInsets.all(4.0),
child: Text(
'name: ${addCash.name}',
),
);
}
}
You could set shrinkWrap: true to the ListView.
shrinkWrap property
If the scroll view does not shrink wrap, then the scroll view will
expand to the maximum allowed size in the scrollDirection. If the
scroll view has unbounded constraints in the scrollDirection, then
shrinkWrap must be true.