File tree Expand file tree Collapse file tree 4 files changed +58
-2
lines changed Expand file tree Collapse file tree 4 files changed +58
-2
lines changed Original file line number Diff line number Diff line change 1+ import 'package:flutter/material.dart' ;
2+ import 'package:flutter_constraintlayout/src/constraint_layout.dart' ;
3+
4+ import 'custom_app_bar.dart' ;
5+
6+ class CirclePositionExample extends StatelessWidget {
7+ const CirclePositionExample ({Key ? key}) : super (key: key);
8+
9+ @override
10+ Widget build (BuildContext context) {
11+ return Scaffold (
12+ appBar: const CustomAppBar (
13+ title: 'Circle Position' ,
14+ codePath: 'example/circle_position.dart' ,
15+ ),
16+ body: ConstraintLayout (
17+ children: [
18+ Container (
19+ color: Colors .redAccent,
20+ ).applyConstraint (
21+ width: 100 ,
22+ height: 100 ,
23+ centerTo: parent,
24+ ),
25+ for (int angle = 0 ; angle <= 360 ; angle += 15 )
26+ Container (
27+ color: Colors .yellow,
28+ ).applyConstraint (
29+ width: 50 ,
30+ height: 50 ,
31+ centerTo: rId (0 ),
32+ translate: circleTranslate (
33+ radius: 300 ,
34+ angle: angle,
35+ ),
36+ ),
37+ ],
38+ ),
39+ );
40+ }
41+ }
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import 'package:flutter_constraintlayout/flutter_constraintlayout.dart';
33
44import 'badge.dart' ;
55import 'barrier.dart' ;
6+ import 'circle_position.dart' ;
67import 'complex_list.dart' ;
78import 'dimension_ratio.dart' ;
89import 'grid.dart' ;
@@ -32,6 +33,7 @@ class ExampleHome extends StatelessWidget {
3233 'Horizontal List' : const HorizontalListExample (),
3334 'Vertical List' : const VerticalListExample (),
3435 'Staggered Grid' : const StaggeredGridExample (),
36+ 'Circle Position' : const CirclePositionExample (),
3537 'Chain (Coming soon)' : null ,
3638 };
3739
@@ -58,7 +60,7 @@ class ExampleHome extends StatelessWidget {
5860 ),
5961 left: parent.left,
6062 top: rId (0 ).bottom,
61- itemCount: 13 ,
63+ itemCount: keyList.length ,
6264 columnCount: 1 ,
6365 itemWidth: matchParent,
6466 itemHeight: 40 ,
Original file line number Diff line number Diff line change 11import 'dart:collection' ;
22import 'dart:convert' ;
3+ import 'dart:math' ;
34import 'dart:ui' as ui;
45import 'dart:ui' ;
56
@@ -92,6 +93,17 @@ class ConstraintLayout extends MultiChildRenderObjectWidget {
9293 }
9394}
9495
96+ Offset circleTranslate ({
97+ required double radius,
98+ required int angle,
99+ }) {
100+ assert (radius >= 0 && radius != double .infinity);
101+ assert (angle >= 0 && angle <= 360 );
102+ double xTranslate = sin ((angle / 180 ) * pi) * radius;
103+ double yTranslate = - cos ((angle / 180 ) * pi) * radius;
104+ return Offset (xTranslate, yTranslate);
105+ }
106+
95107List <Widget > constraintGrid ({
96108 required ConstraintId id,
97109 required _Align left,
Original file line number Diff line number Diff line change @@ -34,4 +34,5 @@ flutter:
3434 - example/grid.dart
3535 - example/horizontal_list.dart
3636 - example/vertical_list.dart
37- - example/staggered_grid.dart
37+ - example/staggered_grid.dart
38+ - example/circle_position.dart
You can’t perform that action at this time.
0 commit comments