The code below is my button part code.
When this button is clicked, I want to display the color of the border of the bookmarked buttons on the "Page Selection Page (code below)" to change color.
Actually the most important part is using shared_preferences: ^2.0.7 to make it stored locally.
I've seen and tried several examples, but I'm struggling on the 4th day.
bool recognizing = false;
...
actions: <Widget>[
IconButton(
onPressed: recognizing ?
Function for Remove from Favorites : function to add to favorites,
icon: recognizing
? Icon(Icons.bookmark_rounded, color: Colors.yellow[800], size: 30) //그대로일때
: Icon(Icons.bookmark_add_outlined, color: Colors.yellow[800],size: 30),
),
],
Below is the button code. In the previous "Page Selection Page", call and use the code below as child:LearnLevelButton().
class LearnLevelButton extends StatelessWidget {
LearnLevelButton({
Key ?key,
this.text = '',
this.width = 80.0,
this.height = 80.0,
this.borderRadius = 50.0,
required this.onTap,
}) : super(key: key);
final String text;
final VoidCallback onTap;
final double width;
final double height;
final double borderRadius;
#override
Widget build(BuildContext context) {
var gradient = LinearGradient(
begin: Alignment.topCenter, // new
end: Alignment.bottomCenter, // new
colors: [
//Color(0xff9cbbf6),
//Color(0xff9cbbf6),linkwell
Color(0xff7ba6f9),
Color(0xff7ba6f9),
],
);
return InkWell(
onTap: onTap,
child: Center(
child: Padding(
padding: const EdgeInsets.only(
top: 20.0,
bottom: 20.0,
left: 22.0,
right: 22.0,
),
child: Container(
padding: const EdgeInsets.all(3.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(borderRadius),
border: Border.all(
width: 0.3,
color: Colors.black38,
),
boxShadow: [
BoxShadow(
blurRadius: 10.0,
offset: Offset(5.0, 5.0),
color: Color.fromRGBO(0, 0, 0, 0.3),
),
],
gradient: gradient,
),
width: width,
height: height,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(borderRadius),
border: Border.all(
width: 0.3,
color: Colors.black26,
),
boxShadow: [
BoxShadow(
blurRadius: 1.0,
offset: Offset(1.0, 1.5),
color: Color.fromRGBO(0, 0, 0, 0.3),
),
],
gradient: gradient,
),
child: Center(
child: Text(
text,
style: TextStyle(
color: Colors.white,
fontSize: 20.0, fontWeight: FontWeight.bold,
),
),
),
),
),
),
),
);
}
}
Related
I have an image and text in a container. How do I write my code so the image will still retain its position in the middle of the container when the text expands and have two lines instead of one line. Here is my code and an image for context. I want the text to be able to grow upwards when it becomes two lines, just like it is in the image i uploaded. But i want the circle svg to retain its
position even if the text expands to two lines.
class CategoryCardWithSvg extends StatelessWidget {
final String svgimage;
final String title;
final Function press;
const CategoryCardWithSvg({
Key key,
this.svgimage,
this.title,
this.press,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
// padding: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Theme.of(context).cardColor,
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: Theme.of(context).shadowColor,
width: 0.5
),
boxShadow: [
BoxShadow(
offset: Offset(0.0, 10.0),
blurRadius: 2.0,
spreadRadius: 0.0,
color: Theme.of(context).shadowColor,
),
],
),
child: InkWell(
onTap: press,
child: Padding(
padding: const EdgeInsets.fromLTRB(10, 0, 10, 20),
child: Column(
children: <Widget>[
Spacer(),
SvgPicture.asset(
svgimage,
height: 60,
),
Spacer(),
Text(
title,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.headline6.copyWith(
fontSize: 15,
height: 1,
fontWeight: FontWeight.bold,
fontFamily: 'Cairo'),
)
],
),
),
),
);
}
}
you can use Expanded() widget to take same amount of space and distribute them equally between two widgets.
class CategoryCardWithSvg extends StatelessWidget {
final String svgimage;
final String title;
final Function press;
const CategoryCardWithSvg({
Key key,
this.svgimage,
this.title,
this.press,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
// padding: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Theme.of(context).cardColor,
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: Theme.of(context).shadowColor,
width: 0.5
),
boxShadow: [
BoxShadow(
offset: Offset(0.0, 10.0),
blurRadius: 2.0,
spreadRadius: 0.0,
color: Theme.of(context).shadowColor,
),
],
),
child: InkWell(
onTap: press,
child: Padding(
padding: const EdgeInsets.fromLTRB(10, 0, 10, 20),
child: Column(
children: <Widget>[
Expanded(child:
SvgPicture.asset(
svgimage,
height: 60,
),),
Expanded(child:
Center(child:
Text(
title,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.headline6.copyWith(
fontSize: 15,
height: 1,
fontWeight: FontWeight.bold,
fontFamily: 'Cairo'),
)))
],
),
),
),
);
}
}
See how the edges are faded and merged with the color of the button? How do you get something like that in flutter?
I have the button, don't know how to get that effect.
#override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(top: 30),
child: Column(
children: [
//OUTER CIRCLE (BUTTON INSIDE)
Container(
height: 275,
width: 275,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(150),
border: Border.all(
width: 3,
color: Colors.grey.withOpacity(0.6),
style: BorderStyle.solid,
),
),
child: Padding(
padding: const EdgeInsets.all(40),
//SHADOW (Button inside)
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: const Color(0xfffd194b).withOpacity(0.7),
spreadRadius: 10,
blurRadius: 40,
offset: const Offset(0, 25),
),
],
),
//BUTTON
child: RecordButtonWithText(
buttonText: _buttonText,
startStopRecording: startStopRecording,
),
),
),
),
],
),
);
class RecordButtonWithText extends StatelessWidget {
const RecordButtonWithText({
Key? key,
required String buttonText,
required this.startStopRecording,
}) : _buttonText = buttonText,
super(key: key);
final String _buttonText;
final VoidCallback startStopRecording;
#override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: () {
startStopRecording();
},
style: ElevatedButton.styleFrom(
elevation: 10,
padding: const EdgeInsets.all(30),
shape: const CircleBorder(),
shadowColor: const Color(0xfffd194b),
primary: const Color(0xfffd194b),
),
child: Text(
_buttonText.toUpperCase(),
style: const TextStyle(fontSize: 22, letterSpacing: 3),
),
);
}
}
If the you don't have to use the "ElevatedButton" widget, you can achieve what you want like that:
class RecordButtonWithText extends StatelessWidget {
final String _buttonText;
final VoidCallback startStopRecording;
final EdgeInsets padding;
final double size;
const RecordButtonWithText({
Key? key,
required String buttonText,
required this.startStopRecording,
this.padding = const EdgeInsets.all(30.0),
this.size = 275.0,
}) : _buttonText = buttonText,
super(key: key);
#override
Widget build(BuildContext context) {
return Container(
height: size,
width: size,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
width: 2,
color: Colors.grey.withOpacity(0.4),
style: BorderStyle.solid,
),
),
child: Padding(
padding: EdgeInsets.all(size * 0.145),
//SHADOW (Button inside)
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: const Color(0xfffd194b).withOpacity(0.7),
spreadRadius: size * 0.03,
blurRadius: size * 0.145,
offset: Offset(0, size * 0.09),
),
],
),
//BUTTON
child: InkWell(
borderRadius: BorderRadius.circular(size / 2),
onTap: () {
startStopRecording();
},
child: Container(
alignment: Alignment.center,
padding: EdgeInsets.all(size * 0.1),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.black,
gradient: RadialGradient(colors: [
const Color(0xfffd194b),
const Color(0xfffd194b),
const Color(0xfffd194b).withOpacity(0.5),
], stops: const [
0,
0.8,
1
]),
),
child: Text(
_buttonText.toUpperCase(),
style: TextStyle(
color: Colors.white,
fontSize: size * 0.08,
),
),
),
),
),
),
);
}
}
I am implementing an app using a plotter.
We are developing to move to the next page by pressing a button created using InkWell.
If you only have one button, no problem, but clicking one of the over 200 buttons will take you to the next "learning page". After that, my code is implemented so that I can do a "short learning", then come back, or move on to the next question.
Looking at other people's example code, I often see initialization or management with controllers.
Should I do that too? Below is the button code.
class Syllable extends StatelessWidget{
#override
Widget build(BuildContext context){
return Scaffold(
appBar: AppBar(
title: Text('', style: TextStyle(fontWeight: FontWeight.bold)),
centerTitle: true,
elevation: 0.0
),
body: Center(
child: ListView(
padding: const EdgeInsets.all(10.0),
children: <Widget>[
Align(
alignment: Alignment.centerLeft,
child: Text('',style: TextStyle(fontSize: 20.0,fontWeight: FontWeight.bold))
),
SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
LearnLevelButton(
text: '',
onTap: () async {
await Navigator.push(context, MaterialPageRoute(builder: (context){
return Home();
}));
},
),
Below is the code with only the buttons separated.
return InkWell(
onTap: onTap,
child: Center(
child: Padding(
padding: const EdgeInsets.only(
top: 20.0,
bottom: 20.0,
left: 22.0,
right: 22.0,
),
child: Container(
padding: const EdgeInsets.all(3.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(borderRadius),
border: Border.all(
width: 0.3,
color: Colors.black38,
),
boxShadow: [
BoxShadow(
blurRadius: 10.0,
offset: Offset(5.0, 5.0),
color: Color.fromRGBO(0, 0, 0, 0.3),
),
],
gradient: gradient,
),
width: width,
height: height,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(borderRadius),
border: Border.all(
width: 0.3,
color: Colors.black26,
),
boxShadow: [
BoxShadow(
blurRadius: 1.0,
offset: Offset(1.0, 1.5),
color: Color.fromRGBO(0, 0, 0, 0.3),
),
],
gradient: gradient,
),
child: Center(
child: Text(
text,
style: TextStyle(
color: Colors.white,
fontSize: 20.0, fontWeight: FontWeight.bold,
),
),
I'm trying to make glow around items in list. For this I use box-shadow in item's decoration. But it is appeared above other items, not as background. How to draw boxshadow behind sibling items as well.
class ShadowItem extends StatelessWidget {
const ShadowItem({required this.isWithGlow});
final bool isWithGlow;
#override
Widget build(BuildContext context) {
return Container(
height: 100,
decoration: BoxDecoration(
boxShadow: (isWithGlow)
? [
BoxShadow(
color: Colors.blue,
blurRadius: 42.0,
spreadRadius: 0.0,
offset: Offset(
0.0,
12.0,
),
),
]
: [],
),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(19),
),
),
);
}
}
you need to set margins between boxes so the shadow will not overflow on another widget.
I am using flutter_neumorphic: ^3.0.3 Package to solve your problem.
here is the code
import 'package:flutter/material.dart';
import 'package:flutter_neumorphic/flutter_neumorphic.dart';
class ShadowItem extends StatelessWidget {
const ShadowItem({required this.isWithGlow});
final bool isWithGlow;
#override
Widget build(BuildContext context) {
return Container(
height: 100,
margin: EdgeInsets.symmetric(vertical: 10, horizontal: 5),
child: Neumorphic(
style: isWithGlow
? NeumorphicStyle(
shadowDarkColor: Colors.blue,
shadowLightColor: Colors.blue,
depth: 10,
shape: NeumorphicShape.convex,
lightSource: LightSource.right)
: NeumorphicStyle(
depth: 2,
shape: NeumorphicShape.convex,
),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(19),
),
),
),
);
}
}
Your need is to show BoxShadow depends on the isWithGlow. so you can set grey shadow background instead of empty shadow [] and set margin for container, it will highlight your Container.
return Container(
height: 100,
margin: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
decoration: BoxDecoration(
boxShadow: (isWithGlow)
? [
BoxShadow(
color: Colors.blue,
blurRadius: 42.0,
spreadRadius: 0.0,
offset: Offset(
0.0,
12.0,
),
),
]
: [
BoxShadow(
color: Colors.grey[400]!,
blurRadius: 42.0,
spreadRadius: 0.0,
offset: Offset(
0.0,
12.0,
),
),
],
),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(19),
),
),
);
I am trying to create an Elevated button with gradient background, But it provides some parameters that do not fit it well, and May you know that after Flutter 2.0 version most of the Button classes have been deprecated such as Raised Button, Flat Button, ... etc
ElevatedButton(
child: Text('Woolha.com'),
style: ElevatedButton.styleFrom(
primary: Colors.teal,
onPrimary: Colors.white,
onSurface: Colors.grey,
),
onPressed: () {
print('Pressed');
},
)
Is there anyway to create ElevatedButton with gradient background?
Screenshot (Null safe)
Create this class (customizable)
class MyElevatedButton extends StatelessWidget {
final BorderRadiusGeometry? borderRadius;
final double? width;
final double height;
final Gradient gradient;
final VoidCallback? onPressed;
final Widget child;
const MyElevatedButton({
Key? key,
required this.onPressed,
required this.child,
this.borderRadius,
this.width,
this.height = 44.0,
this.gradient = const LinearGradient(colors: [Colors.cyan, Colors.indigo]),
}) : super(key: key);
#override
Widget build(BuildContext context) {
final borderRadius = this.borderRadius ?? BorderRadius.circular(0);
return Container(
width: width,
height: height,
decoration: BoxDecoration(
gradient: gradient,
borderRadius: borderRadius,
),
child: ElevatedButton(
onPressed: onPressed,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.transparent,
shadowColor: Colors.transparent,
shape: RoundedRectangleBorder(borderRadius: borderRadius),
),
child: child,
),
);
}
}
Usage:
Use it like a regular ElevatedButton:
MyElevatedButton(
width: double.infinity,
onPressed: () {},
borderRadius: BorderRadius.circular(20),
child: Text('SIGN IN'),
)
import 'package:flutter/material.dart';
class RoundedButtonWidget extends StatelessWidget {
final String buttonText;
final double width;
final Function onpressed;
RoundedButtonWidget({
required this.buttonText,
required this.width,
required this.onpressed,
});
#override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(10.0),
child: Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black26, offset: Offset(0, 4), blurRadius: 5.0)
],
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
stops: [0.0, 1.0],
colors: [
Colors.deepPurple.shade400,
Colors.deepPurple.shade200,
],
),
color: Colors.deepPurple.shade300,
borderRadius: BorderRadius.circular(20),
),
child: ElevatedButton(
style: ButtonStyle(
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
),
minimumSize: MaterialStateProperty.all(Size(width, 50)),
backgroundColor:
MaterialStateProperty.all(Colors.transparent),
// elevation: MaterialStateProperty.all(3),
shadowColor:
MaterialStateProperty.all(Colors.transparent),
),
onPressed: () {
onpressed();
},
child: Padding(
padding: const EdgeInsets.only(
top: 10,
bottom: 10,
),
child: Text(
buttonText,
style: TextStyle(
fontSize: 18,
// fontWeight: FontWeight.w700,
color: Colors.white,
),
),
),
),
),
);
}
}
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6.0),
gradient: LinearGradient(
begin: Alignment(-0.95, 0.0),
end: Alignment(1.0, 0.0),
colors: [const Color(0xff667eea), const Color(0xff64b6ff)],
stops: [0.0, 1.0],
),
),
child: ElevatedButton(
style: ElevatedButton.styleFrom(primary: Colors.transparent,
onSurface: Colors.transparent,
shadowColor: Colors.transparent,),
onPressed: (){},
child: Center(
child: Text(
'Log in',
style: TextStyle(
fontFamily: textFontFamilySegoeUI,
fontSize: 16,
color: const Color(0xffffffff),
letterSpacing: -0.3858822937011719,
),
textAlign: TextAlign.center,
),
),
),
),
Container(
width: 1120.w,
height: 180.h,
margin: EdgeInsets.fromLTRB(0, 10, 0, 10),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Color(0xFF0379C6), Color(0xFF1298EF)]),
borderRadius: BorderRadius.circular(25.r),
boxShadow: <BoxShadow>[
BoxShadow(
color: Color.fromRGBO(16, 142, 233, 0.57),
blurRadius: 13)
]),
child: ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(
Colors.transparent),
),
onPressed: () => setState(() {
// _launched = _makePhoneCall('tel:$_phone');
}),
child: Text(
'Submit',
style:
TextStyle(color: Colors.white, fontSize: 64.sp),
),
),
)
botao
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Priscila Dev'),
),
body: Center(
child: Container(
width: 300,
height: 100,
decoration: const ShapeDecoration(
shape: StadiumBorder(),
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Colors.blue, Colors.orange, Colors.green],
),
),
child: MaterialButton(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
shape: const StadiumBorder(),
child: const Text(
'ENCERRAR[enter image description here][1]',
style: TextStyle(color: Colors.white, fontSize: 20),
),
onPressed: () {
print('Hello!');
},
),
)),
);
}
Try this
Container(
padding: EdgeInsets.fromLTRB(10.0, 6.0, 10.0, 6.0),
decoration: BoxDecoration(
gradient:
LinearGradient(colors: [Color(0xff3b8594), Color(0xff59a6b6)]),
borderRadius: BorderRadius.circular(25.0)),
child: Text(
'View more',
style: TextStyle(color: Colors.white, fontSize: 16.0),
),
)
Result