lab3-4
This commit is contained in:
parent
4260c7e1a5
commit
b56181b1c4
BIN
images/pizza.png
Normal file
BIN
images/pizza.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 669 KiB |
201
lib/main.dart
201
lib/main.dart
@ -1,6 +1,4 @@
|
|||||||
import 'dart:math';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'weekManager.dart';
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
@ -13,11 +11,12 @@ class MyApp extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: 'Flutter Demo',
|
title: 'Flutter Demo',
|
||||||
|
debugShowCheckedModeBanner: false,
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.orangeAccent),
|
||||||
useMaterial3: true,
|
useMaterial3: true,
|
||||||
),
|
),
|
||||||
home: const MyHomePage(title: 'Deadliner'),
|
home: const MyHomePage(title: 'Cards'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -32,92 +31,140 @@ class MyHomePage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _MyHomePageState extends State<MyHomePage> {
|
class _MyHomePageState extends State<MyHomePage> {
|
||||||
late List<WeekManager> _weekManagers;
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||||
|
title: Text(widget.title),
|
||||||
|
),
|
||||||
|
body: Padding(
|
||||||
|
padding: const EdgeInsets.all(20),
|
||||||
|
child: ListView.separated(
|
||||||
|
itemBuilder: (context, index) => GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => DetailPage(
|
||||||
|
name: "Pizza $index",
|
||||||
|
price: 150.0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: CardWidget(name: "Pizza $index", price: 150.0),
|
||||||
|
),
|
||||||
|
separatorBuilder: (context, index) => const SizedBox(height: 20),
|
||||||
|
itemCount: 5,
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class CardWidget extends StatefulWidget {
|
||||||
|
const CardWidget({super.key, required this.name, required this.price});
|
||||||
|
|
||||||
|
final String name;
|
||||||
|
final double price;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
State<StatefulWidget> createState() => _CardWidgetState();
|
||||||
super.initState();
|
}
|
||||||
final random = Random();
|
|
||||||
_weekManagers = List.generate(5, (index) {
|
|
||||||
DateTime deadline = DateTime.now().add(Duration(days: random.nextInt(365)));
|
|
||||||
DateTime currentDate = DateTime.now().add(Duration(days: random.nextInt(365)));
|
|
||||||
return WeekManager(deadline, currentDate);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _incrementCounter() async {
|
class _CardWidgetState extends State<CardWidget> {
|
||||||
for (var weekManager in _weekManagers) {
|
bool _isFavourite = false;
|
||||||
await Future.delayed(const Duration(milliseconds: 500), () {
|
|
||||||
setState(() {
|
void toggleIsFavourite() {
|
||||||
weekManager.incrementCurrentDate();
|
setState(() {
|
||||||
weekManager.updateCurrentDay();
|
_isFavourite = !_isFavourite;
|
||||||
});
|
final snackBar = SnackBar(
|
||||||
});
|
duration: const Duration(seconds: 1),
|
||||||
}
|
content: Text(
|
||||||
|
_isFavourite ? 'Added to favorites' : 'Removed from favorites'),
|
||||||
|
);
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Container(
|
||||||
appBar: AppBar(
|
padding: const EdgeInsets.all(4),
|
||||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
decoration: BoxDecoration(
|
||||||
title: Text(widget.title),
|
border: Border.all(color: Colors.black12, width: 2),
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
),
|
),
|
||||||
body: Center(
|
child: Row(
|
||||||
child: Column(
|
children: [
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
// Image
|
||||||
children: <Widget>[
|
Expanded(
|
||||||
Text('Дедлайнер',
|
child: Image.asset(
|
||||||
style: Theme.of(context).textTheme.headlineMedium),
|
"images/pizza.png",
|
||||||
const SizedBox(height: 20),
|
fit: BoxFit.cover,
|
||||||
..._weekManagers.map((weekManager) => Column(
|
),
|
||||||
children: [
|
),
|
||||||
Text('Текущий день недели: ${weekManager.currentDay.name}'),
|
// Content
|
||||||
Text('Текущая дата: ${weekManager.formatDate(weekManager.currentDate)}'),
|
Expanded(
|
||||||
Text('Дней до дедлайна: ${weekManager.daysUntilDeadline}'),
|
flex: 2,
|
||||||
Text('Дата дедлайна: ${weekManager.formatDate(weekManager.deadline)}'),
|
child: Padding(
|
||||||
const SizedBox(height: 20),
|
padding: const EdgeInsets.only(left: 10),
|
||||||
],
|
child: Column(
|
||||||
)),
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
],
|
children: [
|
||||||
),
|
Text(widget.name, style: const TextStyle(fontSize: 18)),
|
||||||
),
|
Text(
|
||||||
floatingActionButton: FloatingActionButton(
|
"${widget.price} Руб",
|
||||||
onPressed: _incrementCounter,
|
style: const TextStyle(fontSize: 17, color: Colors.orange),
|
||||||
tooltip: 'Increment',
|
),
|
||||||
child: const Icon(Icons.add),
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// Like Button
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(_isFavourite ? Icons.favorite : Icons.favorite_border),
|
||||||
|
color: Colors.red,
|
||||||
|
onPressed: toggleIsFavourite,
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Weekday {
|
class DetailPage extends StatelessWidget {
|
||||||
Monday,
|
final String name;
|
||||||
Tuesday,
|
final double price;
|
||||||
Wednesday,
|
|
||||||
Thursday,
|
|
||||||
Friday,
|
|
||||||
Saturday,
|
|
||||||
Sunday
|
|
||||||
}
|
|
||||||
|
|
||||||
extension WeekdayExtension on Weekday {
|
const DetailPage({super.key, required this.name, required this.price});
|
||||||
String get name {
|
|
||||||
switch (this) {
|
@override
|
||||||
case Weekday.Monday:
|
Widget build(BuildContext context) {
|
||||||
return 'Понедельник';
|
return Scaffold(
|
||||||
case Weekday.Tuesday:
|
appBar: AppBar(
|
||||||
return 'Вторник';
|
title: Text(name),
|
||||||
case Weekday.Wednesday:
|
),
|
||||||
return 'Среда';
|
body: Padding(
|
||||||
case Weekday.Thursday:
|
padding: const EdgeInsets.all(20),
|
||||||
return 'Четверг';
|
child: Column(
|
||||||
case Weekday.Friday:
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
return 'Пятница';
|
children: [
|
||||||
case Weekday.Saturday:
|
Center(
|
||||||
return 'Суббота';
|
child: Image.asset(
|
||||||
case Weekday.Sunday:
|
"images/pizza.png",
|
||||||
return 'Воскресенье';
|
),
|
||||||
}
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
Text(name,
|
||||||
|
style:
|
||||||
|
const TextStyle(fontSize: 24, fontWeight: FontWeight.bold)),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
Text("$price Руб",
|
||||||
|
style: const TextStyle(fontSize: 20, color: Colors.orange)),
|
||||||
|
// Add more details here as needed
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
import 'package:intl/intl.dart';
|
|
||||||
import 'main.dart';
|
|
||||||
|
|
||||||
class WeekManager {
|
|
||||||
final DateTime _deadline;
|
|
||||||
DateTime _currentDate;
|
|
||||||
Weekday _currentDay;
|
|
||||||
|
|
||||||
WeekManager(this._deadline, this._currentDate)
|
|
||||||
: _currentDay = _getCurrentDayOfWeek(_currentDate);
|
|
||||||
|
|
||||||
DateTime get deadline => _deadline;
|
|
||||||
DateTime get currentDate => _currentDate;
|
|
||||||
Weekday get currentDay => _currentDay;
|
|
||||||
|
|
||||||
static Weekday _getCurrentDayOfWeek(DateTime date) {
|
|
||||||
switch (date.weekday) {
|
|
||||||
case 1:
|
|
||||||
return Weekday.Monday;
|
|
||||||
case 2:
|
|
||||||
return Weekday.Tuesday;
|
|
||||||
case 3:
|
|
||||||
return Weekday.Wednesday;
|
|
||||||
case 4:
|
|
||||||
return Weekday.Thursday;
|
|
||||||
case 5:
|
|
||||||
return Weekday.Friday;
|
|
||||||
case 6:
|
|
||||||
return Weekday.Saturday;
|
|
||||||
case 7:
|
|
||||||
return Weekday.Sunday;
|
|
||||||
default:
|
|
||||||
return Weekday.Monday;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int get daysUntilDeadline {
|
|
||||||
return _deadline.difference(_currentDate).inDays;
|
|
||||||
}
|
|
||||||
|
|
||||||
String formatDate(DateTime date) {
|
|
||||||
DateFormat formatter = DateFormat('dd-MM-yyyy');
|
|
||||||
return formatter.format(date);
|
|
||||||
}
|
|
||||||
|
|
||||||
void incrementCurrentDate() {
|
|
||||||
_currentDate = _currentDate.add(const Duration(days: 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
void updateCurrentDay() {
|
|
||||||
_currentDay = _getCurrentDayOfWeek(_currentDate);
|
|
||||||
}
|
|
||||||
}
|
|
@ -60,10 +60,9 @@ flutter:
|
|||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
|
|
||||||
# To add assets to your application, add an assets section, like this:
|
# To add assets to your application, add an assets section, like this:
|
||||||
# assets:
|
assets:
|
||||||
# - images/a_dot_burr.jpeg
|
- images/pizza.png
|
||||||
# - images/a_dot_ham.jpeg
|
# - images/a_dot_ham.jpeg
|
||||||
|
|
||||||
# An image asset can refer to one or more resolution-specific "variants", see
|
# An image asset can refer to one or more resolution-specific "variants", see
|
||||||
# https://flutter.dev/to/resolution-aware-images
|
# https://flutter.dev/to/resolution-aware-images
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user