238f2e555f
This reverts commit 27b47afa09
.
126 lines
4.0 KiB
Dart
126 lines
4.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'CourseStatus.dart';
|
|
import 'University.dart';
|
|
import '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,
|
|
),
|
|
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 = [];
|
|
|
|
void _addStudent() {
|
|
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 Scaffold(
|
|
appBar: AppBar(
|
|
title: Text('Строев Владимир, ПИбд-32'),
|
|
),
|
|
body: Column(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Column(
|
|
children: [
|
|
Text('Университет', style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)),
|
|
SizedBox(height: 20),
|
|
TextField(
|
|
controller: nameController,
|
|
decoration: InputDecoration(labelText: 'Name'),
|
|
),
|
|
TextField(
|
|
controller: ageController,
|
|
decoration: InputDecoration(labelText: 'Age'),
|
|
keyboardType: TextInputType.number,
|
|
),
|
|
DropdownButton<String>(
|
|
value: selectedCourses.isNotEmpty ? selectedCourses.first : null,
|
|
hint: Text('Select Courses'),
|
|
onChanged: (String? newValue) {
|
|
setState(() {
|
|
if (newValue != null && !selectedCourses.contains(newValue)) {
|
|
selectedCourses.add(newValue);
|
|
}
|
|
});
|
|
},
|
|
items: CourseStatus.values.map<DropdownMenuItem<String>>((CourseStatus value) {
|
|
return DropdownMenuItem<String>(
|
|
value: value.name,
|
|
child: Text(value.name),
|
|
);
|
|
}).toList(),
|
|
),
|
|
Wrap(
|
|
spacing: 8.0,
|
|
children: selectedCourses.map((course) {
|
|
return Chip(
|
|
label: Text(course),
|
|
onDeleted: () {
|
|
setState(() {
|
|
selectedCourses.remove(course);
|
|
});
|
|
},
|
|
);
|
|
}).toList(),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: _addStudent,
|
|
child: Text('Add Student'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Expanded(
|
|
child: ListView.builder(
|
|
itemCount: university.students.length,
|
|
itemBuilder: (context, index) {
|
|
Student student = university.students[index];
|
|
return ListTile(
|
|
title: Text(student.name),
|
|
subtitle: Text('Age: ${student.age}, Courses: ${student.courses.join(", ")}'),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
} |