-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: server config modifier dialog (indev)
- Loading branch information
Showing
11 changed files
with
527 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2025 Fries_I23 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:uuid/uuid.dart'; | ||
|
||
import '../logging/helper.dart'; | ||
import '../model/app_sync_server.dart'; | ||
import 'commons.dart'; | ||
|
||
class AppSyncServerFormViewModel extends ChangeNotifier | ||
implements ProviderMounted { | ||
final AppSyncServer? initServerConfig; | ||
|
||
bool _mounted = true; | ||
AppSyncServer? _crtServerConfig; | ||
|
||
late AppSyncServerForm _form; | ||
|
||
AppSyncServerFormViewModel({ | ||
this.initServerConfig, | ||
}) { | ||
_form = initServerConfig?.toForm() ?? getDefaultForm(); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
if (!_mounted) return; | ||
super.dispose(); | ||
_mounted = false; | ||
} | ||
|
||
@override | ||
bool get mounted => _mounted; | ||
|
||
AppSyncServerForm getDefaultForm() => | ||
AppWebDavSyncServer.newServer(identity: const Uuid().v4(), path: '') | ||
.toForm(); | ||
|
||
AppSyncServer? get crtServerConfig => initServerConfig ?? _crtServerConfig; | ||
|
||
void updateCrtServerConfig(AppSyncServer? newConfig) { | ||
if (newConfig != crtServerConfig) { | ||
appLog.load.info("$runtimeType.updateCrtServerConfig", ex: [newConfig]); | ||
_crtServerConfig = newConfig; | ||
notifyListeners(); | ||
} | ||
} | ||
|
||
AppSyncServerType get type => _form.type; | ||
set type(AppSyncServerType value) { | ||
if (type == value) return; | ||
_form = value != crtServerConfig?.type | ||
? AppSyncServer.newServer(value)?.toForm() ?? getDefaultForm() | ||
: crtServerConfig!.toForm(); | ||
notifyListeners(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright 2025 Fries_I23 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
import '../../common/consts.dart'; | ||
|
||
enum UiLayoutType { | ||
/// Small | ||
s(0), | ||
|
||
/// Large | ||
l(10); | ||
|
||
final int value; | ||
|
||
const UiLayoutType(this.value); | ||
} | ||
|
||
class AppUiLayoutBuilder extends StatelessWidget { | ||
final Widget? child; | ||
final bool ignoreWidth; | ||
final bool ignoreHeight; | ||
final UiLayoutType defaultUiType; | ||
final Widget Function( | ||
BuildContext context, | ||
UiLayoutType layoutType, | ||
Widget? child, | ||
) builder; | ||
|
||
const AppUiLayoutBuilder({ | ||
super.key, | ||
this.ignoreHeight = true, | ||
this.ignoreWidth = false, | ||
this.defaultUiType = UiLayoutType.s, | ||
this.child, | ||
required this.builder, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) => LayoutBuilder( | ||
builder: (context, constraints) { | ||
final isWidthLarger = | ||
constraints.maxWidth >= kHabitLargeScreenAdaptWidth; | ||
final isHeightLarger = | ||
constraints.maxHeight >= kHabitLargeScreenAdaptHeight; | ||
|
||
if (ignoreWidth && ignoreHeight) { | ||
return builder(context, defaultUiType, child); | ||
} else if (ignoreWidth) { | ||
return builder( | ||
context, | ||
isHeightLarger ? UiLayoutType.l : UiLayoutType.s, | ||
child, | ||
); | ||
} else if (ignoreHeight) { | ||
return builder( | ||
context, | ||
isWidthLarger ? UiLayoutType.l : UiLayoutType.s, | ||
child, | ||
); | ||
} else { | ||
return builder( | ||
context, | ||
isWidthLarger && isHeightLarger ? UiLayoutType.l : UiLayoutType.s, | ||
child, | ||
); | ||
} | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2025 Fries_I23 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
export './app_sync_server_type.dart'; | ||
export './page_providers.dart'; |
52 changes: 52 additions & 0 deletions
52
lib/view/for_app_sync_server_editor/app_sync_server_type.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2025 Fries_I23 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
import '../../l10n/localizations.g.dart'; | ||
import '../../model/app_sync_server.dart'; | ||
import '../../provider/app_sync_server_form.dart'; | ||
|
||
class AppSyncServerTypeMenu extends StatelessWidget { | ||
final double? width; | ||
|
||
const AppSyncServerTypeMenu({super.key, this.width}); | ||
|
||
String getName(AppSyncServerType type, [L10n? l10n]) { | ||
switch (type) { | ||
case AppSyncServerType.webdav: | ||
return 'WebDAV'; | ||
default: | ||
return 'Unknown'; | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final l10n = L10n.of(context); | ||
return DropdownMenu<AppSyncServerType>( | ||
width: width, | ||
enableSearch: false, | ||
requestFocusOnTap: false, | ||
initialSelection: context.watch<AppSyncServerFormViewModel>().type, | ||
dropdownMenuEntries: AppSyncServerType.values | ||
.where((e) => e != AppSyncServerType.unknown) | ||
.map((e) => DropdownMenuEntry(value: e, label: getName(e, l10n))) | ||
.toList(), | ||
onSelected: (value) => | ||
context.read<AppSyncServerFormViewModel>().type = value!, | ||
); | ||
} | ||
} |
Oops, something went wrong.