lab3
This commit is contained in:
parent
d912a9656b
commit
20046f13f6
125
lib/main.dart
125
lib/main.dart
@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'CourseStatus.dart';
|
||||||
import 'University.dart';
|
import 'University.dart';
|
||||||
import 'student.dart';
|
import 'student.dart';
|
||||||
|
|
||||||
@ -52,8 +53,7 @@ class _UniversityScreenState extends State<UniversityScreen> {
|
|||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text('Строев Владимир, ПИбд-32'),
|
title: Text('Строев Владимир, ПИбд-32'),
|
||||||
),
|
),
|
||||||
body: const MyWidget()
|
body: Column(
|
||||||
/*Column(
|
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
@ -108,92 +108,74 @@ class _UniversityScreenState extends State<UniversityScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ListView.builder(
|
child: MyWidget(students: university.students),
|
||||||
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(", ")}'),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)*/,
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyWidget extends StatelessWidget {
|
class MyWidget extends StatelessWidget {
|
||||||
const MyWidget ({super.key});
|
final List<Student> students;
|
||||||
|
|
||||||
|
const MyWidget({super.key, required this.students});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final data = [
|
return SingleChildScrollView(
|
||||||
_CardData(
|
child: Column(
|
||||||
text: "Hello",
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
icon: Icons.warning_amber,
|
children: students.map((e) => _Card.fromData(e)).toList(),
|
||||||
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 {
|
class _Card extends StatelessWidget {
|
||||||
final String text;
|
final String name;
|
||||||
final IconData icon;
|
final int age;
|
||||||
final String descriptionText;
|
final List<String> courses;
|
||||||
final String? imageUrl;
|
final String? imageUrl;
|
||||||
|
|
||||||
const _Card(this.text, {
|
const _Card(this.name, {
|
||||||
this.icon = Icons.ac_unit_outlined,
|
required this.age,
|
||||||
required this.descriptionText,
|
required this.courses,
|
||||||
this.imageUrl = 'https://distribution.faceit-cdn.net/images/679409f5-2896-4942-b976-62f5d31bd9eb.jpeg',
|
this.imageUrl = 'https://gryazoveckij-r19.gosweb.gosuslugi.ru/netcat_files/460/2008/net_foto_muzh.jpg',
|
||||||
});
|
});
|
||||||
|
|
||||||
factory _Card.fromData(_CardData data) => _Card(data.text,
|
String getYearWord(int age) {
|
||||||
icon: data.icon,
|
if (age % 10 == 1) {
|
||||||
descriptionText: data.descriptionText);
|
return " год";
|
||||||
|
} else if (age % 10 < 5 && age % 10 != 0) {
|
||||||
|
return " года";
|
||||||
|
} else {
|
||||||
|
return " лет";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
factory _Card.fromData(Student data) => _Card(data.name,
|
||||||
|
age: data.age, courses: data.courses);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
margin: const EdgeInsets.only(top: 16),
|
margin: const EdgeInsets.only(top: 16, left: 16, right: 16, bottom: 16),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.orangeAccent,
|
color: Colors.blueAccent,
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.black.withOpacity(0.2),
|
||||||
|
spreadRadius: 2,
|
||||||
|
blurRadius: 5,
|
||||||
|
offset: Offset(0, 3),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: [
|
children: [
|
||||||
ClipRRect(
|
ClipRRect(
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
@ -201,26 +183,25 @@ class _Card extends StatelessWidget {
|
|||||||
height: 140,
|
height: 140,
|
||||||
width: 100,
|
width: 100,
|
||||||
child: Image.network(imageUrl ?? '',
|
child: Image.network(imageUrl ?? '',
|
||||||
fit: BoxFit.cover,
|
fit: BoxFit.cover,
|
||||||
errorBuilder: (_, __, ___) => const Placeholder(),),
|
errorBuilder: (_, __, ___) => const Placeholder(),),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
SizedBox(width: 16),
|
||||||
Flexible(
|
Flexible(
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(text, style: Theme.of(context).textTheme.headlineLarge
|
Text(name, style: Theme.of(context).textTheme.headlineLarge),
|
||||||
),
|
SizedBox(height: 8),
|
||||||
Text(descriptionText, style: Theme.of(context).textTheme.bodyLarge)
|
Text(age.toString() + getYearWord(age), style: Theme.of(context).textTheme.bodyLarge),
|
||||||
|
SizedBox(height: 8),
|
||||||
|
Text('Courses: ${courses.join(", ")}', style: Theme.of(context).textTheme.bodyMedium),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 8.0),
|
|
||||||
child: Icon(icon),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user