Skip to content

Commit

Permalink
Add connect to play button in connect dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Sep 16, 2024
1 parent 1b80fc7 commit 4079daa
Showing 1 changed file with 45 additions and 39 deletions.
84 changes: 45 additions & 39 deletions app/lib/pages/home/connect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ import 'package:quokka/widgets/search.dart';
import 'package:quokka_api/quokka_api.dart';
import 'package:rxdart/rxdart.dart';

void _connect(BuildContext context, String address, bool secure) {
Navigator.of(context).pop();
GoRouter.of(context).goNamed('connect', queryParameters: {
'address': address,
'secure': secure.toString(),
});
}

class ConnectEditDialog extends StatelessWidget {
final ListGameServer? initialValue;
final int? index;
Expand All @@ -26,16 +34,13 @@ class ConnectEditDialog extends StatelessWidget {
String address = initialValue?.address ?? '';
String name = initialValue?.name ?? '';
bool secure = initialValue?.secure ?? true;
void connect() {
Navigator.of(context).pop();
GoRouter.of(context).goNamed('connect', queryParameters: {
'address': address,
'secure': secure.toString(),
});
}

final secureSwitchEnabled = !kIsWeb || Uri.base.isScheme('HTTP');

void connect() {
_connect(context, address, secure);
}

return ResponsiveAlertDialog(
title: Text(AppLocalizations.of(context).connect),
leading: IconButton.outlined(
Expand Down Expand Up @@ -132,16 +137,12 @@ class _ServersDialogState extends State<ServersDialog> {
.autoConnect();
}

_buildDetailsChildren(GameProperty? server) => server == null
? [
Center(child: Text(AppLocalizations.of(context).error)),
]
: [
ListTile(
title: Text(AppLocalizations.of(context).description),
subtitle: Text(server.description),
),
];
_buildDetailsChildren(GameProperty server) => [
ListTile(
title: Text(AppLocalizations.of(context).description),
subtitle: Text(server.description),
),
];
@override
Widget build(BuildContext context) {
return BlocBuilder<SettingsCubit, QuokkaSettings>(
Expand Down Expand Up @@ -196,7 +197,8 @@ class _ServersDialogState extends State<ServersDialog> {
child: FilledButton.icon(
icon: const Icon(PhosphorIconsLight.play),
label: Text(AppLocalizations.of(context).play),
onPressed: () => Navigator.of(context).pop(),
onPressed: () =>
_connect(context, server.address, server.secure),
),
),
const SizedBox(width: 8),
Expand Down Expand Up @@ -288,7 +290,8 @@ class _ServersDialogState extends State<ServersDialog> {
titleBuilder: (context) =>
Text(current.display),
childrenBuilder: (context) => [
..._buildDetailsChildren(entry.value),
..._buildDetailsChildren(entry.value ??
const GameProperty()),
const SizedBox(height: 16),
Padding(
padding: const EdgeInsets.all(8.0),
Expand Down Expand Up @@ -322,25 +325,6 @@ class _ServersDialogState extends State<ServersDialog> {
),
],
);
final details = Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
server.display,
style: Theme.of(context).textTheme.titleLarge,
),
),
Expanded(
child: ListView(
children: _buildDetailsChildren(property),
),
),
const SizedBox(height: 16),
playButton,
],
);
return Column(
children: [
RowSearchView(
Expand Down Expand Up @@ -381,7 +365,29 @@ class _ServersDialogState extends State<ServersDialog> {
child: Text(AppLocalizations.of(context)
.selectServer),
)
: details),
: Column(
crossAxisAlignment:
CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
server.display,
style: Theme.of(context)
.textTheme
.titleLarge,
),
),
Expanded(
child: ListView(
children:
_buildDetailsChildren(property),
),
),
const SizedBox(height: 16),
playButton,
],
)),
],
],
),
Expand Down

0 comments on commit 4079daa

Please sign in to comment.