@@ -2,12 +2,13 @@ import 'package:flutter/foundation.dart';
22import 'package:flutter/material.dart' ;
33import 'package:flutter/rendering.dart' ;
44import 'package:flutter/services.dart' ;
5+ import 'package:flutter_hooks/flutter_hooks.dart' ;
56
67import '../theme/theme.dart' ;
78
89/// An iOS-native sheet surface that adopts the system's concentric corners on
910/// iOS 26 and newer. Other platforms keep the normal Flutter shape.
10- class ConcentricSheetSurface extends StatefulWidget {
11+ class ConcentricSheetSurface extends HookWidget {
1112 const ConcentricSheetSurface ({
1213 required this .child,
1314 required this .enabled,
@@ -19,43 +20,38 @@ class ConcentricSheetSurface extends StatefulWidget {
1920 final bool enabled;
2021 final Color ? color;
2122
22- @override
23- State <ConcentricSheetSurface > createState () => _ConcentricSheetSurfaceState ();
24- }
25-
26- class _ConcentricSheetSurfaceState extends State <ConcentricSheetSurface > {
2723 static const _surfaceChannel = MethodChannel ('buzz/concentric_sheet_surface' );
2824
29- bool _nativeSurfaceSupported = false ;
30-
31- @override
32- void initState () {
33- super .initState ();
34- _checkNativeSurfaceSupport ();
35- }
36-
37- Future <void > _checkNativeSurfaceSupport () async {
38- if (! widget.enabled || defaultTargetPlatform != TargetPlatform .iOS) return ;
39-
25+ Future <bool > _checkNativeSurfaceSupport () async {
4026 try {
4127 final supported = await _surfaceChannel.invokeMethod <bool >('isSupported' );
42- if (mounted && supported == true ) {
43- setState (() => _nativeSurfaceSupported = true );
44- }
28+ return supported == true ;
4529 } on MissingPluginException {
4630 // The registrar is unavailable, so retain the Flutter surface.
31+ return false ;
4732 } on PlatformException {
4833 // The native surface is optional; retain the Flutter surface on failure.
34+ return false ;
4935 }
5036 }
5137
5238 @override
5339 Widget build (BuildContext context) {
54- if (! widget.enabled || defaultTargetPlatform != TargetPlatform .iOS) {
55- return widget.child;
40+ final shouldCheckNativeSurface =
41+ enabled && defaultTargetPlatform == TargetPlatform .iOS;
42+ final supportFuture = useMemoized (
43+ () => shouldCheckNativeSurface
44+ ? _checkNativeSurfaceSupport ()
45+ : Future <bool >.value (false ),
46+ [shouldCheckNativeSurface],
47+ );
48+ final nativeSurfaceSupported = useFuture (supportFuture).data ?? false ;
49+
50+ if (! shouldCheckNativeSurface) {
51+ return child;
5652 }
5753
58- final surfaceColor = widget. color ?? context.colors.surface;
54+ final surfaceColor = color ?? context.colors.surface;
5955
6056 return Padding (
6157 padding: const EdgeInsets .only (
@@ -65,7 +61,7 @@ class _ConcentricSheetSurfaceState extends State<ConcentricSheetSurface> {
6561 ),
6662 child: Stack (
6763 children: [
68- if (_nativeSurfaceSupported )
64+ if (nativeSurfaceSupported )
6965 Positioned .fill (
7066 child: ExcludeSemantics (
7167 child: UiKitView (
@@ -87,7 +83,7 @@ class _ConcentricSheetSurfaceState extends State<ConcentricSheetSurface> {
8783 clipBehavior: Clip .antiAlias,
8884 ),
8985 ),
90- widget. child,
86+ child,
9187 ],
9288 ),
9389 );
0 commit comments