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,
),
)),
),
),
),
),
),
);
}
}
Related
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,
)
],
),
),
);
}
}
I'm a beginner at flutter. I'm practicing to make in Scaffold.
In my code, the last area that Sized Box has errors in child and elevation, and color.
I don't understand why they are used in not correctly, Could you explain that to me?
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
home:Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
leading: IconButton(
icon: Icon(Icons.menu, color: Colors.pink,),
onPressed: () {
print("menu button is clicked");
}
),
title: IconButton(
onPressed: () { print("이미지버튼 동작"); },
icon: Image.asset('assets/images/Slimer_by_shinrider-dcqaiza.webp')),
),
body: Container(
width: 100,
height: 200,
margin: EdgeInsets.all(5.0),
decoration: BoxDecoration(
color: Colors.pinkAccent,
border: Border.all(color: Colors.purple)
),
),
child: SizedBox(
height: 80, width: 100,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0)
),
),
elevation: 4.0,
color: Colors.red
)
)
);
}
}
You have closed Container and Card early on. Please check below against yours and use below to fix the issue.
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
leading: IconButton(
icon: Icon(
Icons.menu,
color: Colors.pink,
),
onPressed: () {
print("menu button is clicked");
}),
title: IconButton(
onPressed: () {
print("이미지버튼 동작");
},
icon: Image.asset(
'assets/images/Slimer_by_shinrider-dcqaiza.webp')),
),
body: Container(
width: 100,
height: 200,
margin: EdgeInsets.all(5.0),
decoration: BoxDecoration(
color: Colors.pinkAccent,
border: Border.all(color: Colors.purple)),
child: SizedBox(
height: 80,
width: 100,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0)),
elevation: 4.0,
color: Colors.red)))));
}
}
your body is Container, which is only need 1 Widget as child.
if you want to use more than 1 Widget , you need to wrap your children that provide List<Widget> as their children.
such as : Column, Row , ListView, etc.
What you miss is you add 1 close bracket in your code
body: Container(
width: 100,
height: 200,
margin: EdgeInsets.all(5.0),
decoration: BoxDecoration(
color: Colors.pinkAccent,
border: Border.all(color: Colors.purple)
),
), <= here your error , you close your container , so your child not included inside the container.
remove what i notice above
Here I am using introduction_screen plugin.
In this problem, I want the same Ui which is my first image, but my second image is being created as it is.
Here I want dots in middle after image and next text on bottom with arrow which should be work for next intro page
How to make it
This is my intro page code.
I am using introduction_screen plugin
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:introduction_screen/introduction_screen.dart';
class OnBoardingPage extends StatefulWidget {
#override
_OnBoardingPageState createState() => _OnBoardingPageState();
}
class _OnBoardingPageState extends State<OnBoardingPage> {
final introKey = GlobalKey<IntroductionScreenState>();
void _onIntroEnd(context) {
Navigator.of(context).push(
MaterialPageRoute(builder: (_) => HomePage()),
);
}
Widget _buildImage(String assetName, ) {
return Image.asset('assets/$assetName',);
}
#override
Widget build(BuildContext context) {
const bodyStyle = TextStyle(fontSize: 19.0);
const pageDecoration = PageDecoration(
titleTextStyle: TextStyle(fontSize: 28.0, fontWeight: FontWeight.w700),
bodyTextStyle: bodyStyle,
bodyPadding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 16.0),
pageColor: Colors.white,
imagePadding: EdgeInsets.zero,
);
return Scaffold(
body: SafeArea(
child: IntroductionScreen(
key: introKey,
globalBackgroundColor: Colors.white,
pages: [
PageViewModel(
decoration: pageDecoration,
title: "Fractional shares",
body:
"Instead of having to buy an entire share, invest any amount you want.",
image: _buildImage('intro_s1.png'),
),
PageViewModel(
title: "Learn as you go",
body:
"Download the Stockpile app and master the market with our mini-lesson.",
image: _buildImage('intro_s1.png'),
decoration: pageDecoration,
),
PageViewModel(
title: "Kids and teens",
body:
"Kids and teens can track their stocks 24/7 and place trades that you approve.",
image: _buildImage('intro_s1.png'),
decoration: pageDecoration,
),
],
onDone: () => _onIntroEnd(context),
next: const Icon(Icons.arrow_forward),
done: const Icon(Icons.arrow_forward),
curve: Curves.fastLinearToSlowEaseIn,
controlsMargin: const EdgeInsets.all(16),
controlsPadding: kIsWeb
? const EdgeInsets.all(12.0)
: const EdgeInsets.fromLTRB(8.0, 4.0, 8.0, 4.0),
dotsDecorator: const DotsDecorator(
size: Size(10.0, 10.0),
color: Color(0xFFBDBDBD),
activeSize: Size(22.0, 10.0),
activeShape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(25.0)),
),
),
dotsContainerDecorator: const ShapeDecoration(
color: Colors.black87,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(8.0)),
),
),
),
),
);
}
}
class HomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Home')),
body: const Center(child: Text("This is the screen after Introduction")),
);
}
}
I want looks like this
but it is becoming like this
change black87 to white in this section of your code.
dotsContainerDecorator: const ShapeDecoration(
color: Colors.black87,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(8.0))
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.
I have tried to implement a layout like this using flutter.
I have used the Cupertino Picker Class for that.
But it just looks not as good as I want it to look.
I have tried to fix it by using the properties, that are listed on the flutter website, but I did not find any better solution. How can I fix this issue or is there even another widget that is better in this case?
My code looks like this:
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
backgroundColor: Colors.red,
),
child: Container(
child: Center(
child: CupertinoPicker(
itemExtent: 40,
diameterRatio: 5,
offAxisFraction: 10,
backgroundColor: Colors.black54,
onSelectedItemChanged: (int index) {
print(index);
},
children: <Widget>[
Text('Tap', style: TextStyle(color:Colors.white)),
Text('Colorbattle',style: TextStyle(color:Colors.white)),
Text('Patience',style: TextStyle(color:Colors.white)),
],
))));
}
}
Playing around your code, I've tried to implement the same behavior. I've observed that changing the values of diameterRatio and offAxisFraction could change the way your UI look like. In my sample, the values of diameterRatio and offAxisFraction is 10 and -1 respectively. Just imagine this kind of roulette:
diameterRatio is the diameter of the cylinder and offAxisFraction is the axis where the side of the cylinder is facing. To mimic the example in the picture, set the value of the offAxisFraction to a positive value, in the implementation shown below, I've set it to 10.
Below is an example of copy the behavior of the UI you're trying to replicate:
import 'package:flutter/cupertino.dart';
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 CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
backgroundColor: Colors.red,
),
child: Center(
child: Container(
// color: Colors.black54,
decoration: BoxDecoration(
border: Border.all(color: Colors.white),
borderRadius: BorderRadius.all(
Radius.circular(15),
),
),
width: 200.0,
height: 150.0,
child: Center(
child: CupertinoPicker(
itemExtent: 40,
diameterRatio: 10,
offAxisFraction: -1,
backgroundColor: Colors.black54,
onSelectedItemChanged: (int index) {
print(index);
},
children: <Widget>[
Align(
alignment: Alignment.centerRight,
child: Padding(
padding: const EdgeInsets.only(right: 40.0),
child: Text(
'Estimate',
style: TextStyle(color: Colors.white),
),
),
),
Align(
alignment: Alignment.centerRight,
child: Padding(
padding: const EdgeInsets.only(right: 40.0),
child: Text(
'Random',
style: TextStyle(color: Colors.white),
),
),
),
Align(
alignment: Alignment.centerRight,
child: Padding(
padding: const EdgeInsets.only(right: 40.0),
child: Text(
'Colorbattle',
style: TextStyle(color: Colors.white),
),
),
),
Align(
alignment: Alignment.centerRight,
child: Padding(
padding: const EdgeInsets.only(right: 40.0),
child: Text(
'Patience',
style: TextStyle(color: Colors.white),
),
),
),
Align(
alignment: Alignment.centerRight,
child: Padding(
padding: const EdgeInsets.only(right: 40.0),
child: Text(
'Tap',
style: TextStyle(color: Colors.white),
),
),
),
],
),
),
),
),
);
}
}
Output: