softplayer-web/lib/components/menubar.dart

95 lines
2.7 KiB
Dart

import 'dart:html';
import 'package:flutter/material.dart';
import 'package:softplayer_web/components/sign_in_form.dart';
/// Flutter code sample for [AppBar].
class MenuPanel extends StatefulWidget implements PreferredSizeWidget {
final TabName tab;
const MenuPanel({super.key, required this.tab})
: preferredSize = const Size.fromHeight(kToolbarHeight);
@override
final Size preferredSize; // default is 56.0
@override
State<StatefulWidget> createState() => _MenuPanel();
}
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";
@override
PreferredSizeWidget build(BuildContext context) {
final TabName tab = widget.tab;
return AppBar(
title: Row(children: [
TextButton(
child: const Text("Softplayer"),
onPressed: () {
Navigator.pushNamed(context, "/");
}),
TextButton(
child: Text(
linkHome,
style: (tab == TabName.home)
? const TextStyle(decoration: TextDecoration.underline)
: const TextStyle(),
),
onPressed: () {
Navigator.pushNamed(context, "/");
}),
TextButton(
child: Text(
linkCatalog,
style: (tab == TabName.catalog)
? const TextStyle(decoration: TextDecoration.underline)
: const TextStyle(),
),
onPressed: () {
Navigator.pushNamed(context, "/catalog");
}),
TextButton(
child: Text(
linkAbout,
style: (tab == TabName.about)
? const TextStyle(decoration: TextDecoration.underline)
: const TextStyle(),
),
onPressed: () {
Navigator.pushNamed(context, "/about");
}),
]),
backgroundColor: Colors.cyan,
automaticallyImplyLeading: false,
actions: accountActions(),
);
}
}