WIP: something is going on

This commit is contained in:
Nikolai Rodionov 2024-04-04 16:35:33 +02:00
parent 3cc8edfc8c
commit 8e91619b47
Signed by: allanger
GPG Key ID: 0AA46A90E25592AD
7 changed files with 143 additions and 70 deletions

View File

@ -1,4 +1,7 @@
import 'dart:html';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:softplayer_web/components/sign_in_form.dart';
/// Flutter code sample for [AppBar]. /// Flutter code sample for [AppBar].
@ -15,6 +18,30 @@ class MenuPanel extends StatefulWidget implements PreferredSizeWidget {
enum TabName { home, catalog, about } enum TabName { home, catalog, about }
class _MenuPanel extends State<MenuPanel> { class _MenuPanel extends State<MenuPanel> {
bool isSignedIn() {
return window.localStorage.containsKey("token");
}
List<Widget> accountActions() {
if (isSignedIn()) {
return [
IconButton(
onPressed: () => print("acc"),
icon: const Icon(Icons.account_circle))
];
} else {
return <Widget>[
TextButton(
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) => const SignInForm());
},
child: const Text("sign in")),
TextButton(onPressed: () => print("sign up"), child: const Text("sign up")),
];
}
}
final String linkCatalog = "catalog"; final String linkCatalog = "catalog";
final String linkAbout = "about"; final String linkAbout = "about";
final String linkHome = "home"; final String linkHome = "home";
@ -59,12 +86,9 @@ class _MenuPanel extends State<MenuPanel> {
Navigator.pushNamed(context, "/about"); Navigator.pushNamed(context, "/about");
}), }),
]), ]),
automaticallyImplyLeading: false,
actions: <Widget>[
IconButton(
onPressed: () => print("acc"), icon: const Icon(Icons.account_circle))
],
backgroundColor: Colors.cyan, backgroundColor: Colors.cyan,
automaticallyImplyLeading: false,
actions: accountActions(),
); );
} }
} }

View File

@ -0,0 +1,55 @@
import 'package:flutter/material.dart';
class SignInForm extends StatefulWidget {
const SignInForm({super.key});
@override
State<StatefulWidget> createState() => _SignInFormState();
}
class _SignInFormState extends State<SignInForm> {
final _formKey = GlobalKey<FormState>();
static const dialogName = "Sign In";
@override
Widget build(BuildContext context) => AlertDialog(
title: const Text(dialogName),
content: Form(
key: _formKey,
child: Center(
child: Column(children: [
TextFormField(
autofocus: true,
decoration: const InputDecoration(
hintText: "Enter your username or email",
icon: Icon(Icons.account_circle),
),
),
TextFormField(
obscureText: true,
decoration: const InputDecoration(
hintText: "Enter your password",
icon: Icon(Icons.password),
),
),
]))),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context, 'Cancel'),
child: const Text('Cancel'),
),
TextButton(
onPressed: () {
// Validate returns true if the form is valid, or false otherwise.
if (_formKey.currentState!.validate()) {
// If the form is valid, display a snackbar. In the real world,
// you'd often call a server or save the information in a database.
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(_formKey.toString())),
);
}
},
child: const Text('OK'),
),
],
);
}

View File

@ -0,0 +1,21 @@
import 'package:flutter/material.dart';
import 'package:softplayer_web/components/menubar.dart';
class PageWrapper extends StatelessWidget{
final Widget child;
final MenuPanel appBar;
const PageWrapper({
super.key,
required this.child,
required this.appBar
});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: appBar,
body: child,
);
}
}

View File

@ -1,54 +1,42 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:grpc/grpc_web.dart';
import 'package:softplayer_web/components/menubar.dart';
import 'package:softplayer_web/helpers/page_wrapper.dart';
import 'package:softplayer_web/pages/about.dart'; import 'package:softplayer_web/pages/about.dart';
import 'package:softplayer_web/pages/catalog.dart'; import 'package:softplayer_web/pages/catalog.dart';
import 'package:softplayer_web/pages/home.dart'; import 'package:softplayer_web/pages/home.dart';
// import 'package:grpc/grpc.dart';
// import 'package:softplayer_dart_proto/accounts/accounts_v1.pb.dart';
// import 'package:softplayer_dart_proto/main.dart';
// import 'package:grpc/grpc_web.dart';
void main() async { void main() async {
// GrpcWebClientChannel channel = GrpcWebClientChannel.xhr(Uri.parse('http://softplayer.badhouseplants.net:80')); const String backendURL = String.fromEnvironment(
// final stub = AccountsClient(channel); 'SOFTPLAYER_BACKEND_URL',
// final accWithPassword = AccountWithPassword( defaultValue: 'http://softplayer.badhouseplants.net:8080',
// data: AccountData( );
// name: "test", GrpcWebClientChannel grpcChannel = GrpcWebClientChannel.xhr(Uri.parse(backendURL));
// email: "test@test.test",
// ), runApp(MyApp(channel: grpcChannel));
// accountPassword: AccountPassword(password: "test"),
// );
//
// try {
// final response = await stub.signUp(
// accWithPassword,
// );
// print('Greeter client received: ${response}');
// } catch (e) {
// print('Caught error: $e');
// }
runApp(const MyApp());
} }
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
const MyApp({super.key}); const MyApp({super.key, required this.channel});
// This widget is the root of your application. // A channel that should be used to fire grpc calls
final GrpcWebClientChannel channel;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
title: 'Flutter Demo', title: 'Softplayer',
routes: { routes: {
'/': (context) => const HomePage(), '/': (context) => PageWrapper(
'/catalog': (context) => const CatalogPage(), child: HomePage(),
'/about': (context) => const AboutPage(), appBar: MenuPanel(tab: TabName.home),
),
}, },
theme: ThemeData( theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true, useMaterial3: true,
), ),
//home: const MyHomePage(title: 'Flutter Demo Home Page'),
); );
} }
} }

View File

@ -1,11 +1,16 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:grpc/grpc_web.dart';
import 'package:softplayer_web/api/third_party/chartmuseum.dart'; import 'package:softplayer_web/api/third_party/chartmuseum.dart';
import 'package:softplayer_web/components/catalog_card.dart'; import 'package:softplayer_web/components/catalog_card.dart';
import 'package:softplayer_web/components/menubar.dart'; import 'package:softplayer_web/components/menubar.dart';
import 'package:softplayer_web/models/catalog_entry.dart'; import 'package:softplayer_web/models/catalog_entry.dart';
class CatalogPage extends StatefulWidget { class CatalogPage extends StatefulWidget {
const CatalogPage({super.key}); final GrpcWebClientChannel grpcChannel;
const CatalogPage({
super.key,
required this.grpcChannel,
});
final String title = "catalog"; final String title = "catalog";
@override @override

View File

@ -1,45 +1,25 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:softplayer_web/components/menubar.dart';
class HomePage extends StatefulWidget { class HomePage extends StatefulWidget {
const HomePage({super.key}); const HomePage({super.key});
final String title = "home"; static String title = "home";
@override @override
State<HomePage> createState() => _HomePage(); State<HomePage> createState() => _HomePage();
} }
class _HomePage extends State<HomePage> { class _HomePage extends State<HomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return const Center(
appBar: const MenuPanel(tab: TabName.home),
body: Center(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
const Text( Text(
'You have pushed the button this many times:', 'You have pushed the button this many times:',
), ),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
], ],
), )
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.tv),
),
); );
} }
} }

View File

@ -85,10 +85,10 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
name: dio name: dio
sha256: "50fec96118958b97c727d0d8f67255d3683f16cc1f90d9bc917b5d4fe3abeca9" sha256: "0978e9a3e45305a80a7210dbeaf79d6ee8bee33f70c8e542dc654c952070217f"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "5.4.2" version: "5.4.2+1"
fake_async: fake_async:
dependency: transitive dependency: transitive
description: description:
@ -114,10 +114,10 @@ packages:
dependency: "direct dev" dependency: "direct dev"
description: description:
name: flutter_lints name: flutter_lints
sha256: e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7 sha256: "9e8c3858111da373efc5aa341de011d9bd23e2c5c5e0c62bccf32438e192d7b1"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "3.0.1" version: "3.0.2"
flutter_test: flutter_test:
dependency: "direct dev" dependency: "direct dev"
description: flutter description: flutter
@ -135,10 +135,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: googleapis_auth name: googleapis_auth
sha256: cafc46446574fd42826aa4cd4d623c94482598fda0a5a5649bf2781bcbc09258 sha256: "1401a9e55f9e0f565d3eebb18d990290f53a12d38a5f7f0230b112895778a85b"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.5.0" version: "1.5.1"
grpc: grpc:
dependency: "direct main" dependency: "direct main"
description: description:
@ -269,7 +269,7 @@ packages:
description: description:
path: "." path: "."
ref: main ref: main
resolved-ref: e13b14a448a17fb0d605a48597e3179fc0d2e196 resolved-ref: eb11f022be9c1fc5db6e87f3463a1ceb3e04501f
url: "https://git.badhouseplants.net/softplayer/softplayer-dart-proto.git" url: "https://git.badhouseplants.net/softplayer/softplayer-dart-proto.git"
source: git source: git
version: "1.0.0+1" version: "1.0.0+1"