LabWork03 Some additions
This commit is contained in:
parent
4913dc0fe7
commit
40b9d1d9b6
@ -1,11 +1,13 @@
|
||||
import 'user_model.dart';
|
||||
|
||||
class CommentModel {
|
||||
final String title;
|
||||
final String text;
|
||||
final String? imageUrl;
|
||||
final UserModel user;
|
||||
|
||||
CommentModel({
|
||||
required this.title,
|
||||
required this.text,
|
||||
this.imageUrl,
|
||||
required this.user,
|
||||
});
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'comment_model.dart';
|
||||
import 'user_model.dart';
|
||||
|
||||
class CommentsWidget extends StatelessWidget {
|
||||
const CommentsWidget({super.key});
|
||||
@ -11,27 +12,42 @@ class CommentsWidget extends StatelessWidget {
|
||||
CommentModel(
|
||||
title: 'Oh my god',
|
||||
text: 'this app is so cool ' * 10,
|
||||
imageUrl:
|
||||
user: UserModel(
|
||||
nickname: 'Steve',
|
||||
avatarUrl:
|
||||
'https://preview.free3d.com/img/2016/03/1875481443430303321/hld8c0oa.jpg',
|
||||
),
|
||||
),
|
||||
CommentModel(
|
||||
title: 'Listen to me',
|
||||
text: 'This app is like Half-Life 3 - it will never be released',
|
||||
imageUrl:
|
||||
user: UserModel(
|
||||
nickname: 'G-Man',
|
||||
avatarUrl:
|
||||
'https://us-tuna-sounds-images.voicemod.net/356aeabd-18d5-40d8-af31-b479f4eff183-1704672174928.png',
|
||||
),
|
||||
),
|
||||
CommentModel(
|
||||
title: 'BREAKING!!!',
|
||||
text: 'The next lab work will have DLC in the form of likes',
|
||||
imageUrl: 'https://i.playground.ru/p/BWixorSTeZQfoPvdVL9lgA.jpeg',
|
||||
user: UserModel(
|
||||
nickname: 'Bethesda',
|
||||
avatarUrl: 'https://i.playground.ru/p/BWixorSTeZQfoPvdVL9lgA.jpeg',
|
||||
),
|
||||
),
|
||||
CommentModel(
|
||||
title: 'Test',
|
||||
text: 'Test',
|
||||
user: UserModel(
|
||||
nickname: 'Noname',
|
||||
),
|
||||
),
|
||||
CommentModel(
|
||||
title: 'Test',
|
||||
text: 'Test',
|
||||
user: UserModel(
|
||||
nickname: 'Noname',
|
||||
),
|
||||
),
|
||||
];
|
||||
|
||||
@ -47,18 +63,18 @@ class CommentsWidget extends StatelessWidget {
|
||||
class _Comment extends StatelessWidget {
|
||||
final String title;
|
||||
final String text;
|
||||
final String? imageUrl;
|
||||
final UserModel? user;
|
||||
|
||||
const _Comment({
|
||||
required this.title,
|
||||
required this.text,
|
||||
this.imageUrl,
|
||||
this.user,
|
||||
});
|
||||
|
||||
factory _Comment.fromData(CommentModel model) => _Comment(
|
||||
title: model.title,
|
||||
text: model.text,
|
||||
imageUrl: model.imageUrl,
|
||||
user: model.user,
|
||||
);
|
||||
|
||||
@override
|
||||
@ -81,19 +97,30 @@ class _Comment extends StatelessWidget {
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
borderRadius: BorderRadius.circular(30),
|
||||
child: SizedBox(
|
||||
height: 140,
|
||||
width: 100,
|
||||
height: 80,
|
||||
width: 80,
|
||||
child: Image.network(
|
||||
imageUrl ?? '',
|
||||
user!.avatarUrl != null && user!.avatarUrl!.isNotEmpty
|
||||
? user!.avatarUrl!
|
||||
: '',
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, __, ___) => const Placeholder(),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
user!.nickname,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 16.0),
|
||||
@ -102,12 +129,13 @@ class _Comment extends StatelessWidget {
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: Theme.of(context).textTheme.headlineLarge,
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
text,
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -40,7 +40,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_color = Color((Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0);
|
||||
_color = _generateColor();
|
||||
}
|
||||
|
||||
@override
|
||||
@ -70,4 +70,13 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
body: const CommentsWidget(),
|
||||
);
|
||||
}
|
||||
|
||||
Color _generateColor() {
|
||||
final Random random = Random();
|
||||
final int red = (random.nextInt(106) + 150);
|
||||
final int green = (random.nextInt(106) + 150);
|
||||
final int blue = (random.nextInt(106) + 150);
|
||||
|
||||
return Color.fromARGB(255, red, green, blue);
|
||||
}
|
||||
}
|
||||
|
9
lib/user_model.dart
Normal file
9
lib/user_model.dart
Normal file
@ -0,0 +1,9 @@
|
||||
class UserModel {
|
||||
final String nickname;
|
||||
final String? avatarUrl;
|
||||
|
||||
UserModel({
|
||||
required this.nickname,
|
||||
this.avatarUrl,
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user