diff --git a/images/pizza.png b/images/pizza.png new file mode 100644 index 0000000..8e9c8a9 Binary files /dev/null and b/images/pizza.png differ diff --git a/lib/main.dart b/lib/main.dart index 659463d..4de09d2 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,4 @@ -import 'dart:math'; import 'package:flutter/material.dart'; -import 'weekManager.dart'; void main() { runApp(const MyApp()); @@ -13,11 +11,12 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', + debugShowCheckedModeBanner: false, theme: ThemeData( - colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue), + colorScheme: ColorScheme.fromSeed(seedColor: Colors.orangeAccent), useMaterial3: true, ), - home: const MyHomePage(title: 'Deadliner'), + home: const MyHomePage(title: 'Cards'), ); } } @@ -32,92 +31,140 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State { - late List _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 - void initState() { - 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); - }); - } + State createState() => _CardWidgetState(); +} - Future _incrementCounter() async { - for (var weekManager in _weekManagers) { - await Future.delayed(const Duration(milliseconds: 500), () { - setState(() { - weekManager.incrementCurrentDate(); - weekManager.updateCurrentDay(); - }); - }); - } +class _CardWidgetState extends State { + bool _isFavourite = false; + + void toggleIsFavourite() { + setState(() { + _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 Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - backgroundColor: Theme.of(context).colorScheme.inversePrimary, - title: Text(widget.title), + return Container( + padding: const EdgeInsets.all(4), + decoration: BoxDecoration( + border: Border.all(color: Colors.black12, width: 2), + borderRadius: BorderRadius.circular(20), ), - body: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text('Дедлайнер', - style: Theme.of(context).textTheme.headlineMedium), - const SizedBox(height: 20), - ..._weekManagers.map((weekManager) => Column( - children: [ - Text('Текущий день недели: ${weekManager.currentDay.name}'), - Text('Текущая дата: ${weekManager.formatDate(weekManager.currentDate)}'), - Text('Дней до дедлайна: ${weekManager.daysUntilDeadline}'), - Text('Дата дедлайна: ${weekManager.formatDate(weekManager.deadline)}'), - const SizedBox(height: 20), - ], - )), - ], - ), - ), - floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: const Icon(Icons.add), + child: Row( + children: [ + // Image + Expanded( + child: Image.asset( + "images/pizza.png", + fit: BoxFit.cover, + ), + ), + // Content + Expanded( + flex: 2, + child: Padding( + padding: const EdgeInsets.only(left: 10), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(widget.name, style: const TextStyle(fontSize: 18)), + Text( + "${widget.price} Руб", + style: const TextStyle(fontSize: 17, color: Colors.orange), + ), + ], + ), + ), + ), + // Like Button + IconButton( + icon: Icon(_isFavourite ? Icons.favorite : Icons.favorite_border), + color: Colors.red, + onPressed: toggleIsFavourite, + ), + ], ), ); } } -enum Weekday { - Monday, - Tuesday, - Wednesday, - Thursday, - Friday, - Saturday, - Sunday -} +class DetailPage extends StatelessWidget { + final String name; + final double price; -extension WeekdayExtension on Weekday { - String get name { - switch (this) { - case Weekday.Monday: - return 'Понедельник'; - case Weekday.Tuesday: - return 'Вторник'; - case Weekday.Wednesday: - return 'Среда'; - case Weekday.Thursday: - return 'Четверг'; - case Weekday.Friday: - return 'Пятница'; - case Weekday.Saturday: - return 'Суббота'; - case Weekday.Sunday: - return 'Воскресенье'; - } + const DetailPage({super.key, required this.name, required this.price}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text(name), + ), + body: Padding( + padding: const EdgeInsets.all(20), + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Center( + child: Image.asset( + "images/pizza.png", + ), + ), + 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 + ], + ), + ), + ); } } diff --git a/lib/weekManager.dart b/lib/weekManager.dart deleted file mode 100644 index 55e6b32..0000000 --- a/lib/weekManager.dart +++ /dev/null @@ -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); - } -} diff --git a/pubspec.yaml b/pubspec.yaml index 7a99d67..05fcf8a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -60,10 +60,9 @@ flutter: uses-material-design: true # To add assets to your application, add an assets section, like this: - # assets: - # - images/a_dot_burr.jpeg + assets: + - images/pizza.png # - images/a_dot_ham.jpeg - # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/to/resolution-aware-images