I have a button in on clicking the button I show the progress Indicator, what I need is animate the button in progress indicator something like the transformation from button to progress indicator
showProgressIndicator ? FloatingActionButton(
elevation: 5.0,
child: CircularProgressIndicator(),
backgroundColor: Colors.white,
onPressed: (){}
) : Padding(
padding: const EdgeInsets.only(left: 20.0, right: 20.0),
child: ButtonTheme(
height: 40.0,
child: RaisedButton(
color: Color(0xFFFD6600),
child: Text("Login", style: TextStyle(fontSize: 16.0),),
textColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
onPressed: () {
setState(() {
showProgressIndicator = true;
});
},
),
),
),
Maybe use AnimatedContainer like this:
InkWell(
borderRadius: BorderRadius.circular(20),
onTap: isLoading ? null : () => buttonPressed(),
child: AnimatedContainer(
curve: Curves.easeInOutCubic,
padding: (isLoading)
? EdgeInsets.fromLTRB(10, 10, 10, 10)
: EdgeInsets.fromLTRB(40, 10, 40, 10),
decoration: BoxDecoration(
color: Colors.blueAccent,
borderRadius: BorderRadius.circular(20),
),
duration: Duration(milliseconds: 400),
child: isLoading
? CircularProgressIndicator(
valueColor: new AlwaysStoppedAnimation<Color>(
Colors.white),
)
: Text(
"LOGIN",
style: TextStyle(
fontSize: 18,
color: Colors.white,
),
)),
),
You can use something like this, use a variable to keep button status.
return _isLoading
? Center(
child: CircularProgressIndicator(),
)
: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30)),
color: .green,
child: Text(
'Continue',
style: TextStyle(
fontSize: 17.0,
fontFamily: 'SFUIDisplay-Bold',
color: .white),
),
onPressed: () => _submitForm(),
);
Related
I would like that highlightColor also take the Text and not only the background of the Material
Container(
height: 75.0,
width: double.infinity,
margin: const EdgeInsets.symmetric(horizontal: 8.0),
child: Material(
color: Colors.grey.shade400,
borderRadius: BorderRadius.circular(4.0),
child: Stack(
children: <Widget>[
InkWell(
onTap: (){},
highlightColor: Colors.white.withOpacity(0.7),
splashColor: Colors.transparent,
customBorder: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4.0))),
const Center(
child: Text(
'Ceci est un texte',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
color: Colors.black
)
)
)
]
)
)
)
If you have a solution!
remove Stack widget and assign the Text widget as a child of InkWell.
Container(
height: 75.0,
width: double.infinity,
margin: const EdgeInsets.symmetric(horizontal: 8.0),
child: Material(
color: Colors.grey.shade400,
borderRadius: BorderRadius.circular(4.0),
child: InkWell(
onTap: () {},
highlightColor: Colors.green,
splashColor: Colors.transparent,
customBorder:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(4.0)),
child: const Center(
child: Text(
'Ceci est un texte',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
color: Colors.black,
),
),
),
),
),
)
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);
}
});
});
},
)
How do you create this button in this way? Need for my academic work. Please help me!!
enter image description here
ElevatedButton(
onPressed: () {
},
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: green,
shadowColor: green,
elevation: 3,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(32.0)),
minimumSize: const Size(100, 50),
),
child: const Padding(
padding: EdgeInsets.all(4.0),
child: Text(
"Arabic",
style: forteenWhite,
),
)),
Try this :
Container(
width: 300,
height: 60,
color: const Color(0xFF9c1f5d),
padding: EdgeInsets.all(10),
child:
ElevatedButton(
onPressed: () {},
child: const Text(
'Register your account today !',
style: TextStyle(
color: Colors.black
)
),
style: ElevatedButton.styleFrom(
primary: const Color(0xFFcc4e8c),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
),
),
),
Container(
padding: Padding.Edgeall(10.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: Colors.white,
),
height: 55,
child: Text("This is button")
),
And to use onClick wrap the Text or container with InkWell.
I am new to flutter. I have created two raised buttons. Both are created as widgets which are then being called in the main Scaffold widget. I want them to overlap with each other. I am trying the stack widget but then one button goes missing. I have also tried padding and positioning but nothing works. I do not want to use toggle buttons as those are just placed next to each other and are not overlapped.
Code
Widget business(context, setState) {
return
Padding(
padding: const EdgeInsets.only(left: 12.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(25.0),
child: SizedBox(
height: 60,
width: 60,
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25.0),
side: BorderSide(color: button2 ? primaryColor : Colors.white)
),
color: button1 ? primaryColor : Colors.white,
onPressed: () {
setState(() {
button1 = true;
button2 = false;
});
Fluttertoast.showToast(
msg:
"Business",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 4,
backgroundColor: primaryColor,
textColor: Colors.white,
fontSize: 16.0,
);
},
child: Icon(
MyFlutterApp.office,
color: button1 ? Colors.white : Colors.black,
),
),
),
),
);
}
else {
return Container();
}
Widget personal(context, setState) {
return
Padding(
padding: const EdgeInsets.only(left: 12.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(25.0),
child: SizedBox(
height: 60,
width: 60,
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25.0),
side: BorderSide(color: button1 ? primaryColor : Colors.white)
),
color: button2 ? primaryColor : Colors.white,
onPressed: () {
setState(() {
button1 = false;
button2 = true;
});
Fluttertoast.showToast(
msg:
"Personal",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 4,
backgroundColor: primaryColor,
textColor: Colors.white,
fontSize: 16.0,
);
},
child: Icon(
MyFlutterApp.personal,
color: button2 ? Colors.white : Colors.black,
),
),
),
),
);
}
else {
return Container();
}
Based on Flutter Oficial Documentation, you can use the Stack widget to achieve this effect. Here is a quick tutorial about this widget.
Using RaisedButton, always remember to remove the elevation from the upper buttons, to not cause a black overlay impression.
Here is a example:
Stack(
children: <Widget>[
RaisedButton(
onPressed: () => {},
color: Colors.red,
child: Text('First'),
),
RaisedButton(
onPressed: () => {},
color: Colors.transparent,
elevation: 0,
child: Text('Second'),
),
],
)
Here is the result.
I have minimal reproduction code of stack in flutter which I can give you
Stack(
children: [
Icon(
Icons.shopping_cart,
),
Positioned(
right: 0,
top: 0,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.red,
),
child: Padding(
padding: const EdgeInsets.all(2),
child: Text(
_bookModel.conutCart.toString(),
style: TextStyle(
color: Colors.white,
fontSize: 8.0,
),
),
),
),
),
],
),
I'm trying set rounded border to my MaterialButton, to do it I'm setting a RoundedRectangleBorder to shape attribute's MaterialButton, the problem is that it's not have effect.
Code:
Widget _showNeedHelpButton() {
return new Padding(
padding: EdgeInsets.fromLTRB(0.0, 5.0, 0.0, 0.0),
child: new MaterialButton(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(20.0))),
elevation: 5.0,
minWidth: 200.0,
height: 35,
color: Color(0xFF801E48),
child: new Text('Preciso de ajuda',
style: new TextStyle(fontSize: 16.0, color: Colors.white)),
onPressed: () {
setState(() {
_isNeedHelp = true;
});
},
),
);
}
Result:
If you need to use MaterialButton() - You need to Warp the button with Material Widget, to get the desired behavior.
Widget _showNeedHelpButton() {
return Padding(
padding: EdgeInsets.fromLTRB(0.0, 5.0, 0.0, 0.0),
child: Material( //Wrap with Material
shape: RoundedRectangleBorder(borderRadius:BorderRadius.circular(22.0) ),
elevation: 18.0,
color: Color(0xFF801E48),
clipBehavior: Clip.antiAlias, // Add This
child: MaterialButton(
minWidth: 200.0,
height: 35,
color: Color(0xFF801E48),
child: new Text('Preciso de ajuda',
style: new TextStyle(fontSize: 16.0, color: Colors.white)),
onPressed: () {
// setState(() {
// _isNeedHelp = true;
// });
},
),
),
);
}
Output:
UPDATE:
minWidth: 200.0,
height: 95,
MaterialButton(
child: Text('My Button'),
height: 40,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
)
RoundedRectangleBorder
will help you https://api.flutter.dev/flutter/painting/RoundedRectangleBorder-class.html
Have you tried wrapping it within a ClipRRect() ?
ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(20.0)),
child: MaterialButton(...),
),
You can find the documentation here: ClipRRect()
You should set the shape for MaterialButton and borderRadius for Material to make it round even when animation tab:
Material(
elevation: 10.0,
borderRadius: BorderRadius.circular(30.0),//12
color: Colors.transparent,//Colors.cyan.withOpacity(0.5),
child: MaterialButton(
minWidth: MediaQuery.of(context).size.width,
color: Colors.cyan.withOpacity(0.7),
shape: RoundedRectangleBorder(borderRadius:BorderRadius.circular(30.0) ),
splashColor: Colors.cyan,
onPressed: () async {},
child: Text('Login',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18.0,
color: Colors.black,
fontWeight: FontWeight.w400,
//fontFamily: lang.font
)),
),
);