// This project is not supposed to be cross-platform, // so we don't care about this warning // ignore: avoid_web_libraries_in_flutter import 'dart:html'; import 'package:flutter/material.dart'; import 'package:softplayer_web/components/sign_in_form.dart'; import 'package:softplayer_web/components/sign_up_form.dart'; 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; @override State createState() => _MenuPanel(); } enum TabName { home, catalog, about } class _MenuPanel extends State { bool isSignedIn() { return window.localStorage.containsKey("token"); } List accountActions() { if (isSignedIn()) { return [ IconButton( onPressed: () => print("acc"), icon: const Icon(Icons.account_circle)) ]; } else { return [ TextButton( onPressed: () { showDialog( context: context, builder: (BuildContext context) => const SignInForm()); }, child: const Text("sign in")), TextButton( onPressed: () { showDialog( context: context, builder: (BuildContext context) => const SignUpForm()); }, 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: const Color.fromRGBO(46, 51, 78, 1.0), automaticallyImplyLeading: false, actions: accountActions(), ); } }