File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -188,6 +188,24 @@ Client? get zoneClient {
188
188
/// The [Client] returned by [clientFactory] is used by the [Client.new] factory
189
189
/// and the convenience HTTP functions (e.g. [http.get] ). If [clientFactory]
190
190
/// returns `Client()` then the default [Client] is used.
191
+ ///
192
+ /// When used in the context of Flutter, [runWithClient] should be called before
193
+ /// [`WidgetsFlutterBinding.ensureInitialized`] (https://api.flutter.dev/flutter/widgets/WidgetsFlutterBinding/ensureInitialized.html)
194
+ /// because Flutter runs in whatever [Zone] was current at the time that the
195
+ /// bindings were initialized.
196
+ ///
197
+ /// [`runApp`] (https://api.flutter.dev/flutter/widgets/runApp.html) calls
198
+ /// [`WidgetsFlutterBinding.ensureInitialized`] (https://api.flutter.dev/flutter/widgets/WidgetsFlutterBinding/ensureInitialized.html)
199
+ /// so the easiest approach is to call that in [body] :
200
+ /// ```
201
+ /// void main() {
202
+ /// var clientFactory = Client.new; // Constructs the default client.
203
+ /// if (Platform.isAndroid) {
204
+ /// clientFactory = MyAndroidHttpClient.new;
205
+ /// }
206
+ /// runWithClient(() => runApp(const MyApp()), clientFactory);
207
+ /// }
208
+ /// ```
191
209
R runWithClient <R >(R Function () body, Client Function () clientFactory,
192
210
{ZoneSpecification ? zoneSpecification}) =>
193
211
runZoned (body,
You can’t perform that action at this time.
0 commit comments