30 lines
909 B
Dart
30 lines
909 B
Dart
|
|
import 'package:flutter/material.dart';
|
||
|
|
|
||
|
|
import '../link/boundary.dart';
|
||
|
|
import '../link/net.dart';
|
||
|
|
|
||
|
|
/// Ask for the gateway's address and reconnect there, binding to the USB link when it is on it.
|
||
|
|
Future<void> editUrl(BuildContext context, Boundary b, UsbLink usb) async {
|
||
|
|
final c = TextEditingController(text: b.url);
|
||
|
|
final url = await showDialog<String>(
|
||
|
|
context: context,
|
||
|
|
builder: (ctx) => AlertDialog(
|
||
|
|
title: const Text('Gateway address'),
|
||
|
|
content: TextField(controller: c, autofocus: true),
|
||
|
|
actions: [
|
||
|
|
TextButton(
|
||
|
|
onPressed: () => Navigator.pop(ctx),
|
||
|
|
child: const Text('Cancel'),
|
||
|
|
),
|
||
|
|
TextButton(
|
||
|
|
onPressed: () => Navigator.pop(ctx, c.text.trim()),
|
||
|
|
child: const Text('Connect'),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
);
|
||
|
|
if (url == null || url.isEmpty) return;
|
||
|
|
await usb.bindFor(Uri.parse(url));
|
||
|
|
b.retarget(url);
|
||
|
|
}
|