I have an app with two containers next to each other/above each other with Row()/Column() widgets accordingly. Both containers have drop shadows in their box decoration parameter. If they are close to each other the one on the top/left casts a shadow on the other one.
Is there a way I can make a widget not have shadows drawn on it?
Edit: here is an example of what I mean.
I don't want the first container to have a shadow from the second container but rather have both containers above the shadows.
Here is the code for this sample: you can copy paste it into dartpad.dev for quick testing.
import 'package:flutter/material.dart';
final Color darkBlue = Colors.grey[200]!;
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: Row(
children: [
SizedBox(width: 20),
Container(
height: 100,
width: 300,
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [BoxShadow(
blurRadius: 20,
color: Colors.black.withOpacity(0.6)
)]
),
),
Container(
height: 100,
width: 300,
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [BoxShadow(
blurRadius: 20,
color: Colors.black
)]
),
),
]
),
),
),
);
}
}
if they both have their own shadows, I guess there is no way to accomplish what you want.
an alternative way could be, giving the shadow to the parent, here is the example code:
import 'package:flutter/material.dart';
final Color darkBlue = Colors.grey[200]!;
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: Container(
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(blurRadius: 20, color: Colors.black),
],
),
child: Row(
children: [
Expanded(
child: Container(
height: 100,
width: 300,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(width: .2),
),
),
),
Expanded(
child: Container(
height: 100,
width: 300,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(width: .2),
),
),
),
],
),
),
),
),
);
}
}
I wrapped each of them with Expanded, to make sure to fill the parent.
Related
I am very new to flutter and i am trying to create a flashcard app The left part is what i need to make
I am trying to make a container and add a text which says title and answer and in the same container i need to set a delete button if anyone wants to delete that flashcard , but to do so i need to child in the same container which is not possible , can anyone help me about how to make a flashcard looking like this in flutter?
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(
home:Home()
));
class Home extends StatelessWidget {
#override
Widget build(BuildContext context) {
return
Scaffold(
backgroundColor: Colors.deepPurple[600],
appBar:AppBar(
title: Text("FlashCards",style:TextStyle(fontSize: 25.0,fontWeight:FontWeight.bold,color:Colors.black,fontFamily:'ZenDots')),
centerTitle:true,
backgroundColor: Colors.deepOrange[300],
),
body: Column(
children:<Widget>[
Container(
padding:EdgeInsets.fromLTRB(10,60 ,100,80),
margin:EdgeInsets.all(30.0),
child: Text("Title:- \n\n\n\nAnswer:- ",style:TextStyle(fontFamily:'ZenDots',fontSize:12,))
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.0),
color: Colors.amber,
floatingActionButton
),
),
Container(
child: IconButton(onPressed:null, icon:Icon(Icons.delete,color: Colors.black,)),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.0),
color: Colors.amber,
),
)
],
),
//IconButton(onPressed:null, icon:Icon(Icons.delete)),
floatingActionButton: FloatingActionButton(onPressed:null,
child:Text("+",style:TextStyle(fontSize: 25.0,color: Colors.black)),
backgroundColor: Colors.amber,
),
);
}
}
I have tried doing this , but the delete button comes below the card and i want it on the bottom right corner of the container which says title and answer.
My output :- [This is how i made it](https://i.stack.imgur.com/APDb4.png)
it is because you do not use inside of the column. All you have to do is move it to Column
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(
home:Home()
));
class Home extends StatelessWidget {
#override
Widget build(BuildContext context) {
return
Scaffold(
backgroundColor: Colors.deepPurple[600],
appBar:AppBar(
title: Text("FlashCards",style:TextStyle(fontSize: 25.0,fontWeight:FontWeight.bold,color:Colors.black,fontFamily:'ZenDots')),
centerTitle:true,
backgroundColor: Colors.deepOrange[300],
),
body: Column(
children:<Widget>[
Container(
padding:EdgeInsets.fromLTRB(10,60 ,100,80),
margin:EdgeInsets.all(30.0),
child: Text("Title:- \n\n\n\nAnswer:- ",style:TextStyle(fontFamily:'ZenDots',fontSize:12,))
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.0),
color: Colors.amber,
floatingActionButton
),
),
Container(
child: IconButton(onPressed:null, icon:Icon(Icons.delete,color: Colors.black,)),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.0),
color: Colors.amber,
),
),
IconButton(onPressed:null, icon:Icon(Icons.delete)),
],
),
floatingActionButton: FloatingActionButton(onPressed:null,
child:Text("+",style:TextStyle(fontSize: 25.0,color: Colors.black)),
backgroundColor: Colors.amber,
),
);
}
}
I'm wanted to achieve the following UI in the screenshot and achieved by the below code on two different phones. But the same is not working on many other devices. Is there a way to handle the size of CircularProgressIndicator(currently I'm using Transform.scale() which is not giving me generic result) so that it fits around the sibling container inside the stack?
Edit:
The reason for using CircularProgressIndicator is to show progress.
Widget build(BuildContext context) {
final mediaq = MediaQuery.of(context).size;
return Stack(alignment: Alignment.center, children: [
Transform.scale(
scale: mediaq.width <= 360 ? 2.35 : 2.70,
child: const CircularProgressIndicator(
backgroundColor: Colors.white,
color: Colors.orange,
strokeWidth: .75,
value: 1,
),
),
Container(
decoration: const BoxDecoration(
shape: BoxShape.circle,
gradient: LinearGradient(
colors: [Colors.red, Colors.orange],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.transparent,
fixedSize: Size(mediaq.width * .24, mediaq.height * .12),
shape: const CircleBorder(side: BorderSide.none),
),
onPressed: () {},
child: const Text("child")),
),
]);
}
Re wrote your code and here is my output
Transform.scale(
scale: mediaq.width> 375 ? 3.10 : 2.35,
child: const CircularProgressIndicator(
backgroundColor: Colors.white,
color: Colors.white,
strokeWidth: .75,
value: 1,
),
),
Output:
Iphone 12 Pro Max (W:428 , H:926)
Iphone SE (Second Generation) (W:375, H: 667)
Also you can try this package for responsive ui.
You can use flutter_screenutil package to make your UI more responsive, instead of MediaQuery.
I have done your screen using flutter_screenutil package.
Please try this out. I assumed the heights, widths, and radius. You can modify these as per your requirement. I have also attached the UI I got.
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return ScreenUtilInit(
designSize: const Size(375, 667),
minTextAdapt: true,
builder: () {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const ButtonTest(),
);
});
}
}
class ButtonTest extends StatefulWidget {
const ButtonTest({Key? key}) : super(key: key);
#override
_ButtonTestState createState() => _ButtonTestState();
}
class _ButtonTestState extends State<ButtonTest> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
body: Center(
child: Container(
height: 94.h, // You can change here
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: Colors.white,
),
),
child: Padding(
padding: EdgeInsets.all(
2.0.w, // You can change here
),
child: GestureDetector(
onTap: () {
print("Button Pressed");
},
child: Container(
height: 92.h, // You can change here
width: 92.h, // You can change here
decoration: const BoxDecoration(
shape: BoxShape.circle,
gradient: LinearGradient(
colors: [
Colors.red,
Colors.orange,
],
),
),
child: const Center(
child: Text(
'child',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
)),
),
),
),
),
),
);
}
}
I have a container wrapped in Dismissible, both the container and dismissible background have their corners cut.
My problem is that even though the corner of the container on top is cut the space that would have been the corner is white instead of transparent.
Here's What I have vs What I want (made on paint)
I tried throwing Colors.transparent around but had no success.
Here is the full code:
import 'package:flutter/material.dart';
class Test extends StatefulWidget {
#override
_TestState createState() => _TestState();
}
class _TestState extends State<Test> {
static const Radius _borderRadius = const Radius.circular(65.0);
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Dismissible(
key: ValueKey("hmm"),
background: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.red, width: 3),
borderRadius: BorderRadius.all(_borderRadius),
color: Colors.white,
),
),
secondaryBackground: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.red, width: 3),
borderRadius: BorderRadius.all(_borderRadius),
color: Colors.white,
),
),
child: Container(
width: 300,
height: 200,
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(_borderRadius),
gradient: LinearGradient(
colors: [Colors.blue, Colors.pink],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
)),
),
)),
);
}
}
Found here
The problem is the clipping behavior in dismissible.dart. I've managed to solve the problem by editing the Dismissible class itself. In lines 559 - 573, you will find an if-statement that looks like this:
if (background != null) {
content = Stack(children: <Widget>[
if (!_moveAnimation.isDismissed)
Positioned.fill(
child: ClipRect(
clipper: _DismissibleClipper(
axis: _directionIsXAxis ? Axis.horizontal : Axis.vertical,
moveAnimation: _moveAnimation,
),
child: background,
),
),
content,
]);
}
If you just comment out the clipper-property in ClipRect, the background will be transparent and you won't lose the collapsing animation.
You can fix this by using moving your background out of your Dismissible:
Full source code:
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
home: HomePage(),
),
);
}
class HomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Test(),
);
}
}
class Test extends StatefulWidget {
#override
_TestState createState() => _TestState();
}
class _TestState extends State<Test> {
static const Radius _borderRadius = const Radius.circular(65.0);
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
Center(
child: Container(
width: 300,
height: 200,
decoration: BoxDecoration(
border: Border.all(color: Colors.red, width: 3),
borderRadius: BorderRadius.all(_borderRadius),
color: Colors.white,
),
),
),
Dismissible(
key: ValueKey("hmm"),
child: Center(
child: Container(
width: 300,
height: 200,
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(_borderRadius),
gradient: LinearGradient(
colors: [Colors.blue, Colors.pink],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
),
),
),
],
),
);
}
}
I am working on a SplashScreen for my new Flutter app.
Here you have a screenshot of it:
And here you have the code for the current Scaffold:
return Scaffold(
body: Stack(
alignment: Alignment.bottomCenter,
children: [
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/splash/${yourList[randomIndex]}"),
fit: BoxFit.cover,
),
),
// child: [Your content here],
),
Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height * 0.1,
decoration: new BoxDecoration(
color: const Color(0xFFFFFFFF).withOpacity(0.5),
image: DecorationImage(
image: new AssetImage('assets/images/app_icon_trans.png'),
),
),
child: Text(
"© 2020 Mov-Map version: ${_projectVersion}",
style: TextStyle(
color: Colors.red,
fontWeight: FontWeight.bold,
fontSize: 16.0),
))
],
),
);
I would like to change the layout for the second container. I would like to put the image on the left side and the text just after the image, vertically at the center of the image.
I have been searching for a solution for a couple of hours and I would appreciate your proposals.
Is this how you would like it? Use a row (I don't have your asset image, so I used a blue container instead)
Copy/paste this code into www.dartpad.dev/flutter to play with it:
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 Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height * 0.1,
decoration:
new BoxDecoration(color: const Color(0xFFFFFFFF).withOpacity(0.5)),
child: Row(children: [
Container(
width: 40,
height: 40,
color: Colors.blue,
),
Text(
"© 2020 Mov-Map version: 1",
style: TextStyle(
color: Colors.red, fontWeight: FontWeight.bold, fontSize: 16.0),
),
]));
}
}
You can also change the Row's alignment using crossAxisAlignment and/or mainAxisAlignment if needed.
I want to make flutter mobile app look like this
1
but i from my code i get this appearance
2
and here is my code
import 'package:flutter/material.dart';
class HomePage extends StatefulWidget {
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
elevation: 0.0,
backgroundColor: Colors.blue,
title: Text('title'),
),
body: Column(
children: <Widget>[
Container(
color: Colors.blue,
height: 150,
width: 500,
),
Image.asset(
'src/image.png',
width: 400,
),
Container(
//flatbutton group
),
],
),
);
}
}
i have tried to use stack, but it doesn't work, or i was false when implemented that.
anyone want to help me to resolve that?
Use a stack instead of column
Here is the updated full code:
class HomePage extends StatefulWidget {
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
elevation: 0.0,
backgroundColor: Colors.blue,
title: Text('SIAP UNDIP'),
),
body: Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Container(
color: Colors.blue,
height: 150,
width: 500,
),
Column(
children: <Widget>[
Container(
height: 90,
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
shape: BoxShape.rectangle,
borderRadius: BorderRadius.all(Radius.circular(8.0)),
color: Colors.green,
image: DecorationImage(
image: AssetImage(
'src/image.png', // Enter the image here
),
),
),
),
Container(
height: 200,
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
shape: BoxShape.rectangle,
borderRadius: BorderRadius.all(Radius.circular(8.0)),
boxShadow: [
BoxShadow(
color: Colors.grey[300],
spreadRadius: 1,
blurRadius: 4,
offset: Offset(0, 2),
),
],
color: Colors.white,
),
// child: , //Enter all the flat Buttons here
),
],
),
],
),
);
}
}