PMU/lib/main.dart

228 lines
6.5 KiB
Dart
Raw Normal View History

2024-09-22 20:35:55 +04:00
/*
2024-09-05 18:23:03 +04:00
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
2024-09-18 02:09:56 +04:00
debugShowCheckedModeBanner: false,
2024-09-05 18:23:03 +04:00
theme: ThemeData(
2024-09-18 02:09:56 +04:00
colorScheme: ColorScheme.fromSeed(seedColor: Colors.orangeAccent),
2024-09-05 18:23:03 +04:00
useMaterial3: true,
),
2024-09-18 02:09:56 +04:00
home: const MyHomePage(title: 'Cards'),
2024-09-05 18:23:03 +04:00
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
2024-09-18 02:09:56 +04:00
@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(
2024-09-18 13:37:08 +04:00
child: CardWidget(name: "Pizza $index", price: 150.0),
2024-09-18 02:09:56 +04:00
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailPage(
name: "Pizza $index",
price: 150.0,
),
),
);
},
),
separatorBuilder: (context, index) => const SizedBox(height: 20),
2024-09-18 13:37:08 +04:00
itemCount: 10,
2024-09-18 02:09:56 +04:00
)));
}
}
class CardWidget extends StatefulWidget {
const CardWidget({super.key, required this.name, required this.price});
final String name;
final double price;
2024-09-10 23:39:25 +04:00
@override
2024-09-18 02:09:56 +04:00
State<StatefulWidget> createState() => _CardWidgetState();
}
class _CardWidgetState extends State<CardWidget> {
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);
2024-09-10 23:39:25 +04:00
});
}
2024-09-18 02:09:56 +04:00
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(
2024-09-18 13:37:08 +04:00
border: Border.all(color: Colors.deepOrangeAccent, width: 2),
2024-09-18 02:09:56 +04:00
borderRadius: BorderRadius.circular(20),
),
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,
),
],
),
);
2024-09-10 23:39:25 +04:00
}
2024-09-18 02:09:56 +04:00
}
class DetailPage extends StatelessWidget {
final String name;
final double price;
const DetailPage({super.key, required this.name, required this.price});
2024-09-05 18:23:03 +04:00
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
2024-09-18 02:09:56 +04:00
title: Text(name),
2024-09-05 18:23:03 +04:00
),
2024-09-18 02:09:56 +04:00
body: Padding(
padding: const EdgeInsets.all(20),
2024-09-05 18:23:03 +04:00
child: Column(
2024-09-18 02:09:56 +04:00
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Center(
child: Image.asset(
"images/pizza.png",
),
),
2024-09-10 23:39:25 +04:00
const SizedBox(height: 20),
2024-09-18 02:09:56 +04:00
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
2024-09-05 18:23:03 +04:00
],
),
),
);
}
}
2024-09-22 20:35:55 +04:00
*/
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_app/components/locale/l10n/app_locale.dart';
import 'package:flutter_app/data/repositories/potter_repository.dart';
import 'package:flutter_app/presentation/home_page/bloc/bloc.dart';
import 'package:flutter_app/presentation/home_page/home_page.dart';
import 'package:flutter_app/presentation/like_bloc/like_bloc.dart';
import 'package:flutter_app/presentation/locale_bloc/locale_bloc.dart';
import 'package:flutter_app/presentation/locale_bloc/locale_state.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return BlocProvider<LocaleBloc>(
lazy: false,
create: (context) => LocaleBloc(Locale(Platform.localeName)),
child: BlocBuilder<LocaleBloc, LocaleState>(
builder: (context, state) {
return MaterialApp(
title: 'Flutter Demo',
locale: state.currentLocale,
localizationsDelegates: AppLocale.localizationsDelegates,
supportedLocales: AppLocale.supportedLocales,
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.orangeAccent),
useMaterial3: true,
),
home: RepositoryProvider<PotterRepository>(
lazy: true,
create: (_) => PotterRepository(),
child: BlocProvider<LikeBloc>(
lazy: false,
create: (context) => LikeBloc(),
child: BlocProvider<HomeBloc>(
lazy: false,
create: (context) => HomeBloc(context.read<PotterRepository>()),
child: const HomePage(),
),
),
),
);
},
),
);
}
}