Design this Button in Flutter? - flutter

How can I design this kind of button in flutter?

You can use elevated button with transparent color and white border and shadow

Try below code hope its help to you.
Container(
padding: EdgeInsets.all(10),
height: 80,
width: 200,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(80),
),
child: InkWell(
onTap: () {
//Write your onPressed function here
print('Button Pressed');
},
child: Card(
color: Colors.teal[100],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(70),
),
child: Center(
child: Text(
'Sign In',
style: TextStyle(
color: Colors.white,
fontSize: 20,
),
),
),
),
),
),
Your result screen->

Here you go, adjust to your needs:
Container(
color: Color.fromRGBO(133,208,212,1),
padding: const EdgeInsets.all(15),
child: Container(
padding: EdgeInsets.all(8),
decoration: ShapeDecoration(
shape: StadiumBorder(),
color: Color.fromRGBO(133,208,212,1),
shadows: <BoxShadow>[
BoxShadow(
color: Colors.white,
spreadRadius: 8,
blurRadius: 3,
offset: Offset(0, 0),
),
BoxShadow(
color: Colors.grey.shade300,
spreadRadius: 3,
blurRadius: 3,
offset: Offset(5, 2),
),
],
),
child: Text(
'Sign in',
style: TextStyle(color: Colors.white),
),
),
),
The first Container is there just to highlight it's child, so it's not important

Related

I want button like a this. but I can not set border or width

I want like a this button
but I can not make it
Please tell me that how to make about
I did tryed code
ElevatedButton(
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30)),
backgroundColor: Colors.lightBlue[400],
side:BorderSide(width: 2, color: Colors.black)),
result
Container(
height: 50,
width: 200,
decoration: BoxDecoration(
color: Color(0xff92fcd1),
border: Border.all(color: Colors.black),
borderRadius: BorderRadius.circular(100),
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.black,
offset: Offset(2.5, 2.5),
spreadRadius: 0.1
)
],
),
child: Center(
child: Text('LOGIN'),
)
),
Container(
width: 100,
height: 30,
decoration: BoxDecoration(
border: Border.all(
width: 1,
color: Colors.black,
),
color: const Color(0xff93fbd1),
borderRadius: BorderRadius.circular(15),
boxShadow: const [
BoxShadow(
color: Colors.black,
blurRadius: 1,
offset: Offset(1, 2), // Shadow position
),
],
),
child: TextButton(
child: const Text(
'LOGIN',
style: TextStyle(
fontStyle: FontStyle.italic,
color: Colors.black,
fontWeight: FontWeight.bold),
),
onPressed: () {
// TODO: button onTap events
},
),
);
I usually create the buttons myself, you can add more features
Card(
elevation: 8,
color: Color.fromARGB(255, 132, 255, 199),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
side: BorderSide(width: 2)),
child: InkWell(
borderRadius: BorderRadius.circular(15),
onTap: () {},
child: Container(
padding:
EdgeInsets.only(left: 20, right: 20, top: 10, bottom: 10),
child: Text(
"LOGIN",
style: TextStyle(fontWeight: FontWeight.w700),
))),
)
I create this button with complete all of your need, having the box shadow, italic login, responsive design base on device width.
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {},
child: Container(
width: MediaQuery.of(context).size.width * 0.4,
height: MediaQuery.of(context).size.height * 0.05,
decoration: BoxDecoration(
color: const Color(0xff92fcd1),
border: Border.all(color: Colors.black),
borderRadius: BorderRadius.circular(100),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.7),
spreadRadius: 2,
offset:
const Offset(2, 2), // changes position of shadow
),
],
),
child: const Center(
child: Text("Login",
style: TextStyle(
fontStyle: FontStyle.italic, color: Colors.black)),
),
),
)
and here is the result

Even though I add an element to the listview, it is not refreshed

I'm trying to make an app that lists bluetooth devices. I am using flutter_blue_plus in my project.
I scan as follows and add the found devices to the list.
FloatingActionButton(
backgroundColor: bleColor,
child: Icon(
Icons.search,
color: Colors.white,
),
onPressed: () {
setState(() {
flutterBlue.startScan(
timeout: const Duration(seconds: 4));
flutterBlue.scanResults.listen((results) {
for (ScanResult r in results) {
deviceList.add(r);
}
});
});
},
)
List define
late List<ScanResult> deviceList = [];
I make the data added to the list transform into an image like the one below. I can't view the list even though the element is added to the list. I did not understand the source of the problem. There is no error anywhere in the program.
Expanded(
child: Container(
child: Padding(
padding: const EdgeInsets.only(
left: 16, right: 16, top: 8, bottom: 8),
child: ListView(
children: deviceList
.map((result) => Container(
margin: EdgeInsets.symmetric(
vertical: 8, horizontal: 16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(20)),
boxShadow: <BoxShadow>[
BoxShadow(
offset: Offset(4, 4),
blurRadius: 10,
color: Colors.grey
.withOpacity(.2),
),
BoxShadow(
offset: Offset(-3, 0),
blurRadius: 15,
color: Colors.grey
.withOpacity(.1),
)
],
),
child: Container(
padding: EdgeInsets.symmetric(
horizontal: 18, vertical: 8),
child: ListTile(
contentPadding:
EdgeInsets.all(0),
leading: ClipRRect(
borderRadius:
BorderRadius.all(
Radius.circular(
13)),
child: Container(
height: 35,
width: 35,
decoration: BoxDecoration(
borderRadius:
BorderRadius
.circular(15),
),
child:
Icon(Icons.bluetooth),
),
),
title: result.device.name ==
''
? Text('Unknown',
style: TextStyle(
fontWeight:
FontWeight
.bold))
: Text(result.device.name,
style: TextStyle(
fontWeight:
FontWeight
.bold)),
subtitle: Text(
result.device.id.toString(),
style: TextStyle(
fontWeight:
FontWeight.bold),
),
trailing: TextButton(
child: Text('Connect'),
onPressed: () {},
)),
),
))
.toList(),
),
),
),
)
Can you help me please ?
Try to do setState after getting results..
FloatingActionButton(
backgroundColor: bleColor,
child: Icon(
Icons.search,
color: Colors.white,
),
onPressed: ()
flutterBlue.startScan(
timeout: const Duration(seconds: 4));
flutterBlue.scanResults.listen((results) {
setState(() { // use here
for (ScanResult r in results) {
deviceList.add(r);
}
});
});
},
)

When creating a button that goes to the next page, do I need to initialize it?

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,
),
),

Flutter how to add box-shadow or drop-shadow onto text input field?

I don't think this is possible but thought I would ask and see if anyone has a solution for this I want to add box-shadow or drop-shadow onto the text input field but I don't want it to get messed up when using error text or hint text. Attached screenshot showing the issue. I tried Material, Physical Mode, Container still getts messed I don't think there is a way as error text is inside the input widget, and once it shows the height grows.
Maybe You Could Try This One
Padding(
padding: const EdgeInsets.only(
left: 16, right: 16, bottom: 16, top: 8),
child: Container(
height: 48,
decoration: BoxDecoration(
color: Colors.red.shade300,
borderRadius: const BorderRadius.all(Radius.circular(24.0)),
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.grey.withOpacity(0.6),
blurRadius: 8,
offset: const Offset(4, 4),
),
],
),
child: Material(
color: Colors.transparent,
child: InkWell(
borderRadius: const BorderRadius.all(Radius.circular(24.0)),
highlightColor: Colors.transparent,
onTap: () {
yourfunction();
},
child: Center(
child: loadingButton
? SizedBox(
height: 30.0,
width: 30.0,
child: CircularProgressIndicator(
valueColor:
AlwaysStoppedAnimation(Colors.white),
),
)
: Text(
'Apply',
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 18,
color: Colors.white),
),
),
),
),
),
)
This is probably not the most elegant way, but you could tinker with something like this:
Stack(
children: [
Container(
height: 40.0,
width: 200.0,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
spreadRadius: 4,
blurRadius: 12,
offset: Offset(0, 8),
),
],
),
),
Container(
width: 200.0,
child: TextFormField(
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: 'Name',
errorText: 'Field cannot be empty',
),
),
),
],
);

Container BoxShadow not working with InkWell Material

I want to use Inkwell splash for this container.
Without Inkwell widget.
Expanded(
child: Container(
padding: EdgeInsets.all(12.0),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black26,
offset: Offset(0, 1),
blurRadius: 2.0)
],
borderRadius: BorderRadius.circular(12.0),
color: _size.white,
),
child: Column(
children: <Widget>[
Icon(
Icons.book,
color: _size.green,
),
SizedBox(
height: 4.0,
),
Text('Instant'),
],
),
),
),
But when i add inkwell and material widget it looks like
Expanded(
child: Material(
color: _size.white,
child: InkWell(
borderRadius: BorderRadius.circular(12.0),
onTap: () {},
splashColor: Colors.red,
splashFactory: InkSplash.splashFactory,
child: Container(
padding: EdgeInsets.all(12.0),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black26,
offset: Offset(0, 1),
blurRadius: 2.0)
],
borderRadius: BorderRadius.circular(12.0),
//color: _size.white,
),
child: Column(
children: <Widget>[
Icon(
Icons.book,
color: _size.green,
),
SizedBox(
height: 4.0,
),
Text('Instant'),
],
),
),
),
),
),
I removed boxshadow from container and added elevation for material and i got like this.
Expanded(
child: Material(
borderRadius: BorderRadius.circular(12.0),
elevation: 2.0,
color: _size.white,
child: InkWell(
borderRadius: BorderRadius.circular(12.0),
onTap: () {},
splashColor: Colors.red,
splashFactory: InkSplash.splashFactory,
child: Container(
padding: EdgeInsets.all(12.0),
decoration: BoxDecoration(
/*boxShadow: [
BoxShadow(
color: Colors.black26,
offset: Offset(0, 1),
blurRadius: 2.0)
],*/
borderRadius: BorderRadius.circular(12.0),
//color: _size.white,
),
child: Column(
children: <Widget>[
Icon(
Icons.book,
color: _size.green,
),
SizedBox(
height: 4.0,
),
Text('Instant'),
],
),
),
),
),
)
finally it similar to what i need but in top of the container that coming shadow or elevation is not like needed one.
Anyone how to get shadow like first image.
I solved by wrapping Material widget by another Container widget and i give box shadow to this container, and i resolved my problem.
Expanded(
child: Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black26,
offset: Offset(0, 1),
blurRadius: 2.0)
],
borderRadius: BorderRadius.circular(12.0),
color: _size.white,
),
child: Material(
borderRadius: BorderRadius.circular(12.0),
color: _size.white,
child: InkWell(
borderRadius: BorderRadius.circular(12.0),
onTap: () {},
splashColor: Colors.red,
splashFactory: InkSplash.splashFactory,
child: Container(
padding: EdgeInsets.all(12.0),
child: Column(
children: <Widget>[
Icon(
Icons.book,
color: _size.green,
),
SizedBox(
height: 4.0,
),
Text('Instant'),
],
),
),
),
),
),
),
Try this way using Card
Card(
elevation: 10.0,
child: Container(
padding: EdgeInsets.all(12.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.0),
),
child: Column(
children: <Widget>[
Icon(
Icons.book,
color: Colors.blue,
),
SizedBox(
height: 4.0,
),
Text('Instant'),
],
),
))
OUTPUT
Use Ink instead of Material when using Inkwell, then give the internal Container a color (it's transparent by default, just showing the shadow underneath):
Expanded(
child: Ink(
color: _size.white,
child: InkWell(
...
child: Container(
decoration: BoxDecoration(
color: Color.white,
...
),
...
),
),
),
),