@@ -18,18 +18,20 @@ class ConnectionSettingsPage extends StatefulWidget {
1818
1919class _ConnectionSettingsPageState extends State <ConnectionSettingsPage >
2020 with TickerProviderStateMixin {
21- late TabController _tabController ;
22- ExternalStorage ? storage ;
21+ bool ? _isRemote ;
22+ late final TabController _tabController ;
2323
2424 @override
2525 void initState () {
2626 super .initState ();
27- storage = context.read <SettingsCubit >().getRemote (widget.remote);
28- _tabController = TabController (length: _isRemote ? 2 : 1 , vsync: this );
27+ _isRemote =
28+ context.read <SettingsCubit >().getRemote (widget.remote) is RemoteStorage ;
29+ _tabController = TabController (
30+ length: (_isRemote ?? false ) ? 2 : 1 ,
31+ vsync: this ,
32+ );
2933 }
3034
31- bool get _isRemote => storage is RemoteStorage ;
32-
3335 @override
3436 void dispose () {
3537 _tabController.dispose ();
@@ -49,7 +51,7 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage>
4951 return Scaffold (
5052 appBar: WindowTitleBar <SettingsCubit , ButterflySettings >(
5153 title: Text (widget.remote),
52- bottom: _isRemote
54+ bottom: ( _isRemote ?? false )
5355 ? TabBar (
5456 controller: _tabController,
5557 onTap: (_) => setState (() {}),
@@ -67,16 +69,17 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage>
6769 )
6870 : null ,
6971 ),
70- body: storage == null
72+ body: _isRemote == null
7173 ? Center (child: Text (AppLocalizations .of (context).noConnections))
7274 : TabBarView (
7375 controller: _tabController,
7476 children: [
75- _GeneralConnectionSettingsView (storage: storage! ),
76- if (_isRemote)
77- _CachesConnectionSettingsView (
78- storage: storage as RemoteStorage ,
79- ),
77+ _GeneralConnectionSettingsView (
78+ identifier: widget.remote,
79+ isRemote: _isRemote ?? false ,
80+ ),
81+ if (_isRemote ?? false )
82+ _CachesConnectionSettingsView (identifier: widget.remote),
8083 ],
8184 ),
8285 floatingActionButton: _createFab ()[_tabController.index],
@@ -120,8 +123,13 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage>
120123}
121124
122125class _GeneralConnectionSettingsView extends StatelessWidget {
123- final ExternalStorage storage;
124- const _GeneralConnectionSettingsView ({required this .storage});
126+ final String identifier;
127+ final bool isRemote;
128+
129+ const _GeneralConnectionSettingsView ({
130+ required this .identifier,
131+ required this .isRemote,
132+ });
125133
126134 @override
127135 Widget build (BuildContext context) {
@@ -143,27 +151,26 @@ class _GeneralConnectionSettingsView extends StatelessWidget {
143151 style: TextTheme .of (context).headlineSmall,
144152 ),
145153 const SizedBox (height: 16 ),
146- if (storage is RemoteStorage ) ...[
154+ if (isRemote ) ...[
147155 BlocBuilder <SettingsCubit , ButterflySettings >(
148156 builder: (context, state) {
149157 final storage =
150- state.getRemote (this .storage.identifier)
151- as RemoteStorage ? ;
158+ state.getRemote (identifier) as RemoteStorage ? ;
159+ final isRootCached =
160+ storage? .cachedDocuments['' ]? .contains ('/' ) ??
161+ false ;
152162 return CheckboxListTile (
153- value:
154- storage? .cachedDocuments['' ]? .contains ('/' ) ??
155- false ,
163+ value: isRootCached,
156164 onChanged: (value) {
157165 if (storage == null ) return ;
158- if (storage.cachedDocuments['' ]? .contains ('/' ) ??
159- false ) {
166+ if (isRootCached) {
160167 context.read <SettingsCubit >().removeCache (
161- storage. identifier,
168+ identifier,
162169 '/' ,
163170 );
164171 } else {
165172 context.read <SettingsCubit >().addCache (
166- storage. identifier,
173+ identifier,
167174 '/' ,
168175 );
169176 }
@@ -181,17 +188,15 @@ class _GeneralConnectionSettingsView extends StatelessWidget {
181188 title: Text (AppLocalizations .of (context).clearCaches),
182189 leading: const PhosphorIcon (PhosphorIconsLight .fileX),
183190 onTap: () {
184- context.read <SettingsCubit >().clearCaches (storage );
191+ context.read <SettingsCubit >().clearCaches (identifier );
185192 },
186193 ),
187194 ],
188195 ListTile (
189196 title: Text (AppLocalizations .of (context).delete),
190197 leading: const PhosphorIcon (PhosphorIconsLight .trash),
191198 onTap: () {
192- context.read <SettingsCubit >().deleteRemote (
193- storage.identifier,
194- );
199+ context.read <SettingsCubit >().deleteRemote (identifier);
195200 GoRouter .of (context).pop ();
196201 },
197202 ),
@@ -207,35 +212,43 @@ class _GeneralConnectionSettingsView extends StatelessWidget {
207212}
208213
209214class _CachesConnectionSettingsView extends StatelessWidget {
210- final RemoteStorage storage;
211- const _CachesConnectionSettingsView ({required this .storage});
215+ final String identifier;
216+
217+ const _CachesConnectionSettingsView ({required this .identifier});
212218
213219 @override
214220 Widget build (BuildContext context) {
215221 return BlocBuilder <SettingsCubit , ButterflySettings >(
216222 builder: (context, state) {
223+ final storage = state.getRemote (identifier);
224+ if (storage == null || storage is ! RemoteStorage ) {
225+ return Center (child: Text (AppLocalizations .of (context).noElements));
226+ }
227+ final cached = storage.cachedDocuments['' ] ?? < String > [];
217228 return Align (
218229 alignment: Alignment .center,
219230 child: ConstrainedBox (
220231 constraints: const BoxConstraints (
221232 maxWidth: LeapBreakpoints .compact,
222233 ),
223- child: ListView .builder (
224- itemCount: storage.cachedDocuments['' ]? .length,
225- itemBuilder: (context, index) {
226- final current = storage.cachedDocuments['' ]! [index];
227- return Dismissible (
228- key: Key (current),
229- onDismissed: (_) {
230- context.read <SettingsCubit >().removeCache (
231- storage.identifier,
232- current,
233- );
234- },
235- child: ListTile (title: Text (current)),
236- );
237- },
238- ),
234+ child: cached.isEmpty
235+ ? Text (AppLocalizations .of (context).noElements)
236+ : ListView .builder (
237+ itemCount: cached.length,
238+ itemBuilder: (context, index) {
239+ final current = cached[index];
240+ return Dismissible (
241+ key: Key (current),
242+ onDismissed: (_) {
243+ context.read <SettingsCubit >().removeCache (
244+ storage.identifier,
245+ current,
246+ );
247+ },
248+ child: ListTile (title: Text (current)),
249+ );
250+ },
251+ ),
239252 ),
240253 );
241254 },
0 commit comments