Custom red button with red border in flutter - flutter

I wanted to create a button like the picture. I am a beginner in flutter so I don't know how to start. Let me add that I would like to add a red glow effect to the button.

Try below code
OutlinedButton(
onPressed: () {
print('button pressed');
//write your onPressed function here
},
child: Text(
'TEXT',
style: TextStyle(
fontSize: 40,
),
),
style: OutlinedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
20,
),
),
primary: Colors.red,
backgroundColor: Colors.red.shade100,
fixedSize: Size(200, 100),
side: BorderSide(
width: 10.0,
color: Colors.red,
),
),
),
Result screen->

You can use InkWell with custom style,
here is an example
InkWell(
onTap: (){
//YOUR FUNCTION
},
radius: 16.0,
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 8.0,
),
decoration: BoxDecoration(
border: Border.all(color: Colors.red, width: 2),
borderRadius: BorderRadius.circular(12),
),
child: Text('Text', style: TextStyle(color: Colors.red),),
),
),
this will give you the you the output:

This should be a little more flexible, allowing the customization of color, shadow, light vs. dark backgrounds plus, of course, text.
Also, this doesn't use containers. You can't make containers constant, so many of us try to avoid them now:
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
#override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: const Center(
child: CustomButton(
// Places a black or white backing behind the inside, translucent color.
backgroundIsDark: true,
// The color of everything.
color: Colors.red,
// The shadow *outside* the border.
shadowSize: 2.0,
text: 'Test',
),
),
);
}
}
class CustomButton extends StatelessWidget {
const CustomButton({
Key? key,
required this.backgroundIsDark,
required this.shadowSize,
required this.text,
required this.color,
}) : super(key: key);
final double shadowSize;
final String text;
final Color color;
final bool backgroundIsDark;
#override
Widget build(BuildContext context) {
return InkWell(
onTap: () {
// TODO Implement Me.
},
radius: 16.0,
child: DecoratedBox(
decoration: BoxDecoration(
color: backgroundIsDark ? Colors.black : Colors.white,
borderRadius: BorderRadius.circular(8),
),
child: DecoratedBox(
decoration: BoxDecoration(
border: Border.all(
color: color,
width: 4,
),
borderRadius: BorderRadius.circular(8),
boxShadow: [
BoxShadow(
color: color.withOpacity(0.4),
blurRadius: shadowSize,
spreadRadius: shadowSize,
offset: const Offset(0.0, 0.0),
),
],
),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 8.0,
),
child: Text(
text,
style: TextStyle(color: color),
),
),
),
),
);
}
}

Related

How to make the design using widget in Flutter

If we click on the "Is there an Bitcode Method iOS App?" then the answer should be shown. So I have tried using card in flutter but it's not working. So you can tell me this how to make it?
enter image description here
This may help. If you have any requirements or confusion, please consider commenting.
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
#override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool showAnswer = false;
String answer =
"At this point, there is no Mobile app on ios or Android. It is available on the trading website and can be accessed via the web on a mobile or laptop.";
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
GestureDetector(
onTap: () {
setState(() {
showAnswer = true;
});
},
child: Container(
height: MediaQuery.of(context).size.height * 0.1,
width: MediaQuery.of(context).size.width,
decoration: const BoxDecoration(
color: Colors.red,
gradient: LinearGradient(
transform: GradientRotation(1.2),
colors: [Colors.redAccent, Colors.blueAccent],
),
borderRadius: BorderRadius.only(
topRight: Radius.circular(20),
topLeft: Radius.circular(20),
),
),
child: const Center(
child: Text(
'Is there an Bitcode Method iOS App?',
style: TextStyle(
color: Colors.black54,
fontWeight: FontWeight.w600,
fontSize: 16,
),
),
),
),
),
(showAnswer)
? Container(
height: MediaQuery.of(context).size.height * 0.2,
width: MediaQuery.of(context).size.width,
padding: const EdgeInsets.symmetric(horizontal: 8),
decoration: BoxDecoration(
color: Colors.grey.withOpacity(0.3),
borderRadius: const BorderRadius.only(
bottomRight: Radius.circular(20),
bottomLeft: Radius.circular(20),
),
),
child: Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
answer,
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.black54,
fontWeight: FontWeight.w600,
fontSize: 16,
height: 1.5,
),
),
),
),
)
: SizedBox(
height: MediaQuery.of(context).size.height * 0.2,
)
],
),
),
);
}
}

flutter problem: how to remove or hide endDrawer from appBar

The first drawer should be on the appBar and the second one should be next to the testfield.
Here, when I used the second drawer next to the testfield, the right side drawer icon appeared in the appBar along with it.
I only want the left side drawer in the appBar and the second drawer next to the testfield in the right side.
this is my code
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
#override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
ApiManager apiManager = ApiManager();
#override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'CWC(Khushi)',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: DemoScreen(),
// home:VideoComponentPurple(),
);
}
}
final GlobalKey<ScaffoldState> _scaffoldkey = new GlobalKey();
class DemoScreen extends StatelessWidget {
const DemoScreen({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldkey,
endDrawer: Drawer(child: Drawer2()),
backgroundColor: Colors.white,
resizeToAvoidBottomInset: false,
appBar: AppBar(
leading: Builder(
builder: (BuildContext context) {
return IconButton(
icon: Icon(Icons.menu),
onPressed: () {
Scaffold.of(context).openDrawer();
},
tooltip: '',
);
},
),
automaticallyImplyLeading: true,
elevation: 0.5,
),
drawer: Drawer(
child: Drawer1(),
),
body: Padding(
padding: const EdgeInsets.only(top: 28.0),
child: Stack(
children: [
Container(
// padding: EdgeInsets.symmetric(vertical: 8),
height: 55,
child: TextField(
textAlignVertical: TextAlignVertical.center,
decoration: InputDecoration(
// contentPadding: EdgeInsets.only(top: 10.0,bottom: 0,left: 10,right: 10),
border: OutlineInputBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
bottomLeft: Radius.circular(10),
),
borderSide: BorderSide.none,
),
filled: true,
fillColor: const Color(0xFFFFFFFF),
hintText: 'Search for Wellness Tips & Tricks',
prefixIcon: const Icon(
Icons.search_outlined,
color: Color(0xFF444444),
),
),
),
),
Positioned(
right: 0,
child: Container(
decoration: BoxDecoration(
border: Border(
left: BorderSide(
color: Colors.grey,
width: 2.0,
),
)),
child: InkWell(
onTap: () {
_scaffoldkey.currentState!.openEndDrawer();
},
child: Container(
padding: EdgeInsets.all(15),
decoration: BoxDecoration(
color: Color(0xFFFFFFFF),
borderRadius: BorderRadius.only(
topRight: Radius.circular(10),
bottomRight: Radius.circular(10),
),
),
height: 55,
width: 60,
child: Image.asset(
'assets/right_side_hamburger.png',
height: 24,
width: 24,
),
),
),
),
),
],
),
),
);
}
}
class Drawer2 extends StatelessWidget {
const Drawer2({
Key? key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Drawer(
// Custom widget must be return Drawer
child: ListTile(
//Implement any design on child property
title: Text("Demo tile2"),
),
);
}
}
class Drawer1 extends StatelessWidget {
const Drawer1({
Key? key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Drawer(
// Custom widget must be return Drawer
child: ListTile(
//Implement any design on child property
title: Text("Demo tile1"),
),
);
}
}
I got the answer of this question.
answer is -->
AppBar(
automaticallyImplyLeading: false, // this will hide Drawer hamburger icon
actions: <Widget>[Container()], // this will hide endDrawer hamburger icon
... // other props
),

Stack with circular progress bar and elevated button in flutter

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

How to stop positioned text objects from moving inside Stack as text changes across devices?

Objective: I want a TextButton to be bisected by a Container in a Stack.
Problem: The size of the TextButton changes across devices, causing an unwanted offset. See the first photo.
Below is a minimum reproducible example in which I use a static integer offset to position the TextButton. I also attempted to specify the TextButton's parent Container's width and height in an attempt to ensure my positional offset was the same each time, but overconstraining the TextButton caused odd reactions like this:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: '):',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: '):'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool buttonToggled = false;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Padding(
padding: EdgeInsets.fromLTRB(0, 30, 0, 0),
child: Stack(
clipBehavior: Clip.hardEdge,
alignment: AlignmentDirectional.center,
children: <Widget>[
Container(
//outline
height: 135,
margin: EdgeInsets.fromLTRB(20, 20, 20, 20),
decoration: BoxDecoration(
border: Border.all(color: Colors.purpleAccent, width: 1),
borderRadius: BorderRadius.circular(5),
shape: BoxShape.rectangle,
color: Colors.green,
),
),
Positioned(
left: 40,
top: 3,
child: Container(
margin: EdgeInsets.fromLTRB(10, 0, 0, 0),
padding: EdgeInsets.fromLTRB(7, 0, 7, 0),
height: 30,
color: Colors.blue,
child: Center(
child: TextButton(
child: Text(
buttonToggled ? '+ End Date and Time ' : '— End Date and Time',
textAlign: TextAlign.start, //aligment
style: TextStyle(color: Colors.white),
),
onPressed: () {
setState(() {
buttonToggled = !buttonToggled;
});
},
)))),
],
),
));
}
}
if you setup same size, inset, margin, it should not be different in different device.
have a try with TextStyle(color: Colors.white, inherit: false)

How to make this custom RangeSlider in Flutter?

I want to make a custom Range slider that looks like this:
However, I tried but my RangeSlider looks like:
My code:
data: SliderTheme.of(context).copyWith(
trackShape: RectangularSliderTrackShape(),
trackHeight: 2.0,
thumbShape:
RoundSliderThumbShape(enabledThumbRadius: 9.0),
overlayShape:
RoundSliderOverlayShape(overlayRadius: 18.0),
valueIndicatorShape: RoundSliderOverlayShape(),
valueIndicatorColor: Color(0xffF5F5F5),
valueIndicatorTextStyle:
TextStyle(color: Color(0xff7E3338), fontSize: 14.0),
rangeThumbShape: RoundRangeSliderThumbShape(),
rangeValueIndicatorShape:
PaddleRangeSliderValueIndicatorShape(),
),
child: RangeSlider(
values: selectedRange,
min: 0.0,
max: 50000.0,
semanticFormatterCallback: (RangeValues rangeValues) {
return '${rangeValues.start.round()} - ${rangeValues.end.round()} dollars';
},
//added talk back feature for android
labels: RangeLabels(
'${selectedRange.start}', '${selectedRange.end}'),
activeColor: Color(0xff7E3338),
inactiveColor: Color(0xffD7D8DD),
onChanged: (RangeValues newRange) {
setState(() => selectedRange = newRange);
},
),
),
What can I do different in the code that will give me the expected output?
Please check this plugin where you can customize the slider as you want i have created the sample from the above-mentioned image.
But you can customize it as per your needs.
Plugin :https://pub.dev/packages/flutter_xlider
Check the code below :
import 'package:flutter/material.dart';
import 'package:flutter_xlider/flutter_xlider.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
//
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
double _lowerValue = 50;
double _upperValue = 180;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 50, left: 20, right: 20),
alignment: Alignment.centerLeft,
child: FlutterSlider(
values: [1000, 15000],
rangeSlider: true,
//rtl: true,
ignoreSteps: [
FlutterSliderIgnoreSteps(from: 8000, to: 12000),
FlutterSliderIgnoreSteps(from: 18000, to: 22000),
],
max: 25000,
min: 0,
step: FlutterSliderStep(step: 100),
jump: true,
trackBar: FlutterSliderTrackBar(
activeTrackBarHeight: 2,
activeTrackBar: BoxDecoration(color: Colors.brown),
),
tooltip: FlutterSliderTooltip(
textStyle: TextStyle(fontSize: 17, color: Colors.lightBlue),
),
handler: FlutterSliderHandler(
decoration: BoxDecoration(),
child: Container(
decoration: BoxDecoration(
color: Colors.brown,
borderRadius: BorderRadius.circular(25)),
padding: EdgeInsets.all(10),
child: Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(25)),
),
),
),
rightHandler: FlutterSliderHandler(
decoration: BoxDecoration(),
child: Container(
decoration: BoxDecoration(
color: Colors.brown,
borderRadius: BorderRadius.circular(25)),
padding: EdgeInsets.all(10),
child: Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(25)),
),
),
),
disabled: false,
onDragging: (handlerIndex, lowerValue, upperValue) {
_lowerValue = lowerValue;
_upperValue = upperValue;
setState(() {});
},
)),
],
),
),
);
}
}
This is the image output
you can change the colors accordingly.
Let me know if it works.
Check out this code for tooltip:
tooltip: FlutterSliderTooltip(
disableAnimation: true,
alwaysShowTooltip: true,
textStyle: TextStyle(fontSize: 17, color: Colors.lightBlue),
),
Wrap your Range Slider in Slider theme and customize your slider data theme according to your need. use the bellow image for reference and name of all the properties of slider.