@@ -14,18 +14,24 @@ class MyApp extends StatefulWidget {
1414}
1515
1616class _MyAppState extends State <MyApp > {
17+ late final Future <CornerRadius > _radiusFuture;
18+
1719 @override
1820 void initState () {
1921 super .initState ();
22+ // Initialize once with a non-zero fallback radius for unsupported devices.
23+ _radiusFuture = CornerRadiusPlugin .init (defaultRadius: 12 );
2024 }
2125
2226 @override
2327 Widget build (BuildContext context) {
2428 return MaterialApp (
29+ debugShowCheckedModeBanner: false ,
2530 home: Scaffold (
31+ appBar: AppBar (title: const Text ('Corner Radius Plugin Example' )),
2632 body: SafeArea (
2733 child: FutureBuilder (
28- future: CornerRadiusPlugin . init () ,
34+ future: _radiusFuture ,
2935 builder: (context, snapshot) {
3036 if (! snapshot.hasData) {
3137 return const Center (child: CircularProgressIndicator ());
@@ -36,57 +42,69 @@ class _MyAppState extends State<MyApp> {
3642 return const Center (child: Text ('No data' ));
3743 }
3844
45+ // Demonstrate the static getter after init.
46+ final screenRadius = CornerRadiusPlugin .screenRadius;
47+
3948 return Padding (
4049 padding: const EdgeInsets .all (16 ),
41- child: DecoratedBox (
42- decoration: BoxDecoration (
43- color: Colors .blue,
44- borderRadius: BorderRadius .only (
45- topLeft: Radius .circular (data.topLeft),
46- topRight: Radius .circular (data.topRight),
47- bottomLeft: Radius .circular (data.bottomLeft),
48- bottomRight: Radius .circular (data.bottomRight),
49- ),
50- ),
51- child: Padding (
52- padding: const EdgeInsets .all (32 ),
53- child: Stack (
54- children: [
55- Align (
56- alignment: Alignment .topLeft,
57- child: Text (
58- data.topLeft.toStringAsFixed (2 ).toString (),
59- textAlign: TextAlign .center,
60- style: TextStyle (color: Colors .white, fontSize: 32 ),
61- ),
62- ),
63- Align (
64- alignment: Alignment .topRight,
65- child: Text (
66- data.topRight.toStringAsFixed (2 ).toString (),
67- textAlign: TextAlign .center,
68- style: TextStyle (color: Colors .white, fontSize: 32 ),
50+ child: Column (
51+ crossAxisAlignment: CrossAxisAlignment .stretch,
52+ children: [
53+ Expanded (
54+ child: DecoratedBox (
55+ decoration: BoxDecoration (
56+ color: Colors .blue,
57+ borderRadius: BorderRadius .only (
58+ topLeft: Radius .circular (screenRadius.topLeft),
59+ topRight: Radius .circular (screenRadius.topRight),
60+ bottomLeft: Radius .circular (
61+ screenRadius.bottomLeft,
62+ ),
63+ bottomRight: Radius .circular (
64+ screenRadius.bottomRight,
65+ ),
6966 ),
7067 ),
71- Align (
72- alignment: Alignment .bottomLeft,
73- child: Text (
74- data.bottomLeft.toStringAsFixed (2 ).toString (),
75- textAlign: TextAlign .center,
76- style: TextStyle (color: Colors .white, fontSize: 32 ),
68+ child: Padding (
69+ padding: const EdgeInsets .all (24 ),
70+ child: Stack (
71+ children: [
72+ _CornerValue (
73+ alignment: Alignment .topLeft,
74+ value: screenRadius.topLeft,
75+ ),
76+ _CornerValue (
77+ alignment: Alignment .topRight,
78+ value: screenRadius.topRight,
79+ ),
80+ _CornerValue (
81+ alignment: Alignment .bottomLeft,
82+ value: screenRadius.bottomLeft,
83+ ),
84+ _CornerValue (
85+ alignment: Alignment .bottomRight,
86+ value: screenRadius.bottomRight,
87+ ),
88+ ],
7789 ),
7890 ),
79- Align (
80- alignment: Alignment .bottomRight,
81- child: Text (
82- data.bottomRight.toStringAsFixed (2 ).toString (),
83- textAlign: TextAlign .center,
84- style: TextStyle (color: Colors .white, fontSize: 32 ),
85- ),
91+ ),
92+ ),
93+ const SizedBox (height: 16 ),
94+ Card (
95+ child: Padding (
96+ padding: const EdgeInsets .all (12 ),
97+ child: Text (
98+ 'Initialized with defaultRadius: 12\n '
99+ 'Current values (TL, TR, BL, BR): '
100+ '${screenRadius .topLeft .toStringAsFixed (2 )}, '
101+ '${screenRadius .topRight .toStringAsFixed (2 )}, '
102+ '${screenRadius .bottomLeft .toStringAsFixed (2 )}, '
103+ '${screenRadius .bottomRight .toStringAsFixed (2 )}' ,
86104 ),
87- ] ,
105+ ) ,
88106 ),
89- ) ,
107+ ] ,
90108 ),
91109 );
92110 },
@@ -96,3 +114,22 @@ class _MyAppState extends State<MyApp> {
96114 );
97115 }
98116}
117+
118+ class _CornerValue extends StatelessWidget {
119+ const _CornerValue ({required this .alignment, required this .value});
120+
121+ final Alignment alignment;
122+ final double value;
123+
124+ @override
125+ Widget build (BuildContext context) {
126+ return Align (
127+ alignment: alignment,
128+ child: Text (
129+ value.toStringAsFixed (2 ),
130+ textAlign: TextAlign .center,
131+ style: const TextStyle (color: Colors .white, fontSize: 28 ),
132+ ),
133+ );
134+ }
135+ }
0 commit comments