feat(ui): show live output, add a stop button and duration/stream inputs
The screen could only start a 10s single-stream test and read the result afterwards. It now renders the transcript as it arrives in a scrolling monospace view that follows the newest line, exposes the duration and parallel-stream settings TestConfiguration already carried, can stop a run in progress, and copies the transcript to the clipboard. The output field previously built a TextEditingController inside build(), so every rebuild — one per output line now that output streams — discarded and replaced it. Replaced with SelectableText, which needs no controller. Seeds the inputs from TestConfiguration's own defaults rather than a second hardcoded server address, so there is one default to change. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:iperf3gui/data/services/iperf3_service.dart';
|
import 'package:iperf3gui/data/services/iperf3_service.dart';
|
||||||
import 'package:iperf3gui/domain/models/test_configuration.dart';
|
import 'package:iperf3gui/domain/models/test_configuration.dart';
|
||||||
@@ -6,8 +7,8 @@ import 'package:iperf3gui/ui/features/test_run/test_run_view_model.dart';
|
|||||||
|
|
||||||
/// Main test run screen.
|
/// Main test run screen.
|
||||||
///
|
///
|
||||||
/// iperf3 is now compiled as a native shared library (libiperf3jni.so)
|
/// iperf3 is compiled as a native shared library (libiperf3jni.so) and accessed
|
||||||
/// and accessed via JNI. No binary extraction or chmod needed.
|
/// via JNI, so there is no binary extraction or chmod step.
|
||||||
class TestRunScreen extends StatelessWidget {
|
class TestRunScreen extends StatelessWidget {
|
||||||
const TestRunScreen({super.key});
|
const TestRunScreen({super.key});
|
||||||
|
|
||||||
@@ -30,111 +31,195 @@ class _TestRunContent extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _TestRunContentState extends State<_TestRunContent> {
|
class _TestRunContentState extends State<_TestRunContent> {
|
||||||
final _serverController = TextEditingController(text: 'speedtest.uztelecom.uz');
|
static const _defaults = TestConfiguration();
|
||||||
final _portController = TextEditingController(text: '5201');
|
|
||||||
|
final _serverController =
|
||||||
|
TextEditingController(text: _defaults.server);
|
||||||
|
final _portController =
|
||||||
|
TextEditingController(text: _defaults.port.toString());
|
||||||
|
final _durationController =
|
||||||
|
TextEditingController(text: _defaults.duration.inSeconds.toString());
|
||||||
|
final _streamsController =
|
||||||
|
TextEditingController(text: _defaults.parallelStreams.toString());
|
||||||
|
final _outputScrollController = ScrollController();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_serverController.dispose();
|
_serverController.dispose();
|
||||||
_portController.dispose();
|
_portController.dispose();
|
||||||
|
_durationController.dispose();
|
||||||
|
_streamsController.dispose();
|
||||||
|
_outputScrollController.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TestConfiguration _readConfiguration() {
|
||||||
|
return TestConfiguration(
|
||||||
|
server: _serverController.text.trim(),
|
||||||
|
port: int.tryParse(_portController.text) ?? _defaults.port,
|
||||||
|
duration: Duration(
|
||||||
|
seconds: int.tryParse(_durationController.text) ??
|
||||||
|
_defaults.duration.inSeconds,
|
||||||
|
),
|
||||||
|
parallelStreams:
|
||||||
|
int.tryParse(_streamsController.text) ?? _defaults.parallelStreams,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Keep the newest output in view, but only once the frame that added it has
|
||||||
|
/// been laid out.
|
||||||
|
void _scrollToBottom() {
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
if (!_outputScrollController.hasClients) return;
|
||||||
|
_outputScrollController
|
||||||
|
.jumpTo(_outputScrollController.position.maxScrollExtent);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('iperf3-gui'),
|
title: const Text('iperf3-gui'),
|
||||||
|
actions: [
|
||||||
|
Consumer<TestRunViewModel>(
|
||||||
|
builder: (context, vm, _) => IconButton(
|
||||||
|
tooltip: 'Copy output',
|
||||||
|
icon: const Icon(Icons.copy_all),
|
||||||
|
onPressed: vm.output.isEmpty
|
||||||
|
? null
|
||||||
|
: () {
|
||||||
|
Clipboard.setData(ClipboardData(text: vm.output));
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(content: Text('Output copied')),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
body: Padding(
|
body: Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
// Server input
|
|
||||||
TextField(
|
TextField(
|
||||||
controller: _serverController,
|
controller: _serverController,
|
||||||
|
autocorrect: false,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'Server',
|
labelText: 'Server',
|
||||||
hintText: 'e.g. iperf.es.net or 192.168.1.1',
|
hintText: 'e.g. iperf.es.net or 192.168.1.1',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 12),
|
||||||
|
|
||||||
// Port input
|
Row(
|
||||||
TextField(
|
children: [
|
||||||
controller: _portController,
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
labelText: 'Port',
|
|
||||||
hintText: '5201',
|
|
||||||
),
|
|
||||||
keyboardType: TextInputType.number,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
|
|
||||||
// Go button
|
|
||||||
Consumer<TestRunViewModel>(
|
|
||||||
builder: (context, vm, _) {
|
|
||||||
return ElevatedButton(
|
|
||||||
onPressed: vm.state == TestRunState.running
|
|
||||||
? null
|
|
||||||
: () {
|
|
||||||
final config = TestConfiguration(
|
|
||||||
server: _serverController.text,
|
|
||||||
port: int.tryParse(_portController.text) ?? 5201,
|
|
||||||
);
|
|
||||||
vm.runTest(config);
|
|
||||||
},
|
|
||||||
child: vm.state == TestRunState.running
|
|
||||||
? const SizedBox(
|
|
||||||
width: 20,
|
|
||||||
height: 20,
|
|
||||||
child: CircularProgressIndicator(strokeWidth: 2),
|
|
||||||
)
|
|
||||||
: const Text('GO'),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
|
|
||||||
// Status indicator
|
|
||||||
Consumer<TestRunViewModel>(
|
|
||||||
builder: (context, vm, _) {
|
|
||||||
final statusText = switch (vm.state) {
|
|
||||||
TestRunState.idle => '',
|
|
||||||
TestRunState.running => 'Running...',
|
|
||||||
TestRunState.completed => 'Test complete',
|
|
||||||
TestRunState.error => 'Error',
|
|
||||||
};
|
|
||||||
return Text(
|
|
||||||
statusText,
|
|
||||||
style: TextStyle(
|
|
||||||
color: vm.state == TestRunState.error
|
|
||||||
? Colors.red
|
|
||||||
: Colors.grey,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
|
|
||||||
// Raw output text box
|
|
||||||
Expanded(
|
Expanded(
|
||||||
|
child: TextField(
|
||||||
|
controller: _portController,
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
decoration: const InputDecoration(labelText: 'Port'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
Expanded(
|
||||||
|
child: TextField(
|
||||||
|
controller: _durationController,
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
decoration: const InputDecoration(labelText: 'Seconds'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
Expanded(
|
||||||
|
child: TextField(
|
||||||
|
controller: _streamsController,
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
decoration: const InputDecoration(labelText: 'Streams'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
|
||||||
|
Consumer<TestRunViewModel>(
|
||||||
|
builder: (context, vm, _) {
|
||||||
|
if (vm.isRunning) {
|
||||||
|
return OutlinedButton.icon(
|
||||||
|
onPressed: vm.stopTest,
|
||||||
|
icon: const Icon(Icons.stop),
|
||||||
|
label: const Text('STOP'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return ElevatedButton(
|
||||||
|
onPressed: () => vm.runTest(_readConfiguration()),
|
||||||
|
child: const Text('GO'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
|
||||||
|
// Status line
|
||||||
|
Consumer<TestRunViewModel>(
|
||||||
|
builder: (context, vm, _) {
|
||||||
|
final scheme = Theme.of(context).colorScheme;
|
||||||
|
final (String label, Color color) = switch (vm.state) {
|
||||||
|
TestRunState.idle => ('Ready', scheme.onSurfaceVariant),
|
||||||
|
TestRunState.running => ('Running…', scheme.primary),
|
||||||
|
TestRunState.completed => ('Test complete', scheme.primary),
|
||||||
|
TestRunState.error => (
|
||||||
|
'Error${vm.result != null ? ' (exit ${vm.result!.exitCode})' : ''}',
|
||||||
|
scheme.error,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
return Row(
|
||||||
|
children: [
|
||||||
|
if (vm.isRunning)
|
||||||
|
const Padding(
|
||||||
|
padding: EdgeInsets.only(right: 8),
|
||||||
|
child: SizedBox(
|
||||||
|
width: 14,
|
||||||
|
height: 14,
|
||||||
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(label, style: TextStyle(color: color)),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
|
||||||
|
// Live output
|
||||||
|
Expanded(
|
||||||
|
child: Container(
|
||||||
|
width: double.infinity,
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border.all(
|
||||||
|
color: Theme.of(context).colorScheme.outlineVariant,
|
||||||
|
),
|
||||||
|
borderRadius: BorderRadius.circular(4),
|
||||||
|
),
|
||||||
child: Consumer<TestRunViewModel>(
|
child: Consumer<TestRunViewModel>(
|
||||||
builder: (context, vm, _) {
|
builder: (context, vm, _) {
|
||||||
final output = vm.result?.rawOutput ?? '';
|
_scrollToBottom();
|
||||||
return TextField(
|
return SingleChildScrollView(
|
||||||
controller: TextEditingController(text: output),
|
controller: _outputScrollController,
|
||||||
decoration: const InputDecoration(
|
child: SelectableText(
|
||||||
labelText: 'Raw Output',
|
vm.output.isEmpty
|
||||||
border: OutlineInputBorder(),
|
? 'Output will appear here.'
|
||||||
|
: vm.output,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontFamily: 'monospace',
|
||||||
|
fontSize: 12,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
maxLines: null,
|
|
||||||
readOnly: true,
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user