How to make the design using widget in Flutter - 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,
)
],
),
),
);
}
}

Related

stack with Carousel causes the app to crash

when using the stack with carousel it work for a which but when navigating or scrolling the app suddenly freeze and crashes by showing the carousel package code. and i have also used listview biulder.
this code is just of carousel and stack
class Carousels extends StatelessWidget {
const Carousels({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Stack(
children: [
ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
),
child: Carousel(
autoplay: false,
dotSize: 4.0,
dotSpacing: 15.0,
dotColor: Colors.lightBlueAccent,
indicatorBgPadding: 5.0,
dotBgColor: Color.fromARGB(255, 100, 99, 100).withOpacity(0.5),
images: const [
AssetImage('assets/finallogo.png'),
AssetImage('assets/rr.png'),
],
),
),
Positioned(
top: 0,
right: 5,
child: Icon(
Icons.favorite,
color: Colors.red,
),
),
Positioned(
child: Icon(
Icons.star_rate_sharp,
color: Colors.white,
),
)
],
);
}
}
add Sizedbox like below
class Carousels extends StatelessWidget {
const Carousels({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Stack(
children: [
SizedBox(
height:300
ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
),
child: Carousel(
autoplay: false,
dotSize: 4.0,
dotSpacing: 15.0,
dotColor: Colors.lightBlueAccent,
indicatorBgPadding: 5.0,
dotBgColor: Color.fromARGB(255, 100, 99, 100).withOpacity(0.5),
images: const [
AssetImage('assets/finallogo.png'),
AssetImage('assets/rr.png'),
],
),
),
),
Positioned(
top: 0,
right: 5,
child: Icon(
Icons.favorite,
color: Colors.red,
),
),
Positioned(
child: Icon(
Icons.star_rate_sharp,
color: Colors.white,
),
)
],
);
}
}
You can use carousel_slider package: carousel_slider: ^4.2.1
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.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({super.key, required this.title});
final String title;
#override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
static List<String> categories = [
'Soft Drinks',
'Smoothies',
'Water',
];
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: CarouselSlider(
options: CarouselOptions(
aspectRatio: 1.5,
viewportFraction: 0.9,
enlargeCenterPage: true,
enlargeStrategy: CenterPageEnlargeStrategy.height,
autoPlay: true
),
items: categories
.map((category) => HeroCarouselCard(category: category))
.toList(),
),
);
}
}
class HeroCarouselCard extends StatelessWidget {
final String? category;
const HeroCarouselCard({Key? key, this.category})
: super(key: key);
#override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.symmetric(vertical: 20.0, horizontal: 5.0),
child: ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(5.0)),
child: Stack(
children: <Widget>[
Image.network(
'https://images.unsplash.com/photo-1631631480669-535cc43f2327?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8YmFja2dyb3VuZCUyMGltYWdlfGVufDB8fDB8fA%3D%3D&w=1000&q=80',
fit: BoxFit.cover,
width: 1000.0),
Positioned(
bottom: 0.0,
left: 0.0,
right: 0.0,
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [
Color.fromARGB(200, 0, 0, 0),
Color.fromARGB(0, 0, 0, 0)
],
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
),
),
padding: const EdgeInsets.symmetric(
vertical: 10.0, horizontal: 20.0),
child: Text(
category!,
style: TextStyle(
color: Colors.white
),
),
),
),
],
)),
);
}
}

Flutter : How to make button like this [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 months ago.
Improve this question
i want to make button like this
The background is of different colors and shapes
Text and icon
Here is a complete code for making one of the buttons. you can play with bordet radius to build other buttons as well.
enter code here import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
final Overlay overlay = const Overlay();
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: '3D Button',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const Home(),
);
}
}
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
#override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: colors[50],
appBar: AppBar(
title: const Center(
child: Text("3D Button"),
),
),
// body: const ClickyButtonPage(),
body: Center(child: const Custom3DButton()),
);
}
}
const MaterialColor colors = Colors.blue;
const MaterialColor colors2 = Colors.grey;
class Custom3DButton extends StatelessWidget {
const Custom3DButton({
Key? key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
double _width = 220;
double _height = 65;
double _sideWidth = 180;
var _borderRadius = const Radius.circular(50);
return Container(
width: _width,
height: 70.0,
child: GestureDetector(
child: Stack(children: <Widget>[
Positioned(
bottom: 0,
child: Container(
width: _width,
height: _height,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(_borderRadius),
color: colors[800],
),
),
),
Positioned(
left: 0,
bottom: 0,
child: Container(
width: _sideWidth * 5 / 6,
height: _height,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: _borderRadius, topLeft: _borderRadius),
color: colors2[400],
),
),
),
Container(
width: _width,
height: _height,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(_borderRadius),
color: Colors.blue,
),
),
Positioned(
left: 0,
child: Container(
width: _sideWidth,
height: _height,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(_borderRadius),
color: Colors.white,
),
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.menu_rounded,
size: 34,
color: Colors.blue,
),
const SizedBox(
width: 10,
),
Text(
'SETTING',
style: TextStyle(color: colors[600], fontSize: 24),
),
],
),
),
),
),
]),
),
);
}
}
Here is the screen shot for this example;

Custom red button with red border in 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),
),
),
),
),
);
}
}

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