77 lines
2.1 KiB
Dart
77 lines
2.1 KiB
Dart
import 'dart:html';
|
|
|
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:grpc/grpc_web.dart';
|
|
import 'package:softplayer_web/api/grpc/accounts.dart';
|
|
import 'package:softplayer_web/components/login_form.dart';
|
|
|
|
void main() async {
|
|
await dotenv.load(fileName: ".env");
|
|
String backendURL = dotenv.env['SOFTPLAYER_BACKEND_URL']!;
|
|
GrpcWebClientChannel grpcChannel =
|
|
GrpcWebClientChannel.xhr(Uri.parse(backendURL));
|
|
|
|
runApp(MyApp(channel: grpcChannel));
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
MyApp({super.key, required this.channel});
|
|
final GrpcWebClientChannel channel;
|
|
late final AccountsGrpc accountsGrpc = AccountsGrpc(channel: channel);
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
accountsGrpc.init();
|
|
return MaterialApp(
|
|
debugShowCheckedModeBanner: false,
|
|
title: 'Softplayer',
|
|
home: RootWidget(channel: channel),
|
|
theme: ThemeData(
|
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
|
useMaterial3: true,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class RootWidget extends StatefulWidget {
|
|
final GrpcWebClientChannel channel;
|
|
|
|
RootWidget({super.key, required this.channel});
|
|
late final AccountsGrpc accountsGrpc = AccountsGrpc(channel: channel);
|
|
|
|
@override
|
|
@override
|
|
State<StatefulWidget> createState() => _StateRootWidget();
|
|
}
|
|
|
|
class _StateRootWidget extends State<RootWidget> {
|
|
refresh() {
|
|
setState(() {});
|
|
}
|
|
|
|
bool isSignedIn() {
|
|
return window.localStorage.containsKey("token");
|
|
}
|
|
|
|
final GlobalKey<ScaffoldState> _key = GlobalKey(); // Create a key
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: Container(
|
|
width: double.infinity,
|
|
height: double.infinity,
|
|
decoration: const BoxDecoration(
|
|
image: DecorationImage(
|
|
image: AssetImage("assets/login_background.jpg"),
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
child: LoginForm(
|
|
grpcChannel: widget.channel,
|
|
notifyParent: refresh,
|
|
)));
|
|
}
|
|
}
|