gergle/lib/player_ui/app_bar.dart
h7x4 6b82280c14
Multiple changes:
- Split up UI into several files
- Handle connection state better
- Add images
- Granular rebuilding of state dependent widgets
- Fix usage of alert dialogs
- Add some basic theming
- Add dialog for adding multiple links at once
2024-12-18 20:12:14 +01:00

108 lines
3.2 KiB
Dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:gergle/api/commands.dart';
import 'package:gergle/player_ui/main.dart';
import 'package:gergle/state/connection_state_bloc.dart';
class PlayerUIAppBar{
static AppBar appbar(BuildContext context) {
return AppBar(
title: const Text('Gergle'),
backgroundColor: Theme.of(context).primaryColor,
actions: [
DropdownMenu(
leadingIcon: const Icon(Icons.storage),
dropdownMenuEntries: const <DropdownMenuEntry<String?>>[
DropdownMenuEntry(
label: 'Georg',
value: 'wss://georg.pvv.ntnu.no/ws',
),
DropdownMenuEntry(
label: 'Brzeczyszczykiewicz',
value: 'wss://brzeczyszczykiewicz.pvv.ntnu.no/ws',
),
if (kDebugMode) ...[
DropdownMenuEntry(
label: 'Local 8009',
value: 'ws://localhost:8009/ws',
),
],
DropdownMenuEntry(
value: null,
label: 'Custom...',
),
],
onSelected: (value) async {
final connectionStateBloc =
BlocProvider.of<ConnectionStateBloc>(context);
value ??= await _askForServerUriMenu(context);
if (value == null) {
// TODO: restore previous selection.
return;
}
connectionStateBloc.add(Connect(value));
},
),
playerBlocBuilder(buildProps: (p) => [p.isPausedForCache], builder: (context, state) {
// TODO: why is the server not sending paused-for-cache events?
if (state.isPausedForCache) {
return const CircularProgressIndicator();
} else {
return const SizedBox.shrink();
}
}),
IconButton(
icon: const Icon(Icons.settings),
onPressed: () {
throw UnimplementedError();
},
),
if (kDebugMode) ...[
const SizedBox(width: 50),
],
],
);
}
static Future<String?> _askForServerUriMenu(BuildContext context) async {
final textController = TextEditingController();
return await showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('Enter server URI'),
content: TextField(
decoration: const InputDecoration(
labelText: 'Server URI',
),
controller: textController,
onSubmitted: (value) {
Navigator.of(context).pop(value);
},
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('Cancel'),
),
TextButton(
onPressed: () {
final value = textController.text;
textController.dispose();
Navigator.of(context).pop(value);
},
child: const Text('Connect'),
),
],
);
},
);
}
}