mirror of
https://github.com/amigan/calls.git
synced 2024-11-21 04:19:47 -05:00
wip
This commit is contained in:
parent
d6d590684d
commit
5f92cf977b
5 changed files with 117 additions and 59 deletions
|
@ -1,20 +1,25 @@
|
|||
import 'package:web_socket_channel/web_socket_channel.dart';
|
||||
import '../pb/stillbox.pb.dart';
|
||||
|
||||
class LiveFeeder {
|
||||
class Client {
|
||||
late Uri _wsUri;
|
||||
late WebSocketChannel channel;
|
||||
|
||||
LiveFeeder() {
|
||||
Client() {
|
||||
String socketUrl = 'ws://xenon:3050/ws';
|
||||
Uri baseUri = Uri.base;
|
||||
if (baseUri.scheme == 'http' || baseUri.scheme == 'https') {
|
||||
String port = (baseUri.hasPort ? ':${baseUri.port}' : '');
|
||||
socketUrl = 'ws://${baseUri.host}$port/ws';
|
||||
final port = (baseUri.hasPort ? ':${baseUri.port}' : '');
|
||||
socketUrl =
|
||||
'${baseUri.scheme == 'http' ? 'ws' : 'wss'}://${baseUri.host}$port/ws';
|
||||
}
|
||||
_wsUri = Uri.parse(socketUrl);
|
||||
}
|
||||
|
||||
bool isConnected() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void connect() {
|
||||
channel = WebSocketChannel.connect(_wsUri);
|
||||
channel.stream.listen((event) => _handleData(event));
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'views/radio.dart';
|
||||
import 'views/login.dart';
|
||||
import 'controller/ws.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const CallsApp());
|
||||
|
@ -20,7 +22,50 @@ class CallsApp extends StatelessWidget {
|
|||
brightness: Brightness.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');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class Login extends StatefulWidget {
|
||||
const Login({super.key, required this.title});
|
||||
|
||||
final String title;
|
||||
const Login({super.key});
|
||||
|
||||
@override
|
||||
State<Login> createState() => _LoginState();
|
||||
|
@ -17,12 +15,19 @@ class _LoginState extends State<Login> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: const Text('stillbox login:'),
|
||||
),
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 16),
|
||||
child: Column(children: [
|
||||
TextFormField(
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 8, vertical: 10),
|
||||
child: TextFormField(
|
||||
controller: userController,
|
||||
decoration: const InputDecoration(
|
||||
border: OutlineInputBorder(), labelText: "Username"),
|
||||
|
@ -32,7 +37,7 @@ class _LoginState extends State<Login> {
|
|||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
)),
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 8, vertical: 16),
|
||||
|
@ -43,14 +48,14 @@ class _LoginState extends State<Login> {
|
|||
border: OutlineInputBorder(), labelText: "Password"),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter your password';
|
||||
return 'Please enter your password.';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
)),
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 8, vertical: 16.0),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8, vertical: 16.0),
|
||||
child: Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
|
@ -62,6 +67,10 @@ class _LoginState extends State<Login> {
|
|||
);
|
||||
}
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
foregroundColor: Colors.white,
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
child: const Text('Login'),
|
||||
),
|
||||
)),
|
||||
|
|
|
@ -13,7 +13,6 @@ class MainRadio extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _MainRadioState extends State<MainRadio> {
|
||||
LiveFeeder f = LiveFeeder();
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Scaffold(
|
||||
|
|
|
@ -13,7 +13,7 @@ import 'package:calls/main.dart';
|
|||
void main() {
|
||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||
// Build our app and trigger a frame.
|
||||
await tester.pumpWidget(const CallsApp());
|
||||
await tester.pumpWidget(const CallsHome());
|
||||
|
||||
// Verify that our counter starts at 0.
|
||||
expect(find.text('0'), findsOneWidget);
|
||||
|
|
Loading…
Reference in a new issue