diff --git a/lib/CourseStatus.dart b/lib/CourseStatus.dart new file mode 100644 index 0000000..94c07b6 --- /dev/null +++ b/lib/CourseStatus.dart @@ -0,0 +1,7 @@ +enum CourseStatus{ + Math, + Physics, + Chemistry, + Biology, + ComputerScience, +} \ No newline at end of file diff --git a/lib/ExtensionStudent.dart b/lib/ExtensionStudent.dart new file mode 100644 index 0000000..1a0a349 --- /dev/null +++ b/lib/ExtensionStudent.dart @@ -0,0 +1,12 @@ +import 'CourseStatus.dart'; +import 'Student.dart'; + +extension StudentCourseStatus on Student { + String getCourseStatus(String course) { + if (courses.contains(course)) { + return "Студент присутствует на этих курсах"; + } else { + return "Студент отсутствует на этих курсах"; + } + } +} \ No newline at end of file diff --git a/lib/Student.dart b/lib/Student.dart new file mode 100644 index 0000000..affe571 --- /dev/null +++ b/lib/Student.dart @@ -0,0 +1,12 @@ +class Student { + String name; + int age; + List courses; + + Student(this.name, this.age, this.courses); + + void displayInfo() { + print('Name: $name, Age: $age'); + print('Courses: ${courses.join(", ")}'); + } +} \ No newline at end of file diff --git a/lib/University.dart b/lib/University.dart new file mode 100644 index 0000000..cf266b9 --- /dev/null +++ b/lib/University.dart @@ -0,0 +1,19 @@ +import 'student.dart'; + +class University { + List students = []; + + void addStudent(Student student) { + students.add(student); + } + + void displayAllStudents() { + for (var student in students) { + student.displayInfo(); + } + } + + List getStudentsByCourse(String course) { + return students.where((student) => student.courses.contains(course)).toList(); + } +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 13ad584..a1a5431 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,70 +1,126 @@ -import 'package:flutter/material.dart'; - -void main() { - runApp(const MyApp()); -} - -class MyApp extends StatelessWidget { - const MyApp({super.key}); - - @override - Widget build(BuildContext context) { - return MaterialApp( - title: 'Flutter Demo', - theme: ThemeData( - colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), - useMaterial3: true, - ), - home: const MyHomePage(title: 'Flutter Demo Home Page'), - ); - } -} - -class MyHomePage extends StatefulWidget { - const MyHomePage({super.key, required this.title}); - - - - final String title; - - @override - State createState() => _MyHomePageState(); -} - -class _MyHomePageState extends State { - int _counter = 0; - - void _incrementCounter() { - setState(() { - _counter++; - }); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - backgroundColor: Theme.of(context).colorScheme.inversePrimary, - title: Text(widget.title), - ), - body: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text( - 'You have pushed the button this many times:', - ), - Text( - '$_counter', - style: Theme.of(context).textTheme.headlineMedium, - ), - ], - ), - ), - floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: const Icon(Icons.add), - ), ); - } -} +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 { + final University university = University(); + final TextEditingController nameController = TextEditingController(); + final TextEditingController ageController = TextEditingController(); + List selectedCourses = []; + + void _addStudent() { + String name = nameController.text; + int age = int.tryParse(ageController.text) ?? 0; + + if (name.isNotEmpty && age > 0 && selectedCourses.isNotEmpty) { + setState(() { + // Создаем новый список курсов для каждого студента + List 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( + 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>((CourseStatus value) { + return DropdownMenuItem( + 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(", ")}'), + ); + }, + ), + ), + ], + ), + ); + } +} \ No newline at end of file