mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-24 15:53:45 +08:00
Experiment more with grpc
Seems to be going well.
This commit is contained in:
56
lib/experiments/grpc_client.dart
Normal file
56
lib/experiments/grpc_client.dart
Normal file
@ -0,0 +1,56 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:grpc/grpc.dart';
|
||||
|
||||
import 'package:gitjournal/generated/shared_preferences.pb.dart';
|
||||
import 'package:gitjournal/generated/shared_preferences.pbgrpc.dart';
|
||||
|
||||
Future<void> main(List<String> args) async {
|
||||
return runApp(MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatefulWidget {
|
||||
@override
|
||||
_MyAppState createState() => _MyAppState();
|
||||
}
|
||||
|
||||
class _MyAppState extends State<MyApp> {
|
||||
var text = "Empty";
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_initAsync();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
void _initAsync() async {
|
||||
final channel = ClientChannel(
|
||||
'localhost',
|
||||
port: 50052,
|
||||
options: ChannelOptions(
|
||||
credentials: const ChannelCredentials.insecure(),
|
||||
codecRegistry:
|
||||
CodecRegistry(codecs: const [GzipCodec(), IdentityCodec()]),
|
||||
),
|
||||
);
|
||||
final stub = SharedPreferencesClient(channel);
|
||||
var keysResp = await stub.getKeys(EmptyMessage());
|
||||
setState(() {
|
||||
text = keysResp.value.toString();
|
||||
});
|
||||
await channel.shutdown();
|
||||
// todo: Catch exceptions!
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Welcome to Flutter',
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: Text(text),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,3 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'package:fixnum/fixnum.dart';
|
||||
import 'package:grpc/grpc.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
@ -83,14 +86,47 @@ class SharedPreferencesService extends SharedPreferencesServiceBase {
|
||||
}
|
||||
|
||||
Future<void> main(List<String> args) async {
|
||||
var pref = await SharedPreferences.getInstance();
|
||||
final server = Server(
|
||||
[SharedPreferencesService(pref)],
|
||||
const <Interceptor>[],
|
||||
CodecRegistry(codecs: const [GzipCodec(), IdentityCodec()]),
|
||||
);
|
||||
await server.serve(port: 50051);
|
||||
print('Server listening on port ${server.port}...');
|
||||
return runApp(MyApp());
|
||||
}
|
||||
|
||||
// todo: Create some kind of QR code for getting the URL
|
||||
// todo: Create some kind of QR code for getting the IP and hostname
|
||||
|
||||
class MyApp extends StatefulWidget {
|
||||
@override
|
||||
_MyAppState createState() => _MyAppState();
|
||||
}
|
||||
|
||||
class _MyAppState extends State<MyApp> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_initAsync();
|
||||
}
|
||||
|
||||
void _initAsync() async {
|
||||
var pref = await SharedPreferences.getInstance();
|
||||
final server = Server(
|
||||
[SharedPreferencesService(pref)],
|
||||
const <Interceptor>[],
|
||||
CodecRegistry(codecs: const [GzipCodec(), IdentityCodec()]),
|
||||
);
|
||||
await server.serve(port: 50052);
|
||||
print('Server listening on port ${server.port}...');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Welcome to Flutter',
|
||||
home: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Welcome to Flutter'),
|
||||
),
|
||||
body: const Center(
|
||||
child: Text('Hello World'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
PODS:
|
||||
- connectivity_macos (0.0.1):
|
||||
- connectivity_plus_macos (0.0.1):
|
||||
- FlutterMacOS
|
||||
- Reachability
|
||||
- device_info_plus_macos (0.0.1):
|
||||
@ -20,6 +20,8 @@ PODS:
|
||||
- Flutter
|
||||
- FlutterMacOS
|
||||
- Sentry (~> 7.1.3)
|
||||
- share_plus_macos (0.0.1):
|
||||
- FlutterMacOS
|
||||
- shared_preferences_macos (0.0.1):
|
||||
- FlutterMacOS
|
||||
- sqflite (0.0.2):
|
||||
@ -29,12 +31,13 @@ PODS:
|
||||
- FlutterMacOS
|
||||
|
||||
DEPENDENCIES:
|
||||
- connectivity_macos (from `Flutter/ephemeral/.symlinks/plugins/connectivity_macos/macos`)
|
||||
- connectivity_plus_macos (from `Flutter/ephemeral/.symlinks/plugins/connectivity_plus_macos/macos`)
|
||||
- device_info_plus_macos (from `Flutter/ephemeral/.symlinks/plugins/device_info_plus_macos/macos`)
|
||||
- FlutterMacOS (from `Flutter/ephemeral`)
|
||||
- package_info_plus_macos (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus_macos/macos`)
|
||||
- path_provider_macos (from `Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos`)
|
||||
- sentry_flutter (from `Flutter/ephemeral/.symlinks/plugins/sentry_flutter/macos`)
|
||||
- share_plus_macos (from `Flutter/ephemeral/.symlinks/plugins/share_plus_macos/macos`)
|
||||
- shared_preferences_macos (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_macos/macos`)
|
||||
- sqflite (from `Flutter/ephemeral/.symlinks/plugins/sqflite/macos`)
|
||||
- url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`)
|
||||
@ -46,8 +49,8 @@ SPEC REPOS:
|
||||
- Sentry
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
connectivity_macos:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/connectivity_macos/macos
|
||||
connectivity_plus_macos:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/connectivity_plus_macos/macos
|
||||
device_info_plus_macos:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/device_info_plus_macos/macos
|
||||
FlutterMacOS:
|
||||
@ -58,6 +61,8 @@ EXTERNAL SOURCES:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos
|
||||
sentry_flutter:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/sentry_flutter/macos
|
||||
share_plus_macos:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/share_plus_macos/macos
|
||||
shared_preferences_macos:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/shared_preferences_macos/macos
|
||||
sqflite:
|
||||
@ -66,7 +71,7 @@ EXTERNAL SOURCES:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
connectivity_macos: 9f30e9d0e67a0bc08a0c563ee82310b51ca6e818
|
||||
connectivity_plus_macos: 3da1605dc99d44cf06fb6852de4ed26ecef3cabc
|
||||
device_info_plus_macos: 1ad388a1ef433505c4038e7dd9605aadd1e2e9c7
|
||||
FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424
|
||||
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
|
||||
@ -75,6 +80,7 @@ SPEC CHECKSUMS:
|
||||
Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96
|
||||
Sentry: 6d963d64804dd06d96e778be729613f481394312
|
||||
sentry_flutter: f20d4f199442900fbdab2b8496f1d2091d8b94d9
|
||||
share_plus_macos: 853ee48e7dce06b633998ca0735d482dd671ade4
|
||||
shared_preferences_macos: 480ce071d0666e37cef23fe6c702293a3d21799e
|
||||
sqflite: a5789cceda41d54d23f31d6de539d65bb14100ea
|
||||
url_launcher_macos: 45af3d61de06997666568a7149c1be98b41c95d4
|
||||
|
Reference in New Issue
Block a user