WIP: something is going on
This commit is contained in:
@ -1,4 +1,7 @@
|
||||
import 'dart:html';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:softplayer_web/components/sign_in_form.dart';
|
||||
|
||||
/// Flutter code sample for [AppBar].
|
||||
|
||||
@ -15,6 +18,30 @@ class MenuPanel extends StatefulWidget implements PreferredSizeWidget {
|
||||
enum TabName { home, catalog, about }
|
||||
|
||||
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 linkAbout = "about";
|
||||
final String linkHome = "home";
|
||||
@ -59,12 +86,9 @@ class _MenuPanel extends State<MenuPanel> {
|
||||
Navigator.pushNamed(context, "/about");
|
||||
}),
|
||||
]),
|
||||
automaticallyImplyLeading: false,
|
||||
actions: <Widget>[
|
||||
IconButton(
|
||||
onPressed: () => print("acc"), icon: const Icon(Icons.account_circle))
|
||||
],
|
||||
backgroundColor: Colors.cyan,
|
||||
automaticallyImplyLeading: false,
|
||||
actions: accountActions(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
55
lib/components/sign_in_form.dart
Normal file
55
lib/components/sign_in_form.dart
Normal 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'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user