softplayer-web/lib/main.dart

70 lines
2.0 KiB
Dart
Raw Normal View History

2024-04-19 11:19:44 +00:00
import 'dart:html';
2024-03-21 08:39:25 +00:00
import 'package:flutter/material.dart';
2024-04-04 14:35:33 +00:00
import 'package:grpc/grpc_web.dart';
2024-04-05 15:14:56 +00:00
import 'package:softplayer_web/api/grpc/accounts.dart';
2024-04-19 11:19:44 +00:00
import 'package:softplayer_web/components/environments.dart';
import 'package:softplayer_web/components/login_form.dart';
2024-03-21 08:39:25 +00:00
void main() async {
2024-04-04 14:35:33 +00:00
const String backendURL = String.fromEnvironment(
'SOFTPLAYER_BACKEND_URL',
2024-04-05 15:14:56 +00:00
defaultValue: 'https://softplayer-backend.badhouseplants.net:8080',
2024-04-04 14:35:33 +00:00
);
2024-04-04 16:15:30 +00:00
GrpcWebClientChannel grpcChannel =
GrpcWebClientChannel.xhr(Uri.parse(backendURL));
2024-04-04 14:35:33 +00:00
runApp(MyApp(channel: grpcChannel));
2024-03-21 08:39:25 +00:00
}
class MyApp extends StatelessWidget {
2024-04-05 15:14:56 +00:00
MyApp({super.key, required this.channel});
2024-04-04 14:35:33 +00:00
final GrpcWebClientChannel channel;
2024-04-05 15:14:56 +00:00
late final AccountsGrpc accountsGrpc = AccountsGrpc(channel: channel);
2024-03-21 08:39:25 +00:00
@override
Widget build(BuildContext context) {
2024-04-05 15:14:56 +00:00
accountsGrpc.init();
2024-03-21 08:39:25 +00:00
return MaterialApp(
2024-03-26 16:17:04 +00:00
debugShowCheckedModeBanner: false,
2024-04-04 14:35:33 +00:00
title: 'Softplayer',
2024-04-19 11:19:44 +00:00
home: Scaffold(
body: TestAlert(channel: channel),
appBar: AppBar(),
floatingActionButton: FloatingActionButton(
onPressed: () => print("1"),
),
),
2024-03-21 08:39:25 +00:00
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
);
}
}
2024-04-19 11:19:44 +00:00
class TestAlert extends StatelessWidget {
final GrpcWebClientChannel channel;
TestAlert({super.key, required this.channel});
late final AccountsGrpc accountsGrpc = AccountsGrpc(channel: channel);
bool isSignedIn() {
return window.localStorage.containsKey("token");
}
@override
Widget build(BuildContext context) {
if (!isSignedIn()) {
return Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/login_background.jpg"),
fit: BoxFit.fill,
),
),
child: LoginForm(grpcChannel: channel),
);
} else {
return EnvirnomentList(channel: channel);
}
}
}