This commit is contained in:
Daniel 2024-08-12 09:13:43 -04:00
parent d6d590684d
commit 5f92cf977b
5 changed files with 117 additions and 59 deletions

View file

@ -1,20 +1,25 @@
import 'package:web_socket_channel/web_socket_channel.dart'; import 'package:web_socket_channel/web_socket_channel.dart';
import '../pb/stillbox.pb.dart'; import '../pb/stillbox.pb.dart';
class LiveFeeder { class Client {
late Uri _wsUri; late Uri _wsUri;
late WebSocketChannel channel; late WebSocketChannel channel;
LiveFeeder() { Client() {
String socketUrl = 'ws://xenon:3050/ws'; String socketUrl = 'ws://xenon:3050/ws';
Uri baseUri = Uri.base; Uri baseUri = Uri.base;
if (baseUri.scheme == 'http' || baseUri.scheme == 'https') { if (baseUri.scheme == 'http' || baseUri.scheme == 'https') {
String port = (baseUri.hasPort ? ':${baseUri.port}' : ''); final port = (baseUri.hasPort ? ':${baseUri.port}' : '');
socketUrl = 'ws://${baseUri.host}$port/ws'; socketUrl =
'${baseUri.scheme == 'http' ? 'ws' : 'wss'}://${baseUri.host}$port/ws';
} }
_wsUri = Uri.parse(socketUrl); _wsUri = Uri.parse(socketUrl);
} }
bool isConnected() {
return false;
}
void connect() { void connect() {
channel = WebSocketChannel.connect(_wsUri); channel = WebSocketChannel.connect(_wsUri);
channel.stream.listen((event) => _handleData(event)); channel.stream.listen((event) => _handleData(event));

View file

@ -1,5 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'views/radio.dart'; import 'views/radio.dart';
import 'views/login.dart';
import 'controller/ws.dart';
void main() { void main() {
runApp(const CallsApp()); runApp(const CallsApp());
@ -20,7 +22,50 @@ class CallsApp extends StatelessWidget {
brightness: Brightness.dark, brightness: Brightness.dark,
), ),
themeMode: ThemeMode.dark, themeMode: ThemeMode.dark,
home: const MainRadio(title: 'Stillbox'), home: const CallsHome(),
); );
} }
} }
class CallsHome extends StatefulWidget {
const CallsHome({super.key});
@override
State<StatefulWidget> createState() => CallsHomeState();
}
class CallsHomeState extends State<CallsHome> {
final c = Client();
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
loadData();
});
}
Future<void> loadData() async {
await Future.delayed(const Duration(seconds: 1)); // Simulate some delay
// Ensure the navigation happens in the context of this widget's subtree
if (mounted) {
Navigator.pushReplacement(
context,
PageRouteBuilder(
pageBuilder: (context, animation, secondaryAnimation) =>
const Login(),
transitionsBuilder: (context, animation, secondaryAnimation, child) {
return child;
},
transitionDuration: const Duration(milliseconds: 0),
),
);
}
}
@override
Widget build(BuildContext context) {
return const MainRadio(title: 'Stillbox');
}
}

View file

@ -1,9 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class Login extends StatefulWidget { class Login extends StatefulWidget {
const Login({super.key, required this.title}); const Login({super.key});
final String title;
@override @override
State<Login> createState() => _LoginState(); State<Login> createState() => _LoginState();
@ -17,12 +15,19 @@ class _LoginState extends State<Login> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text('stillbox login:'),
),
body: Form( body: Form(
key: _formKey, key: _formKey,
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 16), padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 16),
child: Column(children: [ child: Column(children: [
TextFormField( Padding(
padding:
const EdgeInsets.symmetric(horizontal: 8, vertical: 10),
child: TextFormField(
controller: userController, controller: userController,
decoration: const InputDecoration( decoration: const InputDecoration(
border: OutlineInputBorder(), labelText: "Username"), border: OutlineInputBorder(), labelText: "Username"),
@ -32,7 +37,7 @@ class _LoginState extends State<Login> {
} }
return null; return null;
}, },
), )),
Padding( Padding(
padding: padding:
const EdgeInsets.symmetric(horizontal: 8, vertical: 16), const EdgeInsets.symmetric(horizontal: 8, vertical: 16),
@ -43,14 +48,14 @@ class _LoginState extends State<Login> {
border: OutlineInputBorder(), labelText: "Password"), border: OutlineInputBorder(), labelText: "Password"),
validator: (value) { validator: (value) {
if (value == null || value.isEmpty) { if (value == null || value.isEmpty) {
return 'Please enter your password'; return 'Please enter your password.';
} }
return null; return null;
}, },
)), )),
Padding( Padding(
padding: padding: const EdgeInsets.symmetric(
const EdgeInsets.symmetric(horizontal: 8, vertical: 16.0), horizontal: 8, vertical: 16.0),
child: Center( child: Center(
child: ElevatedButton( child: ElevatedButton(
onPressed: () { onPressed: () {
@ -62,6 +67,10 @@ class _LoginState extends State<Login> {
); );
} }
}, },
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: Colors.green,
),
child: const Text('Login'), child: const Text('Login'),
), ),
)), )),

View file

@ -13,7 +13,6 @@ class MainRadio extends StatefulWidget {
} }
class _MainRadioState extends State<MainRadio> { class _MainRadioState extends State<MainRadio> {
LiveFeeder f = LiveFeeder();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return const Scaffold( return const Scaffold(

View file

@ -13,7 +13,7 @@ import 'package:calls/main.dart';
void main() { void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async { testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame. // Build our app and trigger a frame.
await tester.pumpWidget(const CallsApp()); await tester.pumpWidget(const CallsHome());
// Verify that our counter starts at 0. // Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget); expect(find.text('0'), findsOneWidget);