diff --git a/lib/comment_model.dart b/lib/comment_model.dart index d174bcb..4913e8e 100644 --- a/lib/comment_model.dart +++ b/lib/comment_model.dart @@ -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, }); } diff --git a/lib/comments_widget.dart b/lib/comments_widget.dart index 227cf46..07cb5bd 100644 --- a/lib/comments_widget.dart +++ b/lib/comments_widget.dart @@ -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: - 'https://preview.free3d.com/img/2016/03/1875481443430303321/hld8c0oa.jpg', + 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: - 'https://us-tuna-sounds-images.voicemod.net/356aeabd-18d5-40d8-af31-b479f4eff183-1704672174928.png', + 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,19 +63,19 @@ 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, - ); + title: model.title, + text: model.text, + user: model.user, + ); @override Widget build(BuildContext context) { @@ -82,17 +98,28 @@ class _Comment extends StatelessWidget { child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - ClipRRect( - borderRadius: BorderRadius.circular(20), - child: SizedBox( - height: 140, - width: 100, - child: Image.network( - imageUrl ?? '', - fit: BoxFit.cover, - errorBuilder: (_, __, ___) => const Placeholder(), + Column( + children: [ + ClipRRect( + borderRadius: BorderRadius.circular(30), + child: SizedBox( + height: 80, + width: 80, + child: Image.network( + 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( @@ -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, - ) + ), ], ), ), diff --git a/lib/main.dart b/lib/main.dart index cec3ae4..45af0f2 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -40,7 +40,7 @@ class _MyHomePageState extends State { @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 { 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); + } } diff --git a/lib/user_model.dart b/lib/user_model.dart new file mode 100644 index 0000000..8bb91dc --- /dev/null +++ b/lib/user_model.dart @@ -0,0 +1,9 @@ +class UserModel { + final String nickname; + final String? avatarUrl; + + UserModel({ + required this.nickname, + this.avatarUrl, + }); +}