[mob] fix UI of toggle widget on iOS
This commit is contained in:
parent
372ced2502
commit
2c0148d661
3 changed files with 89 additions and 79 deletions
|
@ -474,7 +474,7 @@ SPEC CHECKSUMS:
|
|||
Toast: 1f5ea13423a1e6674c4abdac5be53587ae481c4e
|
||||
uni_links: d97da20c7701486ba192624d99bffaaffcfc298a
|
||||
url_launcher_ios: 6116280ddcfe98ab8820085d8d76ae7449447586
|
||||
video_player_avfoundation: 02011213dab73ae3687df27ce441fbbcc82b5579
|
||||
video_player_avfoundation: 2b4384f3b157206b5e150a0083cdc0c905d260d3
|
||||
video_thumbnail: c4e2a3c539e247d4de13cd545344fd2d26ffafd1
|
||||
volume_controller: 531ddf792994285c9b17f9d8a7e4dcdd29b3eae9
|
||||
wakelock_plus: 8b09852c8876491e4b6d179e17dfe2a0b5f60d47
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import "dart:io";
|
||||
|
||||
import "package:flutter/cupertino.dart";
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:photos/ente_theme_data.dart';
|
||||
import 'package:photos/models/execution_states.dart';
|
||||
|
@ -49,59 +52,23 @@ class _ToggleSwitchWidgetState extends State<ToggleSwitchWidget> {
|
|||
height: 31,
|
||||
child: FittedBox(
|
||||
fit: BoxFit.contain,
|
||||
child: Switch.adaptive(
|
||||
inactiveTrackColor: Colors.transparent,
|
||||
activeTrackColor: enteColorScheme.primary500,
|
||||
activeColor: Colors.white,
|
||||
inactiveThumbColor: enteColorScheme.primary500,
|
||||
trackOutlineColor: MaterialStateColor.resolveWith(
|
||||
(states) => enteColorScheme.primary500,
|
||||
),
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
value: toggleValue ?? false,
|
||||
onChanged: (negationOfToggleValue) async {
|
||||
setState(() {
|
||||
toggleValue = negationOfToggleValue;
|
||||
//start showing inProgress statu icons if toggle takes more than debounce time
|
||||
_debouncer.run(
|
||||
() => Future(
|
||||
() {
|
||||
setState(() {
|
||||
executionState = ExecutionState.inProgress;
|
||||
});
|
||||
},
|
||||
child: Platform.isAndroid
|
||||
? Switch(
|
||||
inactiveTrackColor: Colors.transparent,
|
||||
activeTrackColor: enteColorScheme.primary500,
|
||||
activeColor: Colors.white,
|
||||
inactiveThumbColor: enteColorScheme.primary500,
|
||||
trackOutlineColor: MaterialStateColor.resolveWith(
|
||||
(states) => enteColorScheme.primary500,
|
||||
),
|
||||
);
|
||||
});
|
||||
final Stopwatch stopwatch = Stopwatch()..start();
|
||||
await widget.onChanged.call().onError(
|
||||
(error, stackTrace) => _debouncer.cancelDebounce(),
|
||||
);
|
||||
//for toggle feedback on short unsuccessful onChanged
|
||||
await _feedbackOnUnsuccessfulToggle(stopwatch);
|
||||
//debouncer gets canceled if onChanged takes less than debounce time
|
||||
_debouncer.cancelDebounce();
|
||||
|
||||
final newValue = widget.value.call();
|
||||
setState(() {
|
||||
if (toggleValue == newValue) {
|
||||
if (executionState == ExecutionState.inProgress) {
|
||||
executionState = ExecutionState.successful;
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
executionState = ExecutionState.idle;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
toggleValue = !toggleValue!;
|
||||
executionState = ExecutionState.idle;
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
value: toggleValue ?? false,
|
||||
onChanged: onChanged,
|
||||
)
|
||||
: CupertinoSwitch(
|
||||
value: toggleValue ?? false,
|
||||
onChanged: onChanged,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
@ -137,4 +104,47 @@ class _ToggleSwitchWidgetState extends State<ToggleSwitchWidget> {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> onChanged(bool negationOfToggleValue) async {
|
||||
setState(() {
|
||||
toggleValue = negationOfToggleValue;
|
||||
//start showing inProgress statu icons if toggle takes more than debounce time
|
||||
_debouncer.run(
|
||||
() => Future(
|
||||
() {
|
||||
setState(() {
|
||||
executionState = ExecutionState.inProgress;
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
});
|
||||
final Stopwatch stopwatch = Stopwatch()..start();
|
||||
await widget.onChanged.call().onError(
|
||||
(error, stackTrace) => _debouncer.cancelDebounce(),
|
||||
);
|
||||
//for toggle feedback on short unsuccessful onChanged
|
||||
await _feedbackOnUnsuccessfulToggle(stopwatch);
|
||||
//debouncer gets canceled if onChanged takes less than debounce time
|
||||
_debouncer.cancelDebounce();
|
||||
|
||||
final newValue = widget.value.call();
|
||||
setState(() {
|
||||
if (toggleValue == newValue) {
|
||||
if (executionState == ExecutionState.inProgress) {
|
||||
executionState = ExecutionState.successful;
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
executionState = ExecutionState.idle;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
toggleValue = !toggleValue!;
|
||||
executionState = ExecutionState.idle;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,10 +77,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: args
|
||||
sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596
|
||||
sha256: "7cf60b9f0cc88203c5a190b4cd62a99feea42759a7fa695010eb5de1c0b2252a"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.2"
|
||||
version: "2.5.0"
|
||||
async:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -814,10 +814,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: flutter_plugin_android_lifecycle
|
||||
sha256: "592dc01a18961a51c24ae5d963b724b2b7fa4a95c100fe8eb6ca8a5a4732cadf"
|
||||
sha256: "8cf40eebf5dec866a6d1956ad7b4f7016e6c0cc69847ab946833b7d43743809f"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.18"
|
||||
version: "2.0.19"
|
||||
flutter_secure_storage:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -920,10 +920,10 @@ packages:
|
|||
dependency: "direct dev"
|
||||
description:
|
||||
name: freezed
|
||||
sha256: "91bce569d4805ea5bad6619a3e8690df8ad062a235165af4c0c5d928dda15eaf"
|
||||
sha256: a434911f643466d78462625df76fd9eb13e57348ff43fe1f77bbe909522c67a1
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.5.1"
|
||||
version: "2.5.2"
|
||||
freezed_annotation:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -1061,10 +1061,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: image_editor_ohos
|
||||
sha256: "55c08871814efdd19b3927327b5913649dd1ea36e0a83aa77ab668dad3160dcc"
|
||||
sha256: aee8fa1490fedbb98583dfaebb4162c295abeb0044e94f2eb2ad52ae419e6f6e
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.0.6"
|
||||
version: "0.0.7"
|
||||
image_editor_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -1085,10 +1085,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: in_app_purchase_android
|
||||
sha256: "6863bf74335ccbd80829e8c3d16176f90794f0f8593a4505a7ab79d17334a0bf"
|
||||
sha256: b9d4ecf70c51ab46222502c050b1535f6249caf9d768c4abd856ea16a18a882d
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.3.3"
|
||||
version: "0.3.3+1"
|
||||
in_app_purchase_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -1549,18 +1549,18 @@ packages:
|
|||
dependency: "direct main"
|
||||
description:
|
||||
name: path_provider
|
||||
sha256: b27217933eeeba8ff24845c34003b003b2b22151de3c908d0e679e8fe1aa078b
|
||||
sha256: c9e7d3a4cd1410877472158bee69963a4579f78b68c65a2b7d40d1a7a88bb161
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.2"
|
||||
version: "2.1.3"
|
||||
path_provider_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_android
|
||||
sha256: "51f0d2c554cfbc9d6a312ab35152fc77e2f0b758ce9f1a444a3a1e5b8f3c6b7f"
|
||||
sha256: a248d8146ee5983446bf03ed5ea8f6533129a12b11f12057ad1b4a67a2b3b41d
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.3"
|
||||
version: "2.2.4"
|
||||
path_provider_foundation:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -1933,18 +1933,18 @@ packages:
|
|||
dependency: "direct main"
|
||||
description:
|
||||
name: shared_preferences
|
||||
sha256: "81429e4481e1ccfb51ede496e916348668fd0921627779233bd24cc3ff6abd02"
|
||||
sha256: d3bbe5553a986e83980916ded2f0b435ef2e1893dfaa29d5a7a790d0eca12180
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.2"
|
||||
version: "2.2.3"
|
||||
shared_preferences_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_android
|
||||
sha256: "8568a389334b6e83415b6aae55378e158fbc2314e074983362d20c562780fb06"
|
||||
sha256: "1ee8bf911094a1b592de7ab29add6f826a7331fb854273d55918693d5364a1f2"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.1"
|
||||
version: "2.2.2"
|
||||
shared_preferences_foundation:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -2330,18 +2330,18 @@ packages:
|
|||
dependency: "direct main"
|
||||
description:
|
||||
name: url_launcher
|
||||
sha256: "0ecc004c62fd3ed36a2ffcbe0dd9700aee63bd7532d0b642a488b1ec310f492e"
|
||||
sha256: "6ce1e04375be4eed30548f10a315826fd933c1e493206eab82eed01f438c8d2e"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.2.5"
|
||||
version: "6.2.6"
|
||||
url_launcher_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_android
|
||||
sha256: d4ed0711849dd8e33eb2dd69c25db0d0d3fdc37e0a62e629fe32f57a22db2745
|
||||
sha256: "360a6ed2027f18b73c8d98e159dda67a61b7f2e0f6ec26e86c3ada33b0621775"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.3.0"
|
||||
version: "6.3.1"
|
||||
url_launcher_ios:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -2419,18 +2419,18 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: video_player_android
|
||||
sha256: "4dd9b8b86d70d65eecf3dcabfcdfbb9c9115d244d022654aba49a00336d540c2"
|
||||
sha256: "821cff3446bbde255e8d03c12fe1f9810c69fee2c26c394545b13d824ba63c2e"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.12"
|
||||
version: "2.4.13"
|
||||
video_player_avfoundation:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: video_player_avfoundation
|
||||
sha256: "309e3962795e761be010869bae65c0b0e45b5230c5cee1bec72197ca7db040ed"
|
||||
sha256: "00c49b1d68071341397cf760b982c1e26ed9232464c8506ee08378a5cca5070d"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.5.6"
|
||||
version: "2.5.7"
|
||||
video_player_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
Loading…
Add table
Reference in a new issue