How to create multiple circles using flutter - flutter

i am new to the flutter, need to create 12 circles around circle with proper angle, pls help to find proper answer with mathematically correct. pls refer the above diagram.
I have just faced the same issue...
Easy workaround:
Container(
width: 28,
height: 28,
decoration: BoxDecoration(
color: Colors.green.withOpacity(0.25), // border color
shape: BoxShape.circle,
),
child: Padding(
padding: EdgeInsets.all(2), // border width
child: Container( // or ClipRRect if you need to clip the content
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.blue, // inner circle color
),
child: Container(), // inner content
),
),
),

You Just Need To Run This Code:
import 'package:flutter/material.dart';
import 'circle_file.dart';
import 'dart:math' as math;
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: const CircelFile(),
);
}
}
class CircelFile extends StatefulWidget {
const CircelFile({Key? key}) : super(key: key);
#override
State<CircelFile> createState() => _CircelFileState();
}
class _CircelFileState extends State<CircelFile> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Center(
child: Stack(
children: [
Container(
width:300,
height: 300,
color: Colors.white,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 30,
height:30,
decoration: BoxDecoration(
color: Colors.red, // border color
shape: BoxShape.circle,
),
),
Container(
height:1.0,
width:70,
color:Colors.black,),
Container(
width: 70,
height: 70,
decoration: BoxDecoration(
color: Colors.green, // border color
shape: BoxShape.circle,
),
),
Container(
height:1.0,
width:70,
color:Colors.black,),
Container(
width: 30,
height:30,
decoration: BoxDecoration(
color: Colors.red, // border color
shape: BoxShape.circle,
),
),
],
),
),
Positioned(
left: 136,
top: 18,
child: Column(
children: [
Container(
width: 30,
height:30,
decoration: BoxDecoration(
color: Colors.red, // border color
shape: BoxShape.circle,
),
),
Container(
height:70,
width:1,
color:Colors.black,),
],
),
),
Positioned(
left: 136,
bottom:15,
child: Column(
children: [
Container(
height:70,
width:1,
color:Colors.black,),
Container(
width: 30,
height:30,
decoration: BoxDecoration(
color: Colors.red, // border color
shape: BoxShape.circle,
),
),
],
),
),
Positioned(
left: 197,
bottom:36,
child: Transform.rotate(
angle: -math.pi /4,
child: Column(
children: [
Container(
height:70,
width:1,
color:Colors.black,),
Container(
width: 30,
height:30,
decoration: BoxDecoration(
color: Colors.red, // border color
shape: BoxShape.circle,
),
),
],
),
),
),
Positioned(
left:70,
top: 160,
child: RotationTransition(
turns: AlwaysStoppedAnimation(-20 / 23),
child: Column(
children: [
Container(
height:70,
width:1,
color:Colors.black,),
Container(
width: 30,
height:30,
decoration: BoxDecoration(
color: Colors.red, // border color
shape: BoxShape.circle,
),),
],
),
),
),
Positioned(
right: 65,
top: 55,
child: RotationTransition(
turns: AlwaysStoppedAnimation(-20 / 58),
child: Column(
children: [
Container(
height:70,
width:1,
color:Colors.black,),
Container(
width: 30,
height:30,
decoration: BoxDecoration(
color: Colors.red, // border color
shape: BoxShape.circle,
),),
],
),
),
),
Positioned(
left: 70,
top: 40,
child: RotationTransition(
turns: AlwaysStoppedAnimation(-20 / 32),
child: Column(
children: [
Container(
height:70,
width:1,
color:Colors.black,),
Container(
width: 30,
height:30,
decoration: BoxDecoration(
color: Colors.red, // border color
shape: BoxShape.circle,
),),
],
),
),
),[enter link description here][1]
],
),
),
);
}
}

Related

remove border in background in flutter

I'm confused how to make the colored border cut off, when I meet the word "Month", I tried with BoxDecoration(color: Colors.transparent), but it doesn't produce anything, the border still doesn't get cut.
like the following :
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
#override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Container(
decoration: BoxDecoration(color: Colors.blue),
child: Center(
child: Container(
width: 120,
height: 110,
decoration: BoxDecoration(color: Colors.pink),
child: Stack(
children: [
Positioned(
bottom: 0,
child: Container(
height: 55,
width: 120,
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.all(Radius.circular(10)),
border: Border.all(width: 2, color: Colors.white),
),
),
),
Positioned(
left: (120 - 50) / 2,
top: 45,
child: Container(
width: 50,
height: 15,
decoration:
BoxDecoration(color: Colors.black.withOpacity(0.1)),
child: Center(
child: Text("Month"),
),
),
),
],
),
),
),
)),
);}}
I want a look like this:
Please for the guidance, Thank you
A sample quick trick to have the effect you want is to set the background color for your positioned text as the same as your pink container:
child: Container(
width: 50,
height: 15,
padding: const EdgeInsets.all(5.0) <- with this too
decoration:
BoxDecoration(color: Colors.pink,), <- here
child: Center(
child: Text("Month"),
),
try this
Scaffold(
body: Stack(
children: <Widget>[
Container(
width: double.infinity,
height: 200,
margin: EdgeInsets.fromLTRB(20, 20, 20, 10),
padding: EdgeInsets.only(bottom: 10),
decoration: BoxDecoration(
color: Colors.green,
border: Border.all(width: 2, color: Colors.white),
borderRadius: BorderRadius.circular(15),
shape: BoxShape.rectangle,
),
),
Positioned(
left: 100,
top: 12,
child: Container(
padding: EdgeInsets.only(bottom: 10, left: 10, right: 10),
color: Colors.black.withOpacity(0.1),
child: Text(
'Month',
),
),
),
],
),
)

how to mix between columns and rows in flutter

I want to two add two containers next to each other in a row with two icon buttons on the bottom of the app like shown in the picture. i tried to use sizedbox but it wasn't enough.
i started the code with this but couldn't continue:
class Restaurent extends StatefulWidget {
const Restaurent({Key? key, required this.title}) : super(key: key);
final String title;
#override
_Restaurent createState() => _Restaurent();
}
class _Restaurent extends State<Restaurent> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Restaurant") ,
),
body: Container(
child: SafeArea(
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Icon(Icons.youtube_searched_for),
]
),
),
),
);
}
}
You can create a Row() with setting mainAxisAlignment: MainAxisAlignment.end.
Here's an example, you can adjust it to fit what you want:
Scaffold(
body: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
height: 100,
width: 100,
decoration: BoxDecoration(
// color: Colors.black,
borderRadius: BorderRadius.circular(10),
border: Border.all(color: Colors.black)),
child: Text("hi"),
),
SizedBox(
width: 10,
),
Container(
height: 100,
width: 100,
decoration: BoxDecoration(
// color: Colors.black,
borderRadius: BorderRadius.circular(10),
border: Border.all(color: Colors.black)),
child: Text("hi"),
),
],
),
SizedBox(
height: 50,
),
Divider(
thickness: 5,
color: Colors.black,
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
height: 100,
width: 100,
decoration: BoxDecoration(
// color: Colors.black,
borderRadius: BorderRadius.circular(25),
border: Border.all(color: Colors.black)),
child: Text("hi"),
),
SizedBox(
width: 10,
),
Container(
height: 100,
width: 100,
decoration: BoxDecoration(
// color: Colors.black,
borderRadius: BorderRadius.circular(25),
border: Border.all(color: Colors.black)),
child: Text("hi"),
),
],
),
],
),
);
Result:

how to stack image to show in the background

Please pardon me to post this.
i am working with this design more that 3 days now i can i get the actual design. all my effort design is been rejected.
i am trying to create this design.
the problem i have is the right and left box showing at the back of the image.
thanks in advance.
here is my code
Container(
child: Card(
shape:RoundedRectangleBorder(borderRadius:
BorderRadius.circular(25.0),
),
semanticContainer:true,
clipBehavior:
Clip.antiAliasWithSaveLayer,
child:Image(image:
NetworkImage(snapshot.data.docs[index].data()['picture'], ),
fit: BoxFit.cover,), ),),);
Scaffold(
body: Container(
height: double.infinity,
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Colors.pinkAccent,
Colors.yellowAccent,
],
),
),
child: Stack(
children: [
Positioned(
left: 70,
// right: 40,
top: 40,
child: Transform.rotate(
angle: pi - 3.30,
child: Container(
// transform: ,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.white.withOpacity(0.2),
),
height: 200,
width: 150,
),
),
),
Positioned(
left: 130,
// right: 150,
top: 78,
child: Transform.rotate(
angle: pi + 3.30,
child: Container(
// transform: ,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.white.withOpacity(0.6),
),
height: 190,
width: 150,
),
),
),
Positioned(
left: 0,
right: 0,
top: 50,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 100.0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.white,
image: DecorationImage(
image: NetworkImage("https://picsum.photos/200/300"),
fit: BoxFit.fill
),
),
height: 220,
width: 100,
),
),
),
],
),
),
);
Result
If you like change, black shadow play with stops inside gradient. hope you will get the idea of doing it.
stops: [.5, 1.0],
To AlignWidgte change this valuealignment: Alignment(-1, -1),. For rotation change here. Better use slider or from dart:math use pi.
Transform.rotate(angle: -.166,
Code snippet
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
get imageWidth => 300;
get imageHeight => 450;
double sliderVal = 0.0;
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
buttonTheme: ButtonThemeData(
textTheme: ButtonTextTheme.primary,
),
),
home: Scaffold(
body: Column(
children: [
Slider(
value: sliderVal,
onChanged: (v) {
setState(() {
sliderVal = v;
print(sliderVal);
});
}),
Container(
width: imageWidth * 1.4,
height: imageHeight * 1.1,
child: Stack(
children: [
Align(
alignment: Alignment(-1, -1),
child: Transform.rotate(
angle: -.166,
child: backImage(color: Colors.blue),
),
),
Align(
alignment: Alignment(1, 1),
child: Transform.rotate(
angle: .128,
child: backImage(color: Colors.yellow),
),
),
Center(
child: mainImage(),
),
],
),
),
],
),
),
// CustomSS(),
);
}
backImage({required Color color, double? width, double? height}) {
return Container(
width: width ?? imageWidth,
height: height ?? imageHeight,
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(12),
),
);
}
SizedBox mainImage() {
return SizedBox(
width: imageWidth,
height: imageHeight,
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: Stack(
fit: StackFit.expand,
children: [
Image.asset(
"assets/me.jpg",
fit: BoxFit.cover,
),
Container(
decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(12),
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
stops: [.5, 1.0],
colors: [
Colors.transparent,
Colors.black87,
],
),
),
),
Positioned(
bottom: 30,
left: 30,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Row(
children: [
Text(
"Yeasin",
style: TextStyle(
fontSize: 22,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
SizedBox(
width: 8,
),
Text(
"XX",
style: TextStyle(
fontSize: 22,
color: Colors.white,
),
)
],
),
SizedBox(
height: 10,
),
Text(
"Description",
style: TextStyle(
fontSize: 14,
color: Colors.white,
),
),
]),
)
],
),
));
}
}

How to stop ColorFiltered blending?

I followed the answer of this question to create a widget with a transparent hole. My problem now is that any other widgets I place on the screen have a blend effect as well. I would
like this to not be the case, if possible. Here's my code:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#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> {
#override
Widget build(BuildContext context) {
return Material(
child: Stack(
fit: StackFit.expand,
children: [
Image.network(
'https://wallpaperplay.com/walls/full/8/3/a/35405.jpg',
fit: BoxFit.cover,
),
ColorFiltered(
colorFilter: ColorFilter.mode(Colors.black.withOpacity(0.8),
BlendMode.srcOut), // This one will create the magic
child: Column(
children: [
Expanded(
child: Stack(
fit: StackFit.expand,
children: [
Container(
decoration: BoxDecoration(
color: Colors.black,
backgroundBlendMode: BlendMode
.dstOut), // This one will handle background + difference out
),
Align(
alignment: Alignment.topCenter,
child: Container(
margin: const EdgeInsets.only(top: 80),
height: 200,
width: 200,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(10),
),
),
),
],
),
),
Text("Test",
style: TextStyle(
color: Colors.red,
fontSize: 64,
fontWeight: FontWeight.bold)),
],
),
),
Align(
alignment: Alignment.topCenter,
child: Container(
margin: const EdgeInsets.only(top: 80),
height: 200,
width: 200,
decoration: BoxDecoration(
//color: Colors.red,
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: Colors.red,
width: 2,
),
),
),
),
],
),
);
}
}
And the result:
I want the text widget "Test" to be in red and not show the image below. Any widget placed above the color filter should not be blended with the background. I've tried wrapping the text in a ColorFiltered widget and setting the BlendMode to "src" which should discard the destination image (if I understand the documentation correctly), but that did not work.
since you are using a stack, just pull out the text wsidget from the ColoredFilter widget and place it after the widget. This way it will appear on top.
something like this (not tested):
Stack(
fit: StackFit.expand,
children: [
Image.network(
'https://wallpaperplay.com/walls/full/8/3/a/35405.jpg',
fit: BoxFit.cover,
),
ColorFiltered(
colorFilter: ColorFilter.mode(Colors.black.withOpacity(0.8),
BlendMode.srcOut), // This one will create the magic
child: Column(
children: [
Expanded(
child: Stack(
fit: StackFit.expand,
children: [
Container(
decoration: BoxDecoration(
color: Colors.black,
backgroundBlendMode: BlendMode
.dstOut), // This one will handle background + difference out
),
Align(
alignment: Alignment.topCenter,
child: Container(
margin: const EdgeInsets.only(top: 80),
height: 200,
width: 200,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(10),
),
),
),
],
),
),
],
),
),
// I just moved text widget here, you may need to apply any Position, align, padding, margin you wish, since it is now outside of the Expand widget
Text("Test",
style: TextStyle(
color: Colors.red,
fontSize: 64,
fontWeight: FontWeight.bold)),
Align(
alignment: Alignment.topCenter,
child: Container(
margin: const EdgeInsets.only(top: 80),
height: 200,
width: 200,
decoration: BoxDecoration(
//color: Colors.red,
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: Colors.red,
width: 2,
),
),
),
),
],
),

Create curved card with shadow

I really need you because I don't have even start idea how to implement these, and also I am not sure how it is called.
Actually, I want to implement something similar like on image (this little circle in each of cards - that is like chain between two cards).
With help of key I have made image from up with this code:
class InfoPage extends StatefulWidget {
InfoPage();
#override
_InfoPageState createState() => _InfoPageState();
}
class _InfoPageState extends State<InfoPage> {
InfoItemModel infoData = dataSourceInfoUser;
double basicSize = 70;
#override
initState() {
super.initState();
}
#override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: Text('Example'),
),
body: Container(
color: Colors.white,
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
width: double.infinity,
height: 150,
child: AppCardField(
child: Text('Something'),
),
),
_buildCardWithCircle(
bgCircleX: 0.78,
bgCirceY: -2.0,
innerContainerX: 0.756,
innerContainerY: -1.78,
colorInner: Colors.orange
),
],
),
),
),
);
_buildCardWithCircle({double bgCircleX, double bgCirceY, double innerContainerX, double innerContainerY, Color colorInner}) => Container(
width: double.infinity,
height: 150,
child: Stack(
children: <Widget>[
Container(
width: double.infinity,
height: 150,
child: AppCardField(
child: Text('Something'),
),
),
Align(
alignment: Alignment(bgCircleX, bgCirceY),
child: Container(
height: basicSize,
width: basicSize,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(50.0),
),
),
),
Align(
alignment: Alignment(innerContainerX, innerContainerY),
child: Container(
height: basicSize - 10,
width: basicSize - 10,
decoration: BoxDecoration(
color: colorInner,
borderRadius: BorderRadius.circular(50.0),
),
child: Icon(Icons.vertical_align_center),
),
),
],
),
);
}
class AppCardField extends StatelessWidget {
final Widget child;
final double height;
final double paddingVertical, paddingHorizontal;
final double paddingVerticalChild, paddingHorizontalChild;
AppCardField({
this.child,
this.height,
this.paddingVertical = 8,
this.paddingHorizontal = 16,
this.paddingVerticalChild = 8,
this.paddingHorizontalChild = 16,
Key key})
: super(key: key);
#override
Widget build(BuildContext context) => Padding(
padding: EdgeInsets.symmetric(
vertical: paddingVertical, horizontal: paddingHorizontal),
child: Container(
height: height,
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.all(Radius.circular(8)),
boxShadow: [
BoxShadow(
color: Colors.red,
blurRadius: 15.0,
offset: Offset(0.0, 5.0),
),
],
),
child: Padding(
padding: EdgeInsets.symmetric(
vertical: paddingVerticalChild,
horizontal: paddingHorizontalChild),
child: child,
),
));
}
But here, I have problem with shadow of the card and strongly white background of circle, OFC I need this shadow to be also in this white space, question is how to solve this?
Something like this
MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("Some Stuff"),
),
body: Column(
children: <Widget>[
Container(
width: double.infinity,
height: 150.0,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.red,
blurRadius: 20.0
)
]
),
child: Card(
elevation: 20.0,
color: Colors.blueGrey,
child: Text('Something'),
),
),
SizedBox(height: 10.0,),
Container(
width: double.infinity,
height: 150.0,
child: Stack(
children: <Widget>[
Container(
width: double.infinity,
height: 150.0,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.red,
blurRadius: 20.0
)
]
),
child: Card(
elevation: 20.0,
color: Colors.blueGrey,
child: Text('Something'),
),
),
Align(
alignment: Alignment(0.9,-1.5),
child: Container(
height: 50.0,
width: 50.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(25.0),
),
),
),
Align(
alignment: Alignment(0.88,-1.35),
child: Container(
height: 40.0,
width: 40.0,
decoration: BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.circular(25.0),
),
),
),
Align(
alignment: Alignment(0.85, -1.2),
child: Icon(Icons.access_alarms, color: Colors.white,)
),
],
),
),
],
),
),
);
then you just reaped the card for the other once with different alignment values.