@@ -4,6 +4,7 @@ import 'dart:io';
44import 'package:flutter/material.dart' ;
55import 'package:flutter_secure_storage/flutter_secure_storage.dart' ;
66import 'package:flutter_widget_from_html/flutter_widget_from_html.dart' ;
7+ import 'package:http/http.dart' as http;
78import 'package:provider/provider.dart' ;
89import 'package:the_api/api.dart' ;
910import 'package:the_api/oauth_token.dart' ;
@@ -172,22 +173,21 @@ typedef ApiOnJsonMap = void Function(Map jsonMap);
172173typedef ApiOnError = void Function (dynamic error);
173174
174175class ApiApp extends StatefulWidget {
175- final Api api;
176176 final Widget child;
177+ final bool enableBatch;
177178
178- ApiApp ({
179+ const ApiApp ({
179180 required this .child,
181+ this .enableBatch = true ,
180182 Key ? key,
181- }) : api = Api (config.apiRoot, config.clientId, config.clientSecret)
182- ..httpHeaders['Api-Bb-Code-Chr' ] = '1'
183- ..httpHeaders['Api-Post-Tree' ] = '1' ,
184- super (key: key);
183+ }) : super (key: key);
185184
186185 @override
187186 State <ApiApp > createState () => _ApiAppState ();
188187}
189188
190189class _ApiAppState extends State <ApiApp > {
190+ late final Api api;
191191 final secureStorage = const FlutterSecureStorage ();
192192 final visitor = User .zero ();
193193
@@ -196,15 +196,25 @@ class _ApiAppState extends State<ApiApp> {
196196 OauthToken ? _token;
197197 var _tokenHasBeenSet = false ;
198198
199- Api get api => widget.api;
200-
201199 String get _secureStorageKeyToken =>
202200 kSecureStorageKeyPrefixToken + api.clientId;
203201
204202 @override
205203 void initState () {
206204 super .initState ();
207205
206+ api = Api (
207+ context.read< http.Client > (),
208+ apiRoot: config.apiRoot,
209+ clientId: config.clientId,
210+ clientSecret: config.clientSecret,
211+ enableBatch: widget.enableBatch,
212+ httpHeaders: const {
213+ 'Api-Bb-Code-Chr' : '1' ,
214+ 'Api-Post-Tree' : '1' ,
215+ },
216+ );
217+
208218 secureStorage.read (key: _secureStorageKeyToken).then <OauthToken ?>(
209219 (value) {
210220 try {
0 commit comments