Related
When I open a dialog in flutter I want the background to become a light blue with opacity as shown in the image below:
I've set the surfaceTintColor of my Dialog widget to the color I want, but it is not being applied. Instead I see the default elevation of the dialog. here is my code:
class PickImageDialog extends StatelessWidget {
const PickImageDialog({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Dialog(
surfaceTintColor: Theme.of(context).colorScheme.surfaceTint,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16))),
child: Padding(
padding: const EdgeInsets.fromLTRB(10, 16, 10, 22),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
children: [
IconButton(
onPressed: () {
context.router.pop();
},
icon: Icon(Icons.clear),
),
Expanded(
child: Text(
AppStrings.pickImage,
textAlign: TextAlign.center,
),
),
],
),
SizedBox(
height: 26,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
height: 60,
width: 60,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(16)),
border: Border.all(
width: 2, color: Theme.of(context).primaryColor),
color: Theme.of(context).colorScheme.surfaceTint),
child: SvgPicture.asset(
AppVectors.camera,
color: Theme.of(context).primaryColor,
height: 28,
),
), Container(
height: 60,
width: 60,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(16)),
border: Border.all(
width: 2, color: Theme.of(context).primaryColor),
color: Theme.of(context).colorScheme.surfaceTint),
child: SvgPicture.asset(
AppVectors.gallery,
color: Theme.of(context).primaryColor,
height: 28,
),
),
],
)
],
),
),
);
}
}
If you want to show a dialog you can use barrierColor property, like this:
InkWell(
child: Text('click'),
onTap: () {
showDialog(
context: context,
builder: (_) => PickImageDialog(),
barrierColor: Colors.red.withOpacity(0.4), // <--- add this
);
},
),
And if you want to blur the background you can wrap your Dialog with BackdropFilter in your PickImageDialog class:
BackdropFilter( // <--- add this
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),// <--- add this
child: Dialog(
shape: RoundedRectangleBorder(
...
)
Salaam, For having a blur background first of all edit your PickImageDialog to this:
BackdropFilter(
filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),
child: Dialog(
// surfaceTintColor: Theme.of(context).colorScheme.surfaceTint,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16))),
child: Padding(
padding: const EdgeInsets.fromLTRB(10, 16, 10, 22),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
children: [
IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: Icon(Icons.clear),
),
Expanded(
child: Text(
'AppStrings.pickImage',
textAlign: TextAlign.center,
),
),
],
),
SizedBox(
height: 26,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
height: 60,
width: 60,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(16)),
border: Border.all(
width: 2, color: Theme.of(context).primaryColor),
color: Theme.of(context).colorScheme.surfaceTint),
child: Container(color: Colors.red,),
), Container(
height: 60,
width: 60,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(16)),
border: Border.all(
width: 2, color: Theme.of(context).primaryColor),
color: Theme.of(context).colorScheme.surfaceTint),
child: Container(color: Colors.amber,),
),
],
)
],
),
),
),
);
by the way i didn't see any codes to show your dialog if you haven't implemented it before here is the code you need:
/// put it in your CTA(call to action) of showing dialog
showDialog(
context: context,
builder: (_) => PickImageDialog(),
);
happy coding after Polytechnic!
AnimatedContainer(
duration: const Duration(milliseconds: 200),
curve: Curves.easeIn,
height: expandedStatus[index] ?300 : 160,
decoration: BoxDecoration(
boxShadow: const [
BoxShadow(
color: Color.fromARGB(168, 97, 97, 97),
offset: Offset(2,2),
blurRadius: 3,
spreadRadius: 1,
)
],
color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(20),
),
padding: EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width: MediaQuery.of(context).size.width-130,
child: Text(list[newIndex]['title'], style: _textTheme.headline6)
),
InkWell(
onTap: () async {
expandedStatus.removeAt(newIndex);
int i = await DatabaseClass.instance
.delete(list[newIndex]['url']);
displayNews();
},
child: Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.pink,
borderRadius: BorderRadius.circular(50)
),
child: Icon(Icons.delete_outline_outlined)
)
)
],
),
const SizedBox(height: 10),
Align(
alignment: Alignment.centerRight,
child: Text(
list[newIndex]['date'],
style: _textTheme.subtitle2,
),
),
const SizedBox(
height: 10,
),
AnimatedCrossFade(
firstChild: Text("", style: TextStyle(fontSize: 0)),
secondChild: (list[newIndex]['_description'] != "") ?Flexible(child: Text(list[newIndex]['_description'].substring(0,list[newIndex]['_description'].length - 14), overflow: TextOverflow.ellipsis,maxLines: 5,style: _textTheme.subtitle1,)) :Text("Content Unavailable", style: _textTheme.subtitle1),
crossFadeState: !expandedStatus[index] ?CrossFadeState.showFirst :CrossFadeState.showSecond,
reverseDuration: Duration.zero,
sizeCurve: Curves.fastLinearToSlowEaseIn,
duration: Duration(milliseconds: 800)
)
],
),
)
AnimatedCrossFade Widget not displaying text in release mode instead it displaying a grey background
Above code is working fine in the debugging mode, but in release mode the description text is vanished and a grey colored background is appeared. I'm not sure why is this happening. Please help.
Release Mode
Debug Mode
The cause of your problem is the incorrect use of the Flexible widget.
Using flexible is wrong.
AnimatedContainer(
duration: const Duration(milliseconds: 200),
curve: Curves.easeIn,
height: expandedStatus[index] ?300 : 160,
decoration: BoxDecoration(
boxShadow: const [
BoxShadow(
color: Color.fromARGB(168, 97, 97, 97),
offset: Offset(2,2),
blurRadius: 3,
spreadRadius: 1,
)
],
color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(20),
),
padding: EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width: MediaQuery.of(context).size.width-130,
child: Text(list[newIndex]['title'], style: _textTheme.headline6)
),
InkWell(
onTap: () async {
expandedStatus.removeAt(newIndex);
int i = await DatabaseClass.instance
.delete(list[newIndex]['url']);
displayNews();
},
child: Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.pink,
borderRadius: BorderRadius.circular(50)
),
child: Icon(Icons.delete_outline_outlined)
)
)
],
),
const SizedBox(height: 10),
Align(
alignment: Alignment.centerRight,
child: Text(
list[newIndex]['date'],
style: _textTheme.subtitle2,
),
),
const SizedBox(
height: 10,
),
AnimatedCrossFade(
firstChild: Text("", style: TextStyle(fontSize: 0)),
secondChild: (list[newIndex]['_description'] != "") ? Column(children:[Flexible(child: Text(list[newIndex]['_description'].substring(0,list[newIndex]['_description'].length - 14), overflow: TextOverflow.ellipsis,maxLines: 5,style: _textTheme.subtitle1,))]) :Text("Content Unavailable", style: _textTheme.subtitle1),
crossFadeState: !expandedStatus[index] ?CrossFadeState.showFirst :CrossFadeState.showSecond,
reverseDuration: Duration.zero,
sizeCurve: Curves.fastLinearToSlowEaseIn,
duration: Duration(milliseconds: 800)
)
],
),
)
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
i am trying to create a splash screen that contain animation, of 3 widget.
i notice this:
if the 1st widget animate up the 2nd widget will animate down continuously
while the 3rd flip from right to lift.
How do i move 2 widget with little animation. i using stack with positioned widget in the design.
here is the design code:
Scaffold(
body: Container(
height: double.infinity,
width: double.infinity,
child: Stack(
children: [
SizedBox.expand(
child: Image.asset(
"assets/images/splash.png",
fit: BoxFit.fill,
),
),
Positioned(
right: -150,
child: Transform.rotate(
angle: -math.pi / 4.0,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Container(
height: 10,
width: 300,
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.5),
borderRadius: BorderRadius.circular(20),
),
),
SizedBox(
height: 15,
),
Container(
height: 25,
width: 400,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
),
),
SizedBox(
height: 15,
),
Container(
height: 15,
width: 210,
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.9),
borderRadius: BorderRadius.circular(20),
),
)
],
),
),
),
Positioned(
left: 0,
right: 0,
bottom: 10,
top: -120,
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Un',
style: TextStyle(
color: Colors.white,
fontSize: 45.sp,
fontWeight: FontWeight.w500),
),
SizedBox(
width: 5,
),
Animator(
tween: Tween(begin: 0.0, end: 6.35),
cycles: 1,
duration: Duration(seconds: 8),
builder: (context, anim, child) => Transform.rotate(
angle: 0,
child: child,
),
child: SvgPicture.asset(
"assets/white_lgo.svg",
width: 50.w,
height: 35.h,
),
),
SizedBox(
width: 5,
),
Text(
'leap',
style: TextStyle(
color: Colors.white,
fontSize: 45.sp,
fontWeight: FontWeight.w500),
),
],
),
),
),
Positioned(
left: -140,
bottom: 320,
child: Transform.rotate(
angle: -math.pi / 4.0,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Container(
height: 10,
width: 140,
decoration: BoxDecoration(
color: Color(0xff103E3F),
borderRadius: BorderRadius.circular(20),
),
),
SizedBox(
height: 15,
),
Container(
height: 25,
width: 70,
decoration: BoxDecoration(
color: Color(0xff103E3F),
borderRadius: BorderRadius.circular(20),
),
),
SizedBox(
height: 15,
),
Container(
height: 13,
width: 300,
decoration: BoxDecoration(
color: Color(0xff103E3F),
borderRadius: BorderRadius.circular(20),
),
)
],
),
),
),
],
),
),
);
the animation i am trying to achieve
expected
thanks
You should create an animationController like this:
late final AnimationController animationController = AnimationController(
duration: const Duration(milliseconds: 1000),
vsync: this,
);
and then add an animation. This code will generate numbers and you can use these numbers writing _doubleAnimation.value wherever you wanna change. For Example:
late final Animation<double> _doubleAnimation = Tween<double>(
begin: 0.0,
end: 6.34,
).animate(CurvedAnimation(
parent: animationController,
curve: Curves.fastOutSlowIn,
));
and run this function for infinity animation in initState:
animationController.repeat(reverse: true);
If you don't wanna reverse animation, you can change reverse to false.
Lastly, do not forget to use TickerProviderStateMixin. Also, you can take some help from here
I'm trying to make a widget to display posts by users on a social media platform, I have certain elements I want to include in the post, one of them being the external links he might have attached while creating the posts.
I want these links to be represented by rounded buttons(which I've managed to achieve through the use of ClipOval) and I want these ovals to be in a row spaced evenly from the center.
So far, the only way I've been able to space them out is by adding SizedBox(s) of a certain width. But this is not efficient for different posts may differ in the number of links and thus the number of Ovals. This would look messy then.
I have overlaid the row on top of the post's image(to which I've applied a linear gradient to make the buttons visible) using a stack.
Here's my code
class postTemplate extends StatelessWidget {
List <String> tags = ['tag1','tag2','tag3','tag4','tag5','tag6','tag7','tag8'];
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
SizedBox(height: 150,),
Container(
height: 450,
child: Stack(
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(height: 20,),
Card(
elevation: 8.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(32)
),
color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
ListTile(
title: Padding(
padding: const EdgeInsets.only(left : 70.0),
child: Text("Username"),
),
subtitle: Padding(
padding: const EdgeInsets.only(top: 10.0,left: 80.0),
child: Text("Hello"),
),
),
Stack(
children: [
Container(
child: Container(
foregroundDecoration:BoxDecoration(
gradient: LinearGradient(
colors: [Colors.white, Colors.transparent],
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
stops: [0, 0.3],
),),
child: Image(image: AssetImage('assets/images/modelPostImage.png'),fit: BoxFit.contain,)),
),
Positioned(
bottom: 10.0,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(width: 15,),
Container(
width: 56,
decoration: BoxDecoration(
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.black,
blurRadius: 2.0,
spreadRadius: 1.0,
)
]
),
child: ClipOval(
child: Material(// button color
child: InkWell(
splashColor: Colors.red, // inkwell color
child: SizedBox(width: 56, height: 56, child:Image(
image: new AssetImage("assets/Icons/browser.jpg"),
width: 32,
height:32,
color: null,
fit: BoxFit.scaleDown,
),),
onTap: () {},
),
),
),
),
SizedBox(width: 15,),
Container(
width: 60,
decoration: BoxDecoration(
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.black,
blurRadius: 2.0,
spreadRadius: 1.0,
)
]
),
child: ClipOval(
child: Material(// button color
child: InkWell(
splashColor: Colors.red, // inkwell color
child: SizedBox(width: 56, height: 56, child:Image(
image: new AssetImage("assets/Icons/browser.jpg"),
width: 32,
height:32,
color: null,
fit: BoxFit.scaleDown,
),),
onTap: () {},
),
),
),
),
SizedBox(width: 15,),
Container(
width: 60,
decoration: BoxDecoration(
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.black,
blurRadius: 2.0,
spreadRadius: 1.0,
)
]
),
child: ClipOval(
child: Material(// button color
child: InkWell(
splashColor: Colors.red, // inkwell color
child: SizedBox(width: 56, height: 56, child:Image(
image: new AssetImage("assets/Icons/browser.jpg"),
width: 32,
height:32,
color: null,
fit: BoxFit.scaleDown,
),),
onTap: () {},
),
),
),
),
],
),
),
],
),
Container(
height: 44,
width: 350,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(22))
),
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: tags.length,
itemBuilder: (BuildContext context, int index){
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(22),
border: Border.all(color: Colors.black)
),
margin: EdgeInsets.only(right: 13, left: 13),
child: Padding(
padding: const EdgeInsets.only(
top: 10.0, bottom: 5.0, right: 20, left:20
),
child: Text(tags[index],
style: TextStyle(
color: Colors.black
),),
),
);
},
),
),
],
),
)
],
),
CircleAvatar(
radius: 42,
backgroundImage: AssetImage('assets/Icons/profileLogo.jpg')
)
],
),
),
],
),
);
}
}
Any help would be appreciated.
Wrap with a container and give it full width and remove sizing
Positioned(
bottom: 10.0,
child: Container(
width:MediaQuery.of(context).size.width,
child :Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
width: 56,
decoration: BoxDecoration(
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.black,
blurRadius: 2.0,
spreadRadius: 1.0,
)
]
),
child: ClipOval(
child: Material(// button color
child: InkWell(
splashColor: Colors.red, // inkwell color
child: SizedBox(width: 56, height: 56, child:Image(
image: new AssetImage("assets/Icons/browser.jpg"),
width: 32,
height:32,
color: null,
fit: BoxFit.scaleDown,
),),
onTap: () {},
),
),
),
),
Container(
width: 60,
decoration: BoxDecoration(
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.black,
blurRadius: 2.0,
spreadRadius: 1.0,
)
]
),
child: ClipOval(
child: Material(// button color
child: InkWell(
splashColor: Colors.red, // inkwell color
child: SizedBox(width: 56, height: 56, child:Image(
image: new AssetImage("assets/Icons/browser.jpg"),
width: 32,
height:32,
color: null,
fit: BoxFit.scaleDown,
),),
onTap: () {},
),
),
),
),
Container(
width: 60,
decoration: BoxDecoration(
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.black,
blurRadius: 2.0,
spreadRadius: 1.0,
)
]
),
child: ClipOval(
child: Material(// button color
child: InkWell(
splashColor: Colors.red, // inkwell color
child: SizedBox(width: 56, height: 56, child:Image(
image: new AssetImage("assets/Icons/browser.jpg"),
width: 32,
height:32,
color: null,
fit: BoxFit.scaleDown,
),),
onTap: () {},
),
),
),
),
],
),
),
),
],
),
There is a specialized widget to create even space instead of using SizedBox. Replace SizedBox with Spacer.