11import 'package:flutter/material.dart' ;
2+ import 'package:flutter_it/flutter_it.dart' ;
23import 'package:gap/gap.dart' ;
34import 'package:school_data_hub_flutter/app_utils/pdf_viewer_page.dart' ;
45import 'package:school_data_hub_flutter/common/theme/app_colors.dart' ;
@@ -7,9 +8,7 @@ import 'package:school_data_hub_flutter/features/matrix/domain/matrix_policy_man
78import 'package:school_data_hub_flutter/features/matrix/domain/models/matrix_room.dart' ;
89import 'package:school_data_hub_flutter/features/matrix/rooms/domain/matrix_room_helper.dart' ;
910import 'package:school_data_hub_flutter/features/matrix/rooms/presentation/select_matrix_rooms_list_page/controller/select_matrix_rooms_list_controller.dart' ;
10- import 'package:school_data_hub_flutter/features/matrix/users/domain/matrix_user_manager.dart' ;
1111import 'package:school_data_hub_flutter/features/pupil/domain/models/pupil_proxy.dart' ;
12- import 'package:flutter_it/flutter_it.dart' ;
1312
1413class NewMatrixUserPage extends StatefulWidget {
1514 final String ? matrixId;
@@ -29,16 +28,83 @@ class NewMatrixUserPage extends StatefulWidget {
2928}
3029
3130class NewMatrixUserPageState extends State <NewMatrixUserPage > {
32- final _matrixUserManager = di <MatrixUserManager >();
33- final TextEditingController matrixIdController = TextEditingController ();
31+ @override
32+ Widget build (BuildContext context) {
33+ return FutureBuilder (
34+ future: di.getAsync <MatrixPolicyManager >(),
35+ builder: (context, snapshot) {
36+ if (! snapshot.hasData) {
37+ return Scaffold (
38+ backgroundColor: AppColors .canvasColor,
39+ appBar: AppBar (
40+ automaticallyImplyLeading: false ,
41+ centerTitle: true ,
42+ backgroundColor: AppColors .backgroundColor,
43+ title: const Row (
44+ mainAxisAlignment: MainAxisAlignment .center,
45+ children: [
46+ Icon (Icons .chat_rounded, size: 25 , color: Colors .white),
47+ Gap (10 ),
48+ Text ('Neues Matrix-Konto' , style: AppStyles .appBarTextStyle),
49+ ],
50+ ),
51+ ),
52+ body: const Center (
53+ child: Column (
54+ mainAxisAlignment: MainAxisAlignment .center,
55+ children: [
56+ Text (
57+ 'Bitte warten' ,
58+ style: TextStyle (fontSize: 20 , fontWeight: FontWeight .bold),
59+ ),
60+ Gap (20 ),
61+ CircularProgressIndicator (),
62+ ],
63+ ),
64+ ),
65+ );
66+ }
67+
68+ return _NewMatrixUserPageContent (
69+ matrixPolicyManager: snapshot.data! ,
70+ matrixId: widget.matrixId,
71+ displayName: widget.displayName,
72+ pupil: widget.pupil,
73+ isParent: widget.isParent,
74+ );
75+ },
76+ );
77+ }
78+ }
79+
80+ class _NewMatrixUserPageContent extends StatefulWidget {
81+ final MatrixPolicyManager matrixPolicyManager;
82+ final String ? matrixId;
83+ final String ? displayName;
84+ final PupilProxy ? pupil;
85+ final bool ? isParent;
86+
87+ const _NewMatrixUserPageContent ({
88+ required this .matrixPolicyManager,
89+ this .matrixId,
90+ this .displayName,
91+ this .pupil,
92+ this .isParent,
93+ });
3494
95+ @override
96+ _NewMatrixUserPageContentState createState () =>
97+ _NewMatrixUserPageContentState ();
98+ }
99+
100+ class _NewMatrixUserPageContentState extends State <_NewMatrixUserPageContent > {
101+ final TextEditingController matrixIdController = TextEditingController ();
35102 final TextEditingController displayNameController = TextEditingController ();
36- final allRooms = di < MatrixPolicyManager >().matrixRooms.value ;
103+ Set < String > roomIds = {} ;
37104
38105 @override
39106 void initState () {
40107 super .initState ();
41- setState (() {});
42108 if (widget.matrixId != null ) {
43109 matrixIdController.text = widget.matrixId! ;
44110 }
@@ -53,13 +119,9 @@ class NewMatrixUserPageState extends State<NewMatrixUserPage> {
53119 );
54120 }
55121
56- setState (() {
57- roomIds = rooms;
58- });
122+ roomIds = rooms;
59123 }
60124
61- Set <String > roomIds = {};
62-
63125 @override
64126 Widget build (BuildContext context) {
65127 List <MatrixRoom > roomsFromIds = MatrixRoomHelper .roomsFromRoomIds (
@@ -129,7 +191,7 @@ class NewMatrixUserPageState extends State<NewMatrixUserPage> {
129191 ),
130192 const Gap (5 ),
131193 Text (
132- ':${di < MatrixPolicyManager >() .matrixUrl .split ('://' ).last }' ,
194+ ':${widget . matrixPolicyManager .matrixUrl .split ('://' ).last }' ,
133195 style: const TextStyle (
134196 fontSize: 16 ,
135197 fontWeight: FontWeight .bold,
@@ -280,12 +342,13 @@ class NewMatrixUserPageState extends State<NewMatrixUserPage> {
280342 ElevatedButton (
281343 style: AppStyles .successButtonStyle,
282344 onPressed: () async {
283- final file = await _matrixUserManager.postNewMatrixUser (
284- pupil: widget.pupil,
285- generatedMatrixId: matrixIdController.text,
286- displayName: displayNameController.text,
287- roomIds: roomIds.toList (),
288- );
345+ final file = await widget.matrixPolicyManager.users
346+ .postNewMatrixUser (
347+ pupil: widget.pupil,
348+ generatedMatrixId: matrixIdController.text,
349+ displayName: displayNameController.text,
350+ roomIds: roomIds.toList (),
351+ );
289352
290353 if (file != null && context.mounted) {
291354 Navigator .of (context).push (
0 commit comments