封装webscoekts
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
import 'controls/top_bar.dart';
|
||||
import 'view/student_item.dart';
|
||||
import 'view/waiting_start.dart';
|
||||
import 'viewmodel/students_view_model.dart';
|
||||
|
||||
class TRoomPage extends StatefulWidget {
|
||||
const TRoomPage({super.key});
|
||||
@@ -14,32 +15,39 @@ class TRoomPage extends StatefulWidget {
|
||||
class _TRoomPageState extends State<TRoomPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Color(0xff2c3032),
|
||||
appBar: TopBar(),
|
||||
body: true ? WaitingStart() : Padding(
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: Row(
|
||||
spacing: 15,
|
||||
children: [
|
||||
Expanded(
|
||||
child: StudentItem(),
|
||||
),
|
||||
SizedBox(
|
||||
width: 300,
|
||||
child: ListView.separated(
|
||||
itemBuilder: (_, index) {
|
||||
return SizedBox(
|
||||
height: 250,
|
||||
child: StudentItem(),
|
||||
);
|
||||
},
|
||||
separatorBuilder: (_, __) => SizedBox(height: 15),
|
||||
itemCount: 7,
|
||||
return ChangeNotifierProvider<StudentsViewModel>(
|
||||
create: (BuildContext context) {
|
||||
return StudentsViewModel();
|
||||
},
|
||||
child: Scaffold(
|
||||
backgroundColor: Color(0xff2c3032),
|
||||
appBar: TopBar(),
|
||||
body: true
|
||||
? WaitingStart()
|
||||
: Padding(
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: Row(
|
||||
spacing: 15,
|
||||
children: [
|
||||
Expanded(
|
||||
child: StudentItem(),
|
||||
),
|
||||
SizedBox(
|
||||
width: 300,
|
||||
child: ListView.separated(
|
||||
itemBuilder: (_, index) {
|
||||
return SizedBox(
|
||||
height: 250,
|
||||
child: StudentItem(),
|
||||
);
|
||||
},
|
||||
separatorBuilder: (_, __) => SizedBox(height: 15),
|
||||
itemCount: 7,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
33
lib/pages/teacher/room/viewmodel/students_view_model.dart
Normal file
33
lib/pages/teacher/room/viewmodel/students_view_model.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
import 'package:app/data/models/student.dart';
|
||||
import 'package:app/websocket/room_websocket.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
class StudentsViewModel extends ChangeNotifier {
|
||||
///学生摄像头列表
|
||||
List<Student> _students = [];
|
||||
|
||||
List<Student> get students => _students;
|
||||
|
||||
///websocket管理
|
||||
late RoomWebSocket _ws;
|
||||
|
||||
StudentsViewModel() {
|
||||
_startRoom();
|
||||
}
|
||||
|
||||
///开始链接房间
|
||||
void _startRoom() {
|
||||
_ws = RoomWebSocket();
|
||||
_ws.connect();
|
||||
|
||||
_ws.stream.listen((msg) {
|
||||
_handleMessage();
|
||||
});
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
///发送命令
|
||||
void _handleMessage() {
|
||||
print("监听webscoket传来的事件");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user