80 lines
2.5 KiB
Dart
80 lines
2.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:labs/presentation/home_page/bloc/bloc.dart';
|
|
import 'package:labs/presentation/home_page/home_page.dart';
|
|
import 'package:labs/repo/potter_repo.dart';
|
|
import 'University.dart';
|
|
import 'domain/models/Student.dart';
|
|
|
|
void main() {
|
|
runApp(MyApp());
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'University App',
|
|
theme: ThemeData(
|
|
primarySwatch: Colors.blue,
|
|
scaffoldBackgroundColor: Colors.white, // Устанавливаем белый фон
|
|
),
|
|
home: ScaffoldMessenger(
|
|
child: 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 = [];
|
|
|
|
void _addStudent() async {
|
|
await Future.delayed(Duration(seconds: 1));
|
|
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) {
|
|
return MaterialApp(
|
|
title: 'Строев Владимир, ПИбд-32',
|
|
debugShowCheckedModeBanner: false,
|
|
theme: ThemeData(
|
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.orangeAccent),
|
|
useMaterial3: true,
|
|
scaffoldBackgroundColor: Colors.white, // Устанавливаем белый фон
|
|
),
|
|
home: RepositoryProvider<PotterRepo>(
|
|
lazy: true,
|
|
create: (_) => PotterRepo(),
|
|
child: BlocProvider<HomeBloc>(
|
|
lazy: false,
|
|
create: (context) => HomeBloc(context.read<PotterRepo>()),
|
|
child: Scaffold(
|
|
body: const MyHomePage(),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} |