Overflow visible in Expanded widget - flutter

My layout is a row with three expanded widgets.
I need overflow visible in one of the expanded widgets
This is the code
Row(
children: [
Expanded(
flex: 1,
child: Container(color: Colors.red,)
),
Expanded(
flex: 2,
child: Container(color: Colors.green,)
),
Expanded(
flex: 3,
child: Container(color: Colors.orange,)
),
],
),
Now I need to add circles like this, in of the Expanded widgets, that overflow the Expanded widget. I can't wrap the Expanded in an overflow box, so I am lost
Any help is appreciated.
Edit: I tried this with the third expanded, just to see if it will overflow, but it only overflows the SizedOverflowBox, no overflow over the Expanded
Expanded(
flex: 3,
child: SizedOverflowBox(
size: const Size(100.0, 100.0),
alignment: AlignmentDirectional.bottomCenter,
child: Container(height: 50.0, width: 1500.0, color: Colors.blue,),
),
),
It looks like it is not going to be possible

Can easily be achieved with a Stack. Please see the code below :
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Stack(
children: [
Row(
children: [
Expanded(
flex: 1,
child: Container(
color: Colors.red,
)),
Expanded(
flex: 2,
child: Container(
color: Colors.green,
)),
Expanded(
flex: 3,
child: Container(
color: Colors.orange,
)),
],
),
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
height: 25,
width: 25,
decoration:
BoxDecoration(color: Colors.black, shape: BoxShape.circle),
child: Center(
child: Container(
height: 15,
width: 15,
decoration: BoxDecoration(
color: Colors.white, shape: BoxShape.circle),
),
),
),
Container(
height: 25,
width: 25,
decoration:
BoxDecoration(color: Colors.black, shape: BoxShape.circle),
child: Center(
child: Container(
height: 15,
width: 15,
decoration: BoxDecoration(
color: Colors.white, shape: BoxShape.circle),
),
),
),
Container(
height: 25,
width: 25,
decoration:
BoxDecoration(color: Colors.black, shape: BoxShape.circle),
child: Center(
child: Container(
height: 15,
width: 15,
decoration: BoxDecoration(
color: Colors.white, shape: BoxShape.circle),
),
),
),
],
),
),
],
);
}
}
Please see the code for Text Bullet points overflowing.
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(),
body: MyWidget(),
),
);
}
}
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 1,
child: Container(
color: Colors.red.withAlpha(60),
child: OverflowBox(
alignment: Alignment.topLeft,
maxWidth: 400,
child: SizedBox(
width: 300,
child: Text(
'HelloHello 🅐',
style: TextStyle(color: Colors.white),
),
),
),
),
),
Expanded(
flex: 2,
child: Container(
color: Colors.green.withAlpha(60),
child: OverflowBox(
alignment: Alignment.topLeft,
maxWidth: 400,
child: SizedBox(
width: 300,
child: Container(
child: Text(
'\n\nHelloHello HelloHello 🅐\n\nHelloHello HelloHello 🅐\n\nHelloHello HelloHello 🅐\n\nHelloHello HelloHello 🅐',
style: TextStyle(color: Colors.white),
),
),
),
),
),
),
Expanded(
flex: 3,
child: Container(
color: Colors.purple.withAlpha(60),
child: OverflowBox(
alignment: Alignment.topLeft,
maxWidth: 400,
child: SizedBox(
width: 300,
child: Text(
'\n\n\n\n\n\n\n\n\n\n\n\Hello Hello Hello Hello Hello Hello ',
style: TextStyle(color: Colors.white),
),
),
),
),
),
],
);
}
}

Related

Can I have an idea for Tabber in Flutter?

I have no idea How to make Tab bar like This in my flutter web
Can I have an idea or How call This pattern.
Example video:
https://youtu.be/A3ttwYljg_8
You just have to give body to TabBarView, rest will be taken care by flutter itself.
Sample Code : -
TabBarView(
children: <Widget>[
Tabbar 1 body ...., //1st index, 1st tab
Tabbar 2 body ...., //2nd index, 2nd tab
Tabbar 3 body ...., //...
Tabbar 4 body ...., //...
Tabbar 5 body .... //...
]
)
TabBarView
Complete Code : -
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
#override
Widget build(BuildContext context) {
return const MaterialApp(
title: _title,
home: MyStatelessWidget(),
);
}
}
class MyStatelessWidget extends StatefulWidget {
const MyStatelessWidget({super.key});
#override
State<MyStatelessWidget> createState() => _MyStatelessWidgetState();
}
class _MyStatelessWidgetState extends State<MyStatelessWidget> {
#override
Widget build(BuildContext context) {
return DefaultTabController(
initialIndex: 0,
length: 5,
child: Scaffold(
appBar: AppBar(
backgroundColor: const Color.fromARGB(255, 107, 179, 234),
title: const Text('TabBar Widget'),
bottom: const TabBar(
labelColor: Colors.black,
indicator: BoxDecoration(color: Colors.yellow),
labelPadding: EdgeInsets.only(bottom: 5),
indicatorPadding:
EdgeInsets.only(left: 30, right: 30, bottom: 10, top: 5),
tabs: <Widget>[
SizedBox(
width: 70,
height: 40,
child: Center(
child: Tab(
text: "Tab 1",
),
),
),
SizedBox(
width: 70,
height: 40,
child: Tab(
text: "Tab 2",
),
),
SizedBox(
width: 70,
height: 40,
child: Tab(
text: "Tab 3",
),
),
SizedBox(
width: 70,
height: 40,
child: Tab(
text: "Tab 4",
),
),
SizedBox(
width: 70,
height: 40,
child: Tab(
text: "Tab 5",
),
),
],
),
),
body: TabBarView(
children: <Widget>[
Column(
children: [
Expanded(
child: Container(
color: Colors.red,
)),
Expanded(
child: Container(
color: Colors.purple,
))
],
),
Column(
children: [
Expanded(
child: Container(
color: const Color.fromARGB(255, 9, 79, 135),
)),
Expanded(
child: Container(
color: Colors.purple,
))
],
),
Column(
children: [
Expanded(
child: Container(
color: const Color.fromARGB(255, 144, 255, 54),
)),
Expanded(
child: Container(
color: Colors.purple,
))
],
),
Column(
children: [
Expanded(
child: Container(
color: const Color.fromARGB(255, 109, 40, 36),
)),
Expanded(
child: Container(
color: Colors.yellow,
))
],
),
Column(
children: [
Expanded(
child: Container(
color: Colors.green,
)),
Expanded(
child: Container(
color: Colors.yellow,
))
],
),
],
),
),
);
}
}
Output :-

Positioning widget not effective | How to position containers

I am still new to flutter, and I want to position the box in the screenshot below, not in the centre of the screen, but at a certain distance away from the left side with text inside the box.
I have tried the positioning widget but still no luck.
Any advice on what widget I would use, and how to do so properly?
#override
Widget build(BuildContext context) {
return DecoratedBox(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/startbackground.jpg"),
fit: BoxFit.cover),
),
child: Center(
child: Container(
height: 500.0,
width: 120.0,
color: Colors.blue[50],
child: Align(
alignment: Alignment.topRight,
child: FlutterLogo(
size: 60,
),
),
),
));
}
}
Try out that code. I mainly used containers, paddings, alignment property as well as the axis alignment for the column. With that I achieved what you can see on the screenshot below. In order to use an image behind all that, I would just simply recommend to use a stack and then this whole code with some adaptations. The colors are just illustrative. You could set all of them transparent.
Here is the screenshot:
And here is the code:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blue,
appBar: AppBar(
title: Text("EXAMPLE"),
),
body: Container(
color: Colors.orangeAccent,
height: double.infinity,
width: double.infinity,
alignment: Alignment.bottomLeft,
child: UnconstrainedBox(
child: Padding(
padding: const EdgeInsets.only(left: 50, bottom: 50),
child: Container(
height: 400,
width: 200,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
flex: 1,
child: Container(
child: Text("Text", style: TextStyle(fontSize: 30, fontWeight: FontWeight.w700),textAlign: TextAlign.left,),
color: Colors.purpleAccent,
),
),
Expanded(
flex: 3,
child: Container(
child: Text("Some Text", style: TextStyle(fontSize: 60, fontWeight: FontWeight.w700),),
color: Colors.purpleAccent,
),
),
Expanded(
flex: 3,
child: Container(
child: Text("Some Text", style: TextStyle(fontSize: 60, fontWeight: FontWeight.w700),),
color: Colors.teal,
),
),
Expanded(
flex: 2,
child: Padding(
padding: EdgeInsets.all(15),
child: FlatButton(
minWidth: 200,
onPressed: (){},
child: Text(
"HI",
style: TextStyle(
color: Color(0xff7638c9),
fontSize: 11),
),
color: Colors.transparent,
shape: RoundedRectangleBorder(
side: BorderSide(color: Colors.purple),
borderRadius: BorderRadius.circular(18.0),
),
),
),
),
],
),
),
),
),
),
);
}
}

How to change the text in first screen when there is any change in third screen using provider package in flutter?

I have a firstscreen called including stateful widget, PlantFeatureScreen1 where I have to show the change when the update occurs in thirdscreen which also includes a stateful widget, CartDetais3.
How can i update the first screen when changes happens in third screen and addQuantity and subtractQuantity functions will be added in third screen? Please suggest using provider package.
firstScreen code Here I have to show the change in very last center widget of this widget tree.
class PlantFeatureScreen1 extends StatefulWidget {
#override
_PlantFeatureScreen1State createState() => _PlantFeatureScreen1State();
}
class _PlantFeatureScreen1State extends State<PlantFeatureScreen1> {
#override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
TopAppBar(),
Expanded(
flex: 1,
child: Align(
alignment: Alignment(-1, 0),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
),
child: Text(
"Plants",
style: TextStyle(fontSize: 30, fontWeight: FontWeight.w700),
),
),
),
),
Expanded(
flex: 5,
child: Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.blue,
),
child: DefaultTabController(
length: 5,
child: Column(
children: [
Container(
height: 50,
width: double.infinity,
child: TabBar(
isScrollable: true,
tabs: ourAllLists.tabMaker(),
),
),
Container(
height: 317,
width: double.infinity,
decoration: BoxDecoration(color: Colors.white),
child: TabBarView(
children: ourAllLists.tabViewerMaker(context),),),
],
),
),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(20, 0, 20, 20),
child: Container(
alignment: Alignment.bottomRight,
height: 120,
width: double.infinity,
child: Stack(
overflow: Overflow.visible,
children: [
Container(
height: 70,
width: 105,
decoration: BoxDecoration(
color: Color(0xFF96CA2D),
borderRadius: BorderRadiusDirectional.horizontal(
end: Radius.circular(32),
start: Radius.circular(32))),
child: Icon(FontAwesomeIcons.shoppingBag,color:Colors.white,size:30),
),
Positioned(
// top: 0,
bottom: 50,
right: 0,
child: Container(
height: 35,
width: 35,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(50),
border: Border.all(color: Color(0xFF96CA2D),width: 4)
),
child: Center(child: Text(ourAllLists.totalquantity().toString(),style:TextStyle(fontSize: 20,color: Color(0xFF96CA2D)))),
),
)
],
),
),
)
],
);
}
}
thirdScreen code Here the update happens when the + or - icons get clicked.
class CartDetais3 extends StatefulWidget {
#override
_CartDetais3State createState() => _CartDetais3State();
}
class _CartDetais3State extends State<CartDetais3> {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: SafeArea(
child: Scaffold(
body: Padding(
padding: const EdgeInsets.fromLTRB(8, 20, 8, 15),
child: Column(
children: [
TopAppBar(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Cart",
style: kPlantNameStyle,
),
Text(
"\$" + "284",
style: kItemPrice,
),
],
),
Expanded(
child: ListView.builder(
itemCount: OurAllLists.cartPlantList3.length,
itemBuilder: (context, index) {
return Card(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
height: 110,
width: 100,
child: Image(image: AssetImage("assets/tulip.png")),
),
Container(
height: 80,
width: 120,
child: Column(
children: [
Text(OurAllLists.cartPlantList3[index].pN),
Text(OurAllLists.cartPlantList3[index].ca
.toUpperCase()),
Text("\$ " +
OurAllLists.cartPlantList3[index].pr
.toString()),
],
),
),
Container(
height: 120,
child: Column(
children: [
FlatButton(
onPressed: () {
setState(() {
*here addQuantity function must go*
});
},
child: Icon(
FontAwesomeIcons.plus,
size: 20,
),
),
Text(OurAllLists.cartPlantList3[index].qu
.toString()),
FlatButton(
onPressed: () {
*here subtractQuantity function must go*
},
child: Icon(
FontAwesomeIcons.minus,
size: 20,
),
),
],
))
],
),
);
}),
)
],
),
),
)));
}
}
I have a also a seperate class called ViewTotallItemProvider
class ViewTotalItemProvider extends ChangeNotifier{
addQuantity(index){
OurAllLists.cartPlantList3[index].qu++;
notifyListeners();
}
subtrachQuantity(index){
OurAllLists.cartPlantList3[index].qu--;
}
}

Custom Button in Flutter

What I am trying to achieve is below:
Should I be using Row with Icon and Text?
Here is my code and its output
RaisedButton(
elevation: 10,
onPressed: () {},
color: Colors.white,
child: Padding(
padding: EdgeInsets.all(10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
height: 55,
color: Colors.deepPurple,
child: Icon(
Icons.settings,
color: Colors.white,
),
),
Text(
'Settings',
style: TextStyle(
fontSize: 25,
),
),
],
),
),
);
OUTPUT:
Any help would be appreciated.
Here you go
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.light(), //.copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
get borderRadius => BorderRadius.circular(8.0);
#override
Widget build(BuildContext context) {
return Center(
child: Material(
elevation: 10,
borderRadius: borderRadius,
child: InkWell(
onTap: () {},
child: Container(
padding: EdgeInsets.all(0.0),
height: 60.0,//MediaQuery.of(context).size.width * .08,
width: 220.0,//MediaQuery.of(context).size.width * .3,
decoration: BoxDecoration(
borderRadius: borderRadius,
),
child: Row(
children: <Widget>[
LayoutBuilder(builder: (context, constraints) {
print(constraints);
return Container(
height: constraints.maxHeight,
width: constraints.maxHeight,
decoration: BoxDecoration(
color: Colors.deepPurple,
borderRadius: borderRadius,
),
child: Icon(
Icons.settings,
color: Colors.white,
),
);
}),
Expanded(
child: Text(
'Settings',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 25,
),
),
),
],
),
),
),
),
);
}
}
John Joe's answer is correct. Here is another solution that does the same with plain Container widget. I am posting it here just in case someone interested.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: Colors.white),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: EdgeInsets.all(8.0),
child: MyWidget(),
),
],
),
),
);
}
}
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return SizedBox(
height: 48.0,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(8.0),
),
boxShadow: [
BoxShadow(
color: Colors.grey,
offset: Offset(1.0, 2.0),
blurRadius: 8.0,
spreadRadius: 2.0)
]),
child: Stack(
children: <Widget>[
Row(
children: <Widget>[
Container(
width: 48.0,
height: 48.0,
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
color: Colors.deepPurple,
borderRadius: BorderRadius.all(
Radius.circular(8.0),
),
),
child: Align(
alignment: Alignment.center,
child: Icon(Icons.settings))),
Expanded(
child: Center(
child: Text("Hellow world",
style: Theme.of(context)
.textTheme
.headline6
.copyWith(color: Colors.black)),
)),
],
),
SizedBox.expand(
child: Material(
type: MaterialType.transparency,
child: InkWell(onTap: () {}),
),
),
],
),
),
);
}
}
See the live demo here.
You can use Column and Row.
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Padding(
padding: EdgeInsets.all(10),
child: Column(
children: <Widget>[
_firstWidget(),
SizedBox(height: 15),
_secondWidget(),
],
)),
);
}
Widget _firstWidget() {
return InkWell(
onTap: () {},
child: Card(
shape: BeveledRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
elevation: 2,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
flex: 1,
child: Container(
height: 55,
width: 30,
decoration: myBoxDecoration(),
child: Icon(
Icons.settings,
color: Colors.white,
),
)),
Expanded(
flex: 3,
child: Padding(
padding: EdgeInsets.only(left: 15),
child: Text(
'Programs & Services',
style: TextStyle(
fontSize: 25,
),
))),
],
),
));
}
Widget _secondWidget() {
return InkWell(
onTap: () {},
child: Card(
shape: BeveledRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
elevation: 2,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
flex: 1,
child: Container(
decoration: myBoxDecoration(),
height: 55,
width: 30,
child: Icon(
Icons.settings,
color: Colors.white,
),
)),
Expanded(
flex: 3,
child: Padding(
padding: EdgeInsets.only(left: 15),
child: Text(
'Settings',
style: TextStyle(
fontSize: 25,
),
))),
],
),
));
}
BoxDecoration myBoxDecoration() {
return BoxDecoration(
color: Colors.deepPurple,
borderRadius: BorderRadius.all(
Radius.circular(5.0) // <--- border radius here
),
);
}
Output
Darish's answer seems to me the best, since the splash is displayed on top of everything and makes a very good visual effect.
Even so, since the answer is from so long ago, I wanted to put here the updated code to NullSafety and also correct some bugs and remove unnecessary things.
For the rest it is perfect.
Here my code:
class MyWidget extends StatelessWidget {
const MyWidget({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8.0),
boxShadow: const [
BoxShadow(
color: Colors.grey,
offset: Offset(1.0, 2.0),
blurRadius: 8.0,
spreadRadius: 2.0,
)
],
),
child: SizedBox(
height: 48,
child: Stack(
children: [
Row(
children: <Widget>[
Container(
width: 48.0,
height: 48.0,
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
color: Colors.deepPurple,
borderRadius: BorderRadius.circular(8),
),
child: const Center(
child: Icon(Icons.settings, color: Colors.white),
),
),
const Expanded(
child: Center(
child: Text("Hellow world"),
),
),
],
),
Material(
type: MaterialType.transparency,
child: InkWell(
onTap: () {},
borderRadius: BorderRadius.circular(8.0),
),
),
],
),
),
);
}
}

Flutter: Image button circled

image description here
i d like to centralize 3 image buttons at the screen one on top of the other with a onpressed in each of them below there is my start code.
class Escolha extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
),
body: Material(
elevation: 4.0,
shape: CircleBorder(),
color: Colors.transparent,
child: Ink.image(
image: AssetImage('assets/logotipo.png'),
fit: BoxFit.cover,
width: 100.0,
height: 120.0,
child: InkWell(
)
)
)
),
);
}
}
I have made the UI of the image you have mentioned in the link. Here is the working code.
class _HomePageState extends State<HomePage> {
#override
Widget build(BuildContext context) {
return Container(
color: Colors.black,
child: Center(
child: Row(
children: <Widget>[
Expanded(
flex: 2,
child: Container(
height: 2.0,
color: Colors.greenAccent,
),
),
Expanded(flex: 2, child: Image.asset("assets/four.png"),),
Expanded(
flex: 1,
child: Container(
height: 2.0,
color: Colors.greenAccent,
),
),
Expanded(flex: 2, child: Image.asset("assets/three.png"),),
Expanded(
flex: 1,
child: Container(
height: 2.0,
color: Colors.greenAccent,
),
),
Expanded(flex: 2, child: Image.asset("assets/two.png"),),
Expanded(
flex: 1,
child: Container(
height: 2.0,
color: Colors.greenAccent,
),
),
Expanded(flex: 2, child: Image.asset("assets/one.png"),),
Expanded(
flex: 2,
child: Container(
height: 2.0,
color: Colors.greenAccent,
),
),
],
),
),
);
}
}
This is the output.