How to fix widget overflowing rounded border container flutter - flutter

I have a container with topLeft border as rounded, in its child I have a column with a SingleChildScrollView having the widgets for each full name, mobile etc.
When I'm scrolling up these children come over the container and overflow the rounded border.
I want to fix this.
I want this to go behind the container and not come in front of it.
class SetupAccountScreen extends StatelessWidget {
#override
Widget build(BuildContext context) {
return BaseWidget(
mainTitle: "Setup Account",
description:
"One last step to an awesome shopping experience, we’d like to know you more",
content: SingleChildScrollView(
child: Column(
children: [
SizedBox(
height: 50,
),
FullNameInputWidget(),
MobileNumberInputWidget(),
AddressInputWidget(),
],
),
),
);
}
}
class BaseWidget extends StatelessWidget {
final String mainTitle;
final String description;
final Widget content;
BaseWidget({this.mainTitle, this.description, this.content});
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
title: Text(
"Back",
style: GoogleFonts.playfairDisplay(fontSize: 15),
),
leading: IconButton(
icon: Icon(
Icons.chevron_left,
size: 40,
),
onPressed: () {}),
backgroundColor: Colors.transparent,
),
body: Stack(
children: [
Positioned(
bottom: 0,
child: Container(
height: MediaQuery.of(context).size.height * 0.7,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Colors.white,
borderRadius:
BorderRadius.only(topLeft: Radius.circular(100))),
child: content),
),
Positioned.fill(
child: Align(
alignment: Alignment.topCenter,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 30.0, vertical: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(mainTitle,
style: GoogleFonts.playfairDisplay(
color: Colors.white,
fontWeight: FontWeight.w400,
fontSize: 25)),
Padding(
padding: const EdgeInsets.all(10.0),
child: Text(description,
style: GoogleFonts.playfairDisplay(
color: Colors.white,
fontWeight: FontWeight.w700,
fontSize: 15)),
),
],
),
)))
],
),
);
}
}

Instead of decoration for the container, use ClipRRect to make the round corner, like so.
Positioned(
bottom: 0,
child: ClipRRect(
borderRadius: BorderRadius.only(topLeft: Radius.circular(100)),
child: Container(
height: MediaQuery.of(context).size.height * 0.7,
width: MediaQuery.of(context).size.width,
color: Colors.white,
child: content,
),
),
),

Related

Strange Top Padding on my second AppBar Flutter

Screen of the strange top padding of my app
I have made two classes : the first has a first AppBar and calls the second one that has also a sticky AppBar and display a list of scrollable Items. However, I have a strange top padding in the second AppBar. I have tried a lot of stuff but nothing seems to work.
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
extendBodyBehindAppBar: true,
bottomNavigationBar: BottomNavBar(0, _currentAccount),
appBar: PreferredSize(
preferredSize:
Size.fromHeight(MediaQuery.of(context).size.height / 7),
child: Column(
children: [
Container(
width: MediaQuery.of(context).size.width,
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
colors: <Color>[
Color(0xFF894c56),
Color(0xFFa80d0d)
])),
child: Padding(
padding: const EdgeInsets.only(bottom: 30),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
const Padding(
padding: EdgeInsets.only(top: 50, left: 5),
child: Text(
'Votre évenement ',
style: TextStyle(
fontSize: 15, color: Colors.grey),
)),
Padding(
padding: const EdgeInsets.only(top: 5, left: 5),
child: Text(
event,
style: const TextStyle(
color: Colors.white, fontSize: 17),
),
)
])),
)
],
),
),
body: ListPrestat('Traiteur', _currentAccount)
// ListPrestat('Traiteur', _currentAccount)
));
}
This is the code of my first class that calls the ListPrestat class here under :
#override
Widget build(BuildContext context) {
return SizedBox(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height ,
// -(MediaQuery.of(context).size.height / 6 + 56),
child: CustomScrollView(
slivers: [
SliverAppBar(
toolbarHeight: 50,
expandedHeight: 0,
backgroundColor: const Color(0xFFDCDCDC),
pinned: true,
leading: IconButton(
icon: const Icon(
Icons.arrow_back,
color: Color(0xFFDC3535),
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => MainScreen(_currentAccount)),
);
},
),
centerTitle: true,
shadowColor: Colors.black,
elevation: 10,
bottom: const PreferredSize(
preferredSize: Size.fromHeight(0),
child: TagList(ListCat: 'brouette')),
title: Container(
width: MediaQuery.of(context).size.width,
padding: EdgeInsets.all(MediaQuery.of(context).size.width / 4),
child: Text(
_currentCat,
style: const TextStyle(
color: Colors.black,
fontSize: 16.0,
fontWeight: FontWeight.w700,
),
)),
),
SliverFixedExtentList(
itemExtent: 110.0,
delegate: SliverChildListDelegate(
[
for (int index = 0; index < 5; index++)
CustomListItem2(
thumbnail: ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: AspectRatio(
child: Image.network(
growableList[index],
width: 100.0,
height: 100.0,
fit: BoxFit.fill,
),
aspectRatio: 1 / 1,
)),
title: 'Chez Luigi',
subtitle: 'Les meilleurs pizza hors d\'italie.',
ListCat: 'Food Truck',
),
],
),
)
],
),
);
}
Do you have any idea what can have caused this padding and how to resolve this problem ?
wrap your secound class with scaffold
Scaffold(
body: SizedBox(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height ,),
...................
)

Flutter CustomScrollView „stick“ card on top

I want to create a list in Flutter with a small preview of the content before the user sees all information on a new screen.
Therefor I build a simple list with Sliver-Cards:
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Cards'),
backgroundColor: Colors.blue,
),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 5),
child: CustomScrollView(
shrinkWrap: false,
slivers: <Widget>[
_buildHeader(),
_buildCard('1', Colors.white, Colors.red, Colors.transparent),
_buildCard('2', Colors.white, Colors.blue, Colors.red),
_buildCard('3', Colors.white, Colors.green, Colors.blue),
…
],
),
),
);
}
Widget _buildHeader() => SliverStickyHeader(
header: Container(
height: 50,
color: Colors.white,
padding: const EdgeInsets.symmetric(horizontal: 16),
alignment: Alignment.topLeft,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Center(
child: Text(
"Card-Header",
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.black),
),
),
],
),
),
sliver: SliverToBoxAdapter(
child: Container(
height: 20,
),
),
);
Widget _buildCard(
String logo, Color logoColor, Color cardColor, Color prevColor) =>
SliverStickyHeader(
header: GestureDetector(
child: Stack(
children: <Widget>[
Container(
height: 16,
color: prevColor,
),
Container(
height: 60,
decoration: BoxDecoration(
color: cardColor,
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(16),
topRight: Radius.circular(16))),
padding: const EdgeInsets.symmetric(horizontal: 16),
alignment: Alignment.bottomLeft,
child: Text(
logo,
style:
TextStyle(color: logoColor, fontWeight: FontWeight.bold),
),
),
],
),
),
sliver: SliverToBoxAdapter(
child: Container(
height: 20,
color: cardColor,
),
),
);
Here’s a Screenshot:
The only thing missing is the method to show a small preview of the content, which I want to stick to the top of the list. For example, anything like in this GitHub post: https://github.com/loopeer/CardStackView/blob/master/screenshot/screenshot1.gif
Is it possible to create a method like this in flutter?

Flutter showModalBottomSheet does not allow transparent background container

Am I using some widget here incorrectly or is this an issue with showModalBottomSheet?
As you can see here in the screenshots, the test code I've included displays a button in a 70% transparent container. This looks correct in main body. However, when you tap the Open Bottom Sheet button to display the showModalBottomSheet() function you'll see that that exact same button in a container with 70% transparent bg color is now 100% opaque.
Why is the opacity of the container being ignored in the showModalBottomSheet widget tree?
I've tried using Opacity widget and a Stack, but transparency does not seem to be allowed in a showModalBottomSheet?
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: BottomSheet(),
);
}
}
class BottomSheet extends StatelessWidget {
const BottomSheet({
Key? key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
void _showBottomSheet() {
showModalBottomSheet(
context: context,
builder: (context) {
return Container(
height: MediaQuery.of(context).size.height * 0.75,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.only(top: 27.0, bottom: 27.0),
child: Text(
'Select',
style: TextStyle(
fontSize: 20.0,
color: Colors.blue,
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 24.0, right: 24.0),
child: GridView.count(
crossAxisCount: 3,
mainAxisSpacing: 25.0,
crossAxisSpacing: 25.0,
padding: EdgeInsets.only(
bottom: 100.0,
),
children: [
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
Placeholder(),
],
),
),
),
Container(
width: double.infinity,
height: 161.0,
color: Colors.white.withOpacity(0.3),
child: Padding(
padding: const EdgeInsets.only(
left: 24.0,
right: 24.0,
),
child: Center(
child: OutlinedButton(
child: Text(
'Button in container with 70% transparent bg ignored',
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
),
textAlign: TextAlign.center,
),
onPressed: () {},
style: OutlinedButton.styleFrom(
backgroundColor: Colors.blue,
minimumSize: Size(double.infinity, 52.0),
),
),
),
),
),
],
),
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(32.0),
topRight: const Radius.circular(32.0),
),
),
);
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(32.0),
topRight: const Radius.circular(32.0),
),
),
barrierColor: Color.fromRGBO(0, 0, 0, 0.9),
isScrollControlled: true,
);
}
return Scaffold(
backgroundColor: Colors.indigo,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
child: Text(
'Open bottom sheet',
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
),
),
onPressed: _showBottomSheet,
),
SizedBox(
height: 30.0,
),
Container(
width: double.infinity,
height: 161.0,
color: Colors.white.withOpacity(0.3),
child: Padding(
padding: const EdgeInsets.only(
left: 24.0,
right: 24.0,
),
child: Center(
child: OutlinedButton(
child: Text(
'Button in container with 70% transparent bg',
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
),
textAlign: TextAlign.center,
),
onPressed: () {},
style: OutlinedButton.styleFrom(
backgroundColor: Colors.blue,
minimumSize: Size(double.infinity, 52.0),
),
),
),
),
),
],
),
),
);
}
}
As you can see here, it appears to be a bug in Flutter's showModalBottomSheet().
To overcome this, I built my own bottom sheet in a Stack to get the transparency affect I needed on the bottom sheet button.

how to match height of a row widget which is tallest among other widgets

I've defined a Row of column widgets but unable to match height of other widgets defined in a Row
I have tried with Expand , Intrinsic Height, width, Contrained box, and defining containers inside each column.
Expected Results are to match height with parent/other row widgets[enter image description here][1]
Widget columnOne(String t1, String t2) {
return ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(8)),
child: Container(
color: Colors.white,
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
color: Colors.white,
child: Padding(
padding:
EdgeInsets.fromLTRB(10, 10, 10, 10),
child: Align(
alignment: Alignment.center,
child: Text(t1,
style: TextStyle(
fontSize: 30,
color: Colors.black,
backgroundColor: Colors.white,
fontFamily: 'FJ',fontWeight: FontWeight.bold
)),
)
),
),
IntrinsicHeight(
child: ConstrainedBox(
constraints: const BoxConstraints(minWidth: double.infinity),
child: Container(
color: Colors.red,
child: Padding(
padding: EdgeInsets.all(10),
child: Align(
alignment: Alignment.center,
child: Text(t2 ,
textAlign: TextAlign.center,
textWidthBasis: TextWidthBasis.parent,
style: TextStyle(
fontSize: 16,
color: Colors.black,
backgroundColor: Colors.red,
)),
))),
)
)
],
),
),
);
}
https://i.stack.imgur.com/HfYOl.png
Current result If I change text/overflow the text
https://i.stack.imgur.com/t9MTK.png
Expected
Judging by the design, the bottom of the card can only be one or 2 lines high.
In this case, it’s easier not to rely on the automatic height, but to use fixed values.
import 'package:flutter/material.dart';
import 'package:vector_math/vector_math.dart' as v_math;
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
backgroundColor: Colors.black,
body: SafeArea(
child: RowExample(),
),
),
);
}
}
class RowExample extends StatelessWidget {
final List<List<String>> entities = [
['22', 'fdslfdssdf'],
['22', 'sdfdssf fd fasdf '],
['3242', 'sdsf'],
];
#override
Widget build(BuildContext context) {
return Row(
children: entities.map((item) => columnOne(item[0], item[1])).toList(),
);
}
Widget columnOne(String t1, String t2) {
return ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(8)),
child: Container(
height: 130,
width: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(8)),
color: Colors.white,
),
child: Column(
children: <Widget>[
Container(
height: 70,
color: Colors.white,
child: Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
child: Align(
alignment: Alignment.center,
child: Text(t1,
style: TextStyle(
fontSize: 30,
color: Colors.black,
backgroundColor: Colors.white,
fontFamily: 'FJ',
fontWeight: FontWeight.bold)),
)),
),
Expanded(
child: Container(
color: Colors.red,
child: Padding(
padding: EdgeInsets.all(10),
child: Align(
alignment: Alignment.center,
child: Text(t2,
textAlign: TextAlign.center,
textWidthBasis: TextWidthBasis.parent,
style: TextStyle(
fontSize: 16,
color: Colors.black,
backgroundColor: Colors.red,
)),
))),
)
],
),
),
);
}
}

Why Flutter IconButton Animation Shows Under the Row

In my app, I setup a IconButton to render over a Row with a color background. Unfortunately, the ripple animation on button press renders under the Row (as shown in the screencast). How do i make the ripple show over the Row?
class Card extends StatelessWidget {
final Issue issue;
Color _bgColor;
Card({this.issue}) {
_bgColor = colorSwatch[issue.hashCode % colorSwatch.length];
}
#override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(top: 12, left: 18, right: 18),
padding: EdgeInsets.only(top: 8, bottom: 8),
decoration: new BoxDecoration(
color: _bgColor,
border: new Border.all(color: _bgColor),
borderRadius: BorderRadius.all(
Radius.circular(10.0)
),
),
child: Row(children: [
IconButton(
padding: EdgeInsets.only(right: 16),
icon: Icon(Icons.play_arrow, color: Colors.white, size: 48),
tooltip: 'Start ${issue.issueName}',
onPressed: () {},
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.only(bottom: 8),
child: Text(
issue.title,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
softWrap: true,
),
),
Text(
issue.issueName,
style: TextStyle(
color: Colors.white,
),
),
],
),
),
]));
}
}
The ripple is part of the Material effect. Wrap your IconButton with Material:
Material(
color: _bgColor,
child: IconButton(
padding: EdgeInsets.only(right: 16),
icon: Icon(Icons.play_arrow, color: Colors.white, size: 48),
tooltip: 'Start ${issue.issueName}',
onPressed: () {},
),
),
UPDATE
To be more specific to your goal, you can replace your Container with Material.
return Material(
color: _bgColor,
borderRadius: BorderRadius.all(Radius.circular(10.0)),
child: Container(
margin: EdgeInsets.only(top: 12, left: 18, right: 18),
padding: EdgeInsets.only(top: 8, bottom: 8),
backgroundBlendMode: BlendMode.multiply,
child: Row(
...
),
);
It looks like a bug in the Flutter Framework.
This occurs only with IconButton, no problem with FlatButton.
Possible workaround is to set BlendMode to multiply BlendMode.multiply.
try this:
Container(
decoration: BoxDecoration(
color: Colors.greenAccent[400],
backgroundBlendMode: BlendMode.multiply),
child: ListTile(
leading: IconButton(icon: Icon(Icons.play_arrow), onPressed: () {}),
title: Text("issue title"),
subtitle: Text("description"),
),
),
Update
issue on github
You can wrap your Row inside a InkWell, this will give you the touch ripples.
I have removed the background color of the container, had issues with it showing the ripple, as well as changed the text color to black.
#override
Widget build(BuildContext context) {
return Container(
height: 100,
margin: EdgeInsets.only(top: 12, left: 18, right: 18),
padding: EdgeInsets.only(top: 8, bottom: 8),
decoration: new BoxDecoration(
color: Colors.transparent,
border: new Border.all(color: Colors.orange),
borderRadius: BorderRadius.all(Radius.circular(10.0)),
),
child: InkWell(
// added here
onTap: () {},
child: Row(children: [
IconButton(
padding: EdgeInsets.only(right: 16),
icon: Icon(Icons.play_arrow, color: Colors.black, size: 48),
tooltip: 'Start issue',
onPressed: () {},
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.only(bottom: 8),
child: Text(
'issue.title',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
),
softWrap: true,
),
),
Text(
'issue.issueName',
style: TextStyle(
color: Colors.black,
),
),
],
),
),
]),
));
}
References
Add ripples
Ripple always takes on top of the material widgets. So if there is anything on top of the material widget you will see ripples under your widget.
Just wrap your IconButton with a Material widget with the material set to use the "transparency" type and it should work.
You can use the below generic widget for adding ripples to your widgets.
class AddRipple extends StatelessWidget {
final Widget child;
final Function onTap;
AddRipple({#required this.child, #required this.onTap});
#override
Widget build(BuildContext context) {
return Stack(
children: <Widget>[
child,
Positioned.fill(
child: new Material(
color: Colors.transparent,
child: new InkWell(
onTap: onTap,
))),
],
);
}
}
You can also take in a color in the constructor and user 'splashColor' property of the InkWell widget to set the splash color.