PIbd-32_Stroev_V_M_PMD/lib/main.dart

227 lines
6.7 KiB
Dart
Raw Normal View History

2024-10-01 20:53:17 +04:00
import 'package:flutter/material.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'),
),
2024-10-02 22:51:30 +04:00
body: const MyWidget()
/*Column(
2024-10-01 20:53:17 +04:00
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(", ")}'),
);
},
),
),
],
2024-10-02 22:51:30 +04:00
)*/,
);
}
}
class MyWidget extends StatelessWidget {
const MyWidget ({super.key});
@override
Widget build(BuildContext context) {
final data = [
_CardData(
text: "Hello",
icon: Icons.warning_amber,
descriptionText: "mumumu"),
_CardData(
text: 'H',
descriptionText: "pupupu",),
_CardData(
text: "LLo",
icon: Icons.dangerous,
descriptionText: "kukuku"),
];
return Center(
child:SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: data.map((e) => _Card.fromData(e)).toList(),
),
)
);
}
}
class _CardData{
final String text;
final IconData icon;
final String descriptionText;
final String? imageUrl;
_CardData({required this.text,
this.icon = Icons.ac_unit_outlined,
required this.descriptionText,
this.imageUrl,});
}
class _Card extends StatelessWidget {
final String text;
final IconData icon;
final String descriptionText;
final String? imageUrl;
const _Card(this.text, {
this.icon = Icons.ac_unit_outlined,
required this.descriptionText,
this.imageUrl = 'https://distribution.faceit-cdn.net/images/679409f5-2896-4942-b976-62f5d31bd9eb.jpeg',
});
factory _Card.fromData(_CardData data) => _Card(data.text,
icon: data.icon,
descriptionText: data.descriptionText);
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.only(top: 16),
decoration: BoxDecoration(
color: Colors.orangeAccent,
borderRadius: BorderRadius.circular(20),
),
padding: const EdgeInsets.all(16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(20),
child: SizedBox(
height: 140,
width: 100,
child: Image.network(imageUrl ?? '',
fit: BoxFit.cover,
errorBuilder: (_, __, ___) => const Placeholder(),),
),
),
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(text, style: Theme.of(context).textTheme.headlineLarge
),
Text(descriptionText, style: Theme.of(context).textTheme.bodyLarge)
],
),
),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Icon(icon),
),
],
2024-10-01 20:53:17 +04:00
),
);
}
2024-10-02 22:51:30 +04:00
}