import 'package:flutter/material.dart'; import 'package:mdp/models/card.dart'; import 'package:mdp/repositories/got_repository.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), home: const MyHomePage( title: Text("Персонажи Игры Престолов", style: TextStyle( fontSize: 28, fontWeight: FontWeight.w600, color: Color.fromRGBO(240, 240, 240, 1)))), ); } } class MyHomePage extends StatelessWidget { const MyHomePage({super.key, required this.title}); final Text title; @override Widget build(BuildContext context) { final data = GotRepository().loadData(); return Scaffold( appBar: AppBar( backgroundColor: Colors.black54, title: title, ), body: Center( child: FutureBuilder?>( future: data, builder: (context, snapshot) => SingleChildScrollView( child: snapshot.hasData ? Column( mainAxisAlignment: MainAxisAlignment.center, children: snapshot.data?.map((data) { return GestureDetector( child: Padding( padding: const EdgeInsets.only(bottom: 15, left: 7, right: 7, top: 5), child: Card( fullName: data.fullName, title: data.title, family: data.family, imageURL: data.imageUrl, ), ), onTap: () { Navigator.push( context, MaterialPageRoute( builder: (context) => CardInfo( fullName: data.fullName.toString(), title: data.title.toString(), family: data.family.toString(), imageURL: data.imageUrl.toString(), ), ), ); }, ); }).toList() ?? [], ) : const CircularProgressIndicator(), ), ), ) ); } } class Card extends StatefulWidget { const Card({super.key, required this.fullName, required this.title, required this.family, required this.imageURL}); final String? fullName; final String? title; final String? family; final String? imageURL; @override State createState() => _CardState(); } class _CardState extends State { bool _isFavourite = false; void toggleIsFavourite() { setState(() { _isFavourite = !_isFavourite; final snackBar = SnackBar( duration: const Duration(seconds: 1), backgroundColor: Colors.deepOrangeAccent, content: Text( _isFavourite ? 'Добавлено в любимое' : 'Удалено из любимого', style: const TextStyle(fontWeight: FontWeight.bold)) ); ScaffoldMessenger.of(context).showSnackBar(snackBar); }); } @override Widget build(BuildContext context) { return Stack( children: [ new Container( padding: const EdgeInsets.only(top: 50, bottom: 15, left: 40, right: 40), decoration: BoxDecoration( border: Border.all(color: Colors.black45, width: 2), borderRadius: BorderRadius.circular(40)), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Center( child: Image.network( widget.imageURL.toString()), ), Padding( padding: const EdgeInsets.only(top: 30, right: 30), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(widget.fullName.toString(), style: const TextStyle( fontSize: 22, fontWeight: FontWeight.bold, color: Color.fromRGBO(70, 70, 70, 1))), const SizedBox(height: 7), Text(widget.title.toString(), style: const TextStyle( fontSize: 22, color: Color.fromRGBO(70, 70, 70, 1), fontWeight: FontWeight.bold)) ], ), ) ], ), ), Positioned( right: 20, bottom: 10, child: IconButton( icon: Icon(_isFavourite ? Icons.favorite : Icons.favorite_border), color: Colors.purple, onPressed: toggleIsFavourite, )) ], ); } } class CardInfo extends StatelessWidget { final String fullName; final String title; final String family; final String imageURL; const CardInfo({super.key, required this.fullName, required this.title, required this.family, required this.imageURL}); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: Colors.deepOrangeAccent, title: Text(fullName, style: const TextStyle( fontSize: 28, fontWeight: FontWeight.w600, color: Color.fromRGBO(240, 240, 240, 1))), ), body: Padding( padding: const EdgeInsets.all(20), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Center( child: Image.network( imageURL), ), const SizedBox(height: 20), Text(fullName, style: const TextStyle( fontSize: 22, fontWeight: FontWeight.bold, color: Color.fromRGBO(70, 70, 70, 1))), const SizedBox(height: 10), Text(title, style: const TextStyle( fontSize: 22, color: Color.fromRGBO(70, 70, 70, 1), fontWeight: FontWeight.bold)), const SizedBox(height: 10), Text(family, style: const TextStyle( fontSize: 22, color: Color.fromRGBO(70, 70, 70, 1), fontWeight: FontWeight.bold)), ], ), ), ); } }