Yin and yang: Difference between revisions

Content added Content deleted
Line 2,191: Line 2,191:
<syntaxhighlight lang="dart">import 'package:flutter/material.dart';
<syntaxhighlight lang="dart">import 'package:flutter/material.dart';


const colors = [Colors.black, Colors.white];
const color = [Colors.black, Colors.white];


Container cR(int iClr, double r, {Widget? child, Clip clip = Clip.none}) => Container(
Container cR(int iColor, double r, {Widget? child, bool main = false}) => Container(
decoration: ShapeDecoration(color: color[iColor], shape: const CircleBorder()),
width: r * 2,
constraints: BoxConstraints.tight(Size.fromRadius(r)),
height: r * 2,
clipBehavior: main ? Clip.hardEdge : Clip.none,
decoration: ShapeDecoration(color: colors[iClr], shape: const CircleBorder()),
margin: main ? const EdgeInsets.all(5) : null,
clipBehavior: clip,
child: Center(child: child));
child: Center(child: child));


Container yinYang(double r, [double th = 1.0]) => cR(0, r + th,
Container yinYang(double r, [double th = 1.0]) => cR(0, r + th,
clip: Clip.hardEdge,
main: true,
child: cR(1, r,
child: cR(1, r,
child: Stack(alignment: Alignment.center, children: [
child: Stack(alignment: Alignment.center, children: [
Container(color: colors[0], margin: EdgeInsets.only(left: r)),
Container(color: color[0], margin: EdgeInsets.only(left: r)),
Column(children: List.generate(2, (i) => cR(1 - i, r / 2, child: cR(i, r / 6))))
Column(children: List.generate(2, (i) => cR(1 - i, r / 2, child: cR(i, r / 6))))
])));
])));


void main() => runApp(const MainApp());
void main() => runApp(MaterialApp(
home: ColoredBox(color: color[1], child: Wrap(children: [yinYang(50), yinYang(20)]))));

class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) => MaterialApp(
home: Container(
color: colors[1],
padding: const EdgeInsets.all(10),
child: Wrap(children: [yinYang(50), yinYang(20)])));
}
</syntaxhighlight>
</syntaxhighlight>