mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
add more js api & improve ui
This commit is contained in:
@@ -116,10 +116,10 @@ abstract class LoadingState<T extends StatefulWidget, S extends Object>
|
||||
});
|
||||
loadData().then((value) async {
|
||||
if (value.success) {
|
||||
data = value.data;
|
||||
await onDataLoaded();
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
data = value.data;
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
@@ -131,22 +131,10 @@ abstract class LoadingState<T extends StatefulWidget, S extends Object>
|
||||
}
|
||||
|
||||
Widget buildError() {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
error!,
|
||||
maxLines: 3,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Button.text(
|
||||
onPressed: retry,
|
||||
child: const Text("Retry"),
|
||||
)
|
||||
],
|
||||
),
|
||||
).paddingHorizontal(16);
|
||||
return NetworkError(
|
||||
message: error!,
|
||||
retry: retry,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -154,11 +142,12 @@ abstract class LoadingState<T extends StatefulWidget, S extends Object>
|
||||
void initState() {
|
||||
isLoading = true;
|
||||
Future.microtask(() {
|
||||
loadData().then((value) {
|
||||
loadData().then((value) async {
|
||||
if (value.success) {
|
||||
data = value.data;
|
||||
await onDataLoaded();
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
data = value.data;
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
|
@@ -295,20 +295,21 @@ class ContentDialog extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
void showInputDialog({
|
||||
Future<void> showInputDialog({
|
||||
required BuildContext context,
|
||||
required String title,
|
||||
required String hintText,
|
||||
String? hintText,
|
||||
required FutureOr<Object?> Function(String) onConfirm,
|
||||
String? initialValue,
|
||||
String confirmText = "Confirm",
|
||||
String cancelText = "Cancel",
|
||||
RegExp? inputValidator,
|
||||
}) {
|
||||
var controller = TextEditingController(text: initialValue);
|
||||
bool isLoading = false;
|
||||
String? error;
|
||||
|
||||
showDialog(
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return StatefulBuilder(
|
||||
@@ -327,6 +328,11 @@ void showInputDialog({
|
||||
Button.filled(
|
||||
isLoading: isLoading,
|
||||
onPressed: () async {
|
||||
if (inputValidator != null &&
|
||||
!inputValidator.hasMatch(controller.text)) {
|
||||
setState(() => error = "Invalid input");
|
||||
return;
|
||||
}
|
||||
var futureOr = onConfirm(controller.text);
|
||||
Object? result;
|
||||
if (futureOr is Future) {
|
||||
|
@@ -1,7 +1,8 @@
|
||||
part of 'components.dart';
|
||||
|
||||
class SmoothCustomScrollView extends StatelessWidget {
|
||||
const SmoothCustomScrollView({super.key, required this.slivers, this.controller});
|
||||
const SmoothCustomScrollView(
|
||||
{super.key, required this.slivers, this.controller});
|
||||
|
||||
final ScrollController? controller;
|
||||
|
||||
@@ -22,9 +23,9 @@ class SmoothCustomScrollView extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class SmoothScrollProvider extends StatefulWidget {
|
||||
const SmoothScrollProvider({super.key, this.controller, required this.builder});
|
||||
const SmoothScrollProvider(
|
||||
{super.key, this.controller, required this.builder});
|
||||
|
||||
final ScrollController? controller;
|
||||
|
||||
@@ -51,7 +52,7 @@ class _SmoothScrollProviderState extends State<SmoothScrollProvider> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if(App.isMacOS) {
|
||||
if (App.isMacOS) {
|
||||
return widget.builder(
|
||||
context,
|
||||
_controller,
|
||||
@@ -77,13 +78,15 @@ class _SmoothScrollProviderState extends State<SmoothScrollProvider> {
|
||||
}
|
||||
if (!_isMouseScroll) return;
|
||||
var currentLocation = _controller.position.pixels;
|
||||
var old = _futurePosition;
|
||||
_futurePosition ??= currentLocation;
|
||||
double k = (_futurePosition! - currentLocation).abs() / 1600 + 1;
|
||||
_futurePosition =
|
||||
_futurePosition! + pointerSignal.scrollDelta.dy * k;
|
||||
_futurePosition = _futurePosition! + pointerSignal.scrollDelta.dy * k;
|
||||
_futurePosition = _futurePosition!.clamp(
|
||||
_controller.position.minScrollExtent,
|
||||
_controller.position.maxScrollExtent);
|
||||
_controller.position.minScrollExtent,
|
||||
_controller.position.maxScrollExtent,
|
||||
);
|
||||
if(_futurePosition == old) return;
|
||||
_controller.animateTo(_futurePosition!,
|
||||
duration: _fastAnimationDuration, curve: Curves.linear);
|
||||
}
|
||||
|
Reference in New Issue
Block a user