PIbd-32_Stroev_V_M_PMD/lib/main.dart

75 lines
2.2 KiB
Dart
Raw Normal View History

2024-10-01 20:53:17 +04:00
import 'package:flutter/material.dart';
2024-10-30 22:39:56 +04:00
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:labs/presentation/home_page/bloc/bloc.dart';
2024-10-22 08:55:54 +04:00
import 'package:labs/presentation/home_page/home_page.dart';
2024-10-30 22:39:56 +04:00
import 'package:labs/repo/potter_repo.dart';
2024-10-01 20:53:17 +04:00
import 'University.dart';
2024-10-22 08:55:54 +04:00
import 'domain/models/Student.dart';
2024-10-01 20:53:17 +04:00
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'University App',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: UniversityScreen(),
);
}
}
class UniversityScreen extends StatefulWidget {
@override
_UniversityScreenState createState() => _UniversityScreenState();
}
class _UniversityScreenState extends State<UniversityScreen> {
final University university = University();
final TextEditingController nameController = TextEditingController();
final TextEditingController ageController = TextEditingController();
List<String> selectedCourses = [];
2024-10-03 15:39:20 +04:00
void _addStudent() async {
await Future.delayed(Duration(seconds: 1));
2024-10-01 20:53:17 +04:00
String name = nameController.text;
int age = int.tryParse(ageController.text) ?? 0;
if (name.isNotEmpty && age > 0 && selectedCourses.isNotEmpty) {
setState(() {
// Создаем новый список курсов для каждого студента
List<String> studentCourses = List.from(selectedCourses);
university.addStudent(Student(name, age, studentCourses));
nameController.clear();
ageController.clear();
selectedCourses.clear();
});
}
}
@override
Widget build(BuildContext context) {
2024-10-30 22:39:56 +04:00
return MaterialApp(
title: 'Строев Владимир, ПИбд-32',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.orangeAccent),
useMaterial3: true,
2024-10-02 23:27:54 +04:00
),
2024-10-30 22:39:56 +04:00
home: RepositoryProvider<PotterRepo>(
lazy: true,
create: (_) => PotterRepo(),
child: BlocProvider<HomeBloc>(
lazy: false,
create: (context) => HomeBloc(context.read<PotterRepo>()),
child: const MyHomePage(),
),
)
2024-10-02 22:51:30 +04:00
);
}
}