Start writing the web app
All checks were successful
ci/woodpecker/push/build Pipeline was successful
All checks were successful
ci/woodpecker/push/build Pipeline was successful
Signed-off-by: Nikolai Rodionov <allanger@posteo.com>
This commit was merged in pull request #5.
This commit is contained in:
28
lib/features/test/application/test_controller.dart
Normal file
28
lib/features/test/application/test_controller.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:softplayer_web/core/api/v1/test.dart';
|
||||
import 'package:softplayer_web/core/tokens/application/tokens_application.dart';
|
||||
|
||||
final pingControllerProvider = AsyncNotifierProvider<PingController, String>(
|
||||
PingController.new,
|
||||
);
|
||||
|
||||
class PingController extends AsyncNotifier<String> {
|
||||
@override
|
||||
Future<String> build() async {
|
||||
return 'Idle';
|
||||
}
|
||||
|
||||
Future<void> ping() async {
|
||||
state = const AsyncLoading();
|
||||
|
||||
state = await AsyncValue.guard(() async {
|
||||
final testGrpc = ref.read(testGrpcProvider);
|
||||
final tokenCtrl = ref.read(tokensControllerProvider.notifier);
|
||||
await tokenCtrl.checkTokens();
|
||||
|
||||
await testGrpc.pong();
|
||||
|
||||
return 'Ping successful';
|
||||
});
|
||||
}
|
||||
}
|
||||
30
lib/features/test/presentation/ping_page.dart
Normal file
30
lib/features/test/presentation/ping_page.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../application/test_controller.dart';
|
||||
|
||||
class PingPage extends ConsumerWidget {
|
||||
const PingPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final state = ref.watch(pingControllerProvider);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('gRPC Ping')),
|
||||
body: Center(
|
||||
child: state.when(
|
||||
data: (value) => Text(value),
|
||||
loading: () => const CircularProgressIndicator(),
|
||||
error: (e, _) => Text('Error: $e'),
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () {
|
||||
ref.read(pingControllerProvider.notifier).ping();
|
||||
},
|
||||
child: const Icon(Icons.send),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user