Compare commits
No commits in common. "LabWork03" and "master" have entirely different histories.
@ -1,13 +0,0 @@
|
|||||||
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,
|
|
||||||
});
|
|
||||||
}
|
|
@ -1,147 +0,0 @@
|
|||||||
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,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
119
lib/main.dart
119
lib/main.dart
@ -1,9 +1,5 @@
|
|||||||
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());
|
||||||
}
|
}
|
||||||
@ -11,16 +7,31 @@ 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: 'Comments App',
|
title: 'Flutter Demo',
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
// This is the theme of your application.
|
||||||
|
//
|
||||||
|
// 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: 'Comments App'),
|
home: const MyHomePage(title: 'Flutter Demo Home Page'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -28,6 +39,15 @@ 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
|
||||||
@ -35,48 +55,71 @@ class MyHomePage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _MyHomePageState extends State<MyHomePage> {
|
class _MyHomePageState extends State<MyHomePage> {
|
||||||
Color _color = Colors.transparent;
|
int _counter = 0;
|
||||||
|
|
||||||
@override
|
void _incrementCounter() {
|
||||||
void initState() {
|
setState(() {
|
||||||
super.initState();
|
// This call to setState tells the Flutter framework that something has
|
||||||
_color = _generateColor();
|
// changed in this State, which causes it to rerun the build method below
|
||||||
|
// 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(
|
||||||
backgroundColor: _color,
|
// TRY THIS: Try changing the color here to a specific color (to
|
||||||
title: Column(
|
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
// change color while the other colors stay the same.
|
||||||
children: [
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||||
|
// 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(
|
||||||
widget.title,
|
'$_counter',
|
||||||
style: TextStyle(
|
style: Theme.of(context).textTheme.headlineMedium,
|
||||||
fontSize: 20,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
)),
|
|
||||||
Text(
|
|
||||||
'made by Factorino',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 12,
|
|
||||||
fontStyle: FontStyle.italic,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
body: const CommentsWidget(),
|
floatingActionButton: FloatingActionButton(
|
||||||
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
class UserModel {
|
|
||||||
final String nickname;
|
|
||||||
final String? avatarUrl;
|
|
||||||
|
|
||||||
UserModel({
|
|
||||||
required this.nickname,
|
|
||||||
this.avatarUrl,
|
|
||||||
});
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user