Compare commits

..

5 Commits

Author SHA1 Message Date
40b9d1d9b6 LabWork03 Some additions 2024-09-13 01:19:44 +04:00
4913dc0fe7 LabWork03 Comments is done 2024-09-13 00:51:36 +04:00
3440713e50 LabWork02 ToDo List is done 2024-09-11 20:13:39 +04:00
3a8b49f9c9 LabWork01 remove the DEBUG banner 2024-09-10 02:00:11 +04:00
e73cee57a3 LabWork01 Done 2024-09-10 01:41:34 +04:00
4 changed files with 207 additions and 81 deletions

13
lib/comment_model.dart Normal file
View File

@ -0,0 +1,13 @@
import 'user_model.dart';
class CommentModel {
final String title;
final String text;
final UserModel user;
CommentModel({
required this.title,
required this.text,
required this.user,
});
}

147
lib/comments_widget.dart Normal file
View File

@ -0,0 +1,147 @@
import 'package:flutter/material.dart';
import 'comment_model.dart';
import 'user_model.dart';
class CommentsWidget extends StatelessWidget {
const CommentsWidget({super.key});
@override
Widget build(BuildContext context) {
final data = [
CommentModel(
title: 'Oh my god',
text: 'this app is so cool ' * 10,
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',
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',
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',
),
),
];
return SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: data.map((e) => _Comment.fromData(e)).toList(),
),
);
}
}
class _Comment extends StatelessWidget {
final String title;
final String text;
final UserModel? user;
const _Comment({
required this.title,
required this.text,
this.user,
});
factory _Comment.fromData(CommentModel model) => _Comment(
title: model.title,
text: model.text,
user: model.user,
);
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.all(16),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white70,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: Colors.grey),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(.5),
spreadRadius: 4,
offset: const Offset(0, 5),
blurRadius: 8,
),
],
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
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(
padding: const EdgeInsets.only(left: 16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: Theme.of(context).textTheme.headlineSmall,
),
const SizedBox(height: 8),
Text(
text,
style: Theme.of(context).textTheme.bodyLarge,
),
],
),
),
),
],
),
);
}
}

View File

@ -1,5 +1,9 @@
import 'dart:math';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'comments_widget.dart';
void main() { void main() {
runApp(const MyApp()); runApp(const MyApp());
} }
@ -7,31 +11,16 @@ void main() {
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
const MyApp({super.key}); const MyApp({super.key});
// This widget is the root of your application.
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
title: 'Flutter Demo', title: 'Comments App',
debugShowCheckedModeBanner: false,
theme: ThemeData( theme: ThemeData(
// This is the theme of your application. colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
//
// TRY THIS: Try running your application with "flutter run". You'll see
// the application has a purple toolbar. Then, without quitting the app,
// try changing the seedColor in the colorScheme below to Colors.green
// and then invoke "hot reload" (save your changes or press the "hot
// reload" button in a Flutter-supported IDE, or press "r" if you used
// the command line to start the app).
//
// Notice that the counter didn't reset back to zero; the application
// state is not lost during the reload. To reset the state, use hot
// restart instead.
//
// This works for code too, not just values: Most code changes can be
// tested with just a hot reload.
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true, useMaterial3: true,
), ),
home: const MyHomePage(title: 'Flutter Demo Home Page'), home: const MyHomePage(title: 'Comments App'),
); );
} }
} }
@ -39,15 +28,6 @@ class MyApp extends StatelessWidget {
class MyHomePage extends StatefulWidget { class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title}); const MyHomePage({super.key, required this.title});
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title; final String title;
@override @override
@ -55,71 +35,48 @@ class MyHomePage extends StatefulWidget {
} }
class _MyHomePageState extends State<MyHomePage> { class _MyHomePageState extends State<MyHomePage> {
int _counter = 0; Color _color = Colors.transparent;
void _incrementCounter() { @override
setState(() { void initState() {
// This call to setState tells the Flutter framework that something has super.initState();
// changed in this State, which causes it to rerun the build method below _color = _generateColor();
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
// TRY THIS: Try changing the color here to a specific color (to backgroundColor: _color,
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar title: Column(
// change color while the other colors stay the same. crossAxisAlignment: CrossAxisAlignment.start,
backgroundColor: Theme.of(context).colorScheme.inversePrimary, children: [
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
//
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
// action in the IDE, or press "p" in the console), to see the
// wireframe for each widget.
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text( Text(
'$_counter', widget.title,
style: Theme.of(context).textTheme.headlineMedium, style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
)),
Text(
'made by Factorino',
style: TextStyle(
fontSize: 12,
fontStyle: FontStyle.italic,
),
), ),
], ],
), ),
), ),
floatingActionButton: FloatingActionButton( body: const CommentsWidget(),
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
); );
} }
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
View File

@ -0,0 +1,9 @@
class UserModel {
final String nickname;
final String? avatarUrl;
UserModel({
required this.nickname,
this.avatarUrl,
});
}