86 lines
2.6 KiB
Dart
86 lines
2.6 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:pmu_new/data/repositories/PlacesRepository.dart';
|
|
import 'package:pmu_new/presentation/home_page/MyCard.dart';
|
|
import 'package:pmu_new/models/CardData.dart';
|
|
|
|
import '../../data/repositories/MockRepository.dart';
|
|
import '../details_page/details_page.dart';
|
|
|
|
class MyHomePage extends StatefulWidget {
|
|
const MyHomePage({super.key, required this.title});
|
|
|
|
final String title;
|
|
|
|
@override
|
|
State<MyHomePage> createState() => _MyHomePageState();
|
|
}
|
|
|
|
class _MyHomePageState extends State<MyHomePage> {
|
|
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
backgroundColor: Theme
|
|
.of(context)
|
|
.colorScheme
|
|
.inversePrimary,
|
|
title: Text(widget.title),
|
|
),
|
|
body: const CardWidget());
|
|
}
|
|
}
|
|
|
|
|
|
class CardWidget extends StatelessWidget {
|
|
const CardWidget({super.key});
|
|
|
|
void _showSnackBar(BuildContext context, String title, bool isLiked) {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
|
content: Text(
|
|
'$title ${isLiked ? 'Понравилось!' : 'Больше не нравится'}',
|
|
style: Theme
|
|
.of(context)
|
|
.textTheme
|
|
.bodyLarge,
|
|
),
|
|
backgroundColor: Colors.greenAccent,
|
|
duration: const Duration(seconds: 1),
|
|
));
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final data = PlacesRepository().loadData(q: 1780);
|
|
return Center(
|
|
child: FutureBuilder<List<CardData>?>(
|
|
future: data,
|
|
builder: (context, snapshot) =>
|
|
SingleChildScrollView(
|
|
child: snapshot.hasData ?
|
|
Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: snapshot.data?.map((e) {
|
|
return MyCard(
|
|
cardData: e,
|
|
onlike: (title, state) => _showSnackBar(context, title, state),
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) => DetailsPage(e)),
|
|
);
|
|
}
|
|
);
|
|
}).toList() ?? [],
|
|
)
|
|
: const CircularProgressIndicator()
|
|
)
|
|
),
|
|
);
|
|
}
|
|
} |