softplayer-web/lib/components/menubar.dart

98 lines
2.8 KiB
Dart
Raw Normal View History

2024-04-04 16:15:30 +00:00
// This project is not supposed to be cross-platform,
// so we don't care about this warning
// ignore: avoid_web_libraries_in_flutter
2024-04-04 14:35:33 +00:00
import 'dart:html';
2024-03-26 16:17:04 +00:00
import 'package:flutter/material.dart';
2024-04-04 14:35:33 +00:00
import 'package:softplayer_web/components/sign_in_form.dart';
2024-03-26 16:17:04 +00:00
2024-03-27 21:07:53 +00:00
class MenuPanel extends StatefulWidget implements PreferredSizeWidget {
2024-03-26 16:17:04 +00:00
final TabName tab;
2024-03-27 21:07:53 +00:00
const MenuPanel({super.key, required this.tab})
: preferredSize = const Size.fromHeight(kToolbarHeight);
2024-03-26 16:17:04 +00:00
@override
2024-04-04 16:15:30 +00:00
final Size preferredSize;
2024-03-26 16:17:04 +00:00
@override
State<StatefulWidget> createState() => _MenuPanel();
}
enum TabName { home, catalog, about }
class _MenuPanel extends State<MenuPanel> {
2024-04-04 14:35:33 +00:00
bool isSignedIn() {
return window.localStorage.containsKey("token");
}
2024-04-04 16:15:30 +00:00
2024-04-04 14:35:33 +00:00
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")),
2024-04-04 16:15:30 +00:00
TextButton(
onPressed: () => print("sign up"), child: const Text("sign up")),
2024-04-04 14:35:33 +00:00
];
}
}
2024-03-26 16:17:04 +00:00
final String linkCatalog = "catalog";
final String linkAbout = "about";
final String linkHome = "home";
@override
PreferredSizeWidget build(BuildContext context) {
final TabName tab = widget.tab;
return AppBar(
2024-03-27 21:07:53 +00:00
title: Row(children: [
2024-03-26 16:17:04 +00:00
TextButton(
child: const Text("Softplayer"),
onPressed: () {
Navigator.pushNamed(context, "/");
}),
2024-03-27 21:07:53 +00:00
TextButton(
child: Text(
linkHome,
style: (tab == TabName.home)
? const TextStyle(decoration: TextDecoration.underline)
: const TextStyle(),
2024-03-26 16:17:04 +00:00
),
onPressed: () {
Navigator.pushNamed(context, "/");
}),
2024-03-27 21:07:53 +00:00
TextButton(
child: Text(
linkCatalog,
style: (tab == TabName.catalog)
? const TextStyle(decoration: TextDecoration.underline)
: const TextStyle(),
2024-03-26 16:17:04 +00:00
),
onPressed: () {
Navigator.pushNamed(context, "/catalog");
}),
2024-03-27 21:07:53 +00:00
TextButton(
child: Text(
linkAbout,
style: (tab == TabName.about)
? const TextStyle(decoration: TextDecoration.underline)
: const TextStyle(),
2024-03-26 16:17:04 +00:00
),
onPressed: () {
Navigator.pushNamed(context, "/about");
}),
2024-03-27 21:07:53 +00:00
]),
backgroundColor: Colors.cyan,
2024-04-04 14:35:33 +00:00
automaticallyImplyLeading: false,
actions: accountActions(),
2024-03-27 21:07:53 +00:00
);
2024-03-26 16:17:04 +00:00
}
}