-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
212 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:injector/injector.dart'; | ||
import 'package:unn_mobile/core/misc/try_login_and_retrieve_data.dart'; | ||
import 'package:unn_mobile/core/models/mark_by_subject.dart'; | ||
import 'package:unn_mobile/core/services/interfaces/getting_grade_book.dart'; | ||
import 'package:unn_mobile/core/services/interfaces/mark_by_subject_provider.dart'; | ||
import 'package:unn_mobile/core/viewmodels/base_view_model.dart'; | ||
|
||
class GradesScreenViewModel extends BaseViewModel { | ||
final GettingGradeBook _gradeBookService = | ||
Injector.appInstance.get<GettingGradeBook>(); | ||
final MarkBySubjectProvider _markBySubjectProvider = | ||
Injector.appInstance.get<MarkBySubjectProvider>(); | ||
|
||
Future<Map<int, List<MarkBySubject>>?> getGradeBook() async { | ||
return await tryLoginAndRetrieveData( | ||
() async { | ||
final gradeBook = await _gradeBookService.getGradeBook(); | ||
if (gradeBook != null) { | ||
_markBySubjectProvider.saveData(gradeBook); | ||
} | ||
return gradeBook; | ||
}, | ||
() async => _markBySubjectProvider.getData(), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,181 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:unn_mobile/core/models/mark_by_subject.dart'; | ||
import 'package:unn_mobile/core/viewmodels/grades_screen_view_model.dart'; | ||
import 'package:unn_mobile/ui/views/base_view.dart'; | ||
|
||
class GradesScreenView extends StatelessWidget { | ||
class GradesScreenView extends StatefulWidget { | ||
const GradesScreenView({super.key}); | ||
|
||
@override | ||
State<GradesScreenView> createState() => _GradesScreenViewState(); | ||
} | ||
|
||
class _GradesScreenViewState extends State<GradesScreenView> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return const Placeholder(); | ||
return BaseView<GradesScreenViewModel>( | ||
builder: (context, value, child) { | ||
return _getGradesBook(context: context, model: value); | ||
}, | ||
); | ||
} | ||
|
||
Widget _getGradesBook({ | ||
required GradesScreenViewModel model, | ||
required BuildContext context, | ||
}) { | ||
final theme = Theme.of(context); | ||
return FutureBuilder( | ||
future: model.getGradeBook(), | ||
builder: (context, snapshot) { | ||
if (snapshot.hasError) { | ||
return const Center( | ||
child: Padding( | ||
padding: EdgeInsets.all(8.0), | ||
child: Text('Произошла ошибка :('), | ||
), | ||
); | ||
} | ||
if (snapshot.connectionState == ConnectionState.done) { | ||
if (snapshot.hasData) { | ||
final tabs = snapshot.data!.keys.toList(); | ||
tabs.sort(); | ||
return DefaultTabController( | ||
initialIndex: tabs.length - 1, | ||
length: tabs.length, | ||
child: Column( | ||
children: [ | ||
Container( | ||
color: theme.colorScheme.background, | ||
child: TabBar.secondary( | ||
tabAlignment: TabAlignment.start, | ||
enableFeedback: false, | ||
isScrollable: true, | ||
tabs: [ | ||
for (final tab in tabs) | ||
Tab( | ||
child: Text('Семестр $tab'), | ||
), | ||
], | ||
), | ||
), | ||
Expanded( | ||
child: TabBarView( | ||
children: [ | ||
for (final tab in tabs) | ||
SingleChildScrollView( | ||
physics: const AlwaysScrollableScrollPhysics(), | ||
child: Padding( | ||
padding: const EdgeInsets.all(12.0), | ||
child: Table( | ||
border: TableBorder.all( | ||
borderRadius: const BorderRadius.all( | ||
Radius.circular(4.0), | ||
), | ||
), | ||
children: [ | ||
TableRow( | ||
decoration: BoxDecoration( | ||
color: theme.highlightColor, | ||
), | ||
children: const [ | ||
TableCell( | ||
child: Padding( | ||
padding: EdgeInsets.all(8.0), | ||
child: Text( | ||
'Дисциплина', | ||
textAlign: TextAlign.center, | ||
), | ||
), | ||
), | ||
TableCell( | ||
child: Padding( | ||
padding: EdgeInsets.all(8.0), | ||
child: Text( | ||
'Вид контроля', | ||
textAlign: TextAlign.center, | ||
), | ||
), | ||
), | ||
TableCell( | ||
child: Padding( | ||
padding: EdgeInsets.all(8.0), | ||
child: Text( | ||
'Оценка', | ||
textAlign: TextAlign.center, | ||
), | ||
), | ||
), | ||
], | ||
), | ||
for (final row in snapshot.data![tab]!) | ||
TableRow( | ||
children: [ | ||
TableCell( | ||
child: Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: Text( | ||
row.subject, | ||
textAlign: TextAlign.center, | ||
), | ||
), | ||
), | ||
TableCell( | ||
child: Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: Text( | ||
row.controlType, | ||
textAlign: TextAlign.center, | ||
), | ||
), | ||
), | ||
TableCell( | ||
child: Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: Text( | ||
row.markType.convertToString(), | ||
textAlign: TextAlign.center, | ||
), | ||
), | ||
), | ||
], | ||
), | ||
], | ||
), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} else { | ||
return Center( | ||
child: Column( | ||
children: [ | ||
const Text('Ещё нет загруженной версии зачётной книжки'), | ||
TextButton( | ||
onPressed: () { | ||
// Force redraw | ||
setState(() {}); | ||
}, | ||
child: const Text('Обновить'), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} | ||
|
||
return const Center( | ||
child: SizedBox( | ||
height: 100.0, | ||
width: 100.0, | ||
child: CircularProgressIndicator(), | ||
), | ||
); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.