добавил немного красоты в 5 лабу
This commit is contained in:
parent
de9e03155d
commit
ce3ed67612
@ -30,7 +30,7 @@ class DetailsPage extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Container(
|
Container(
|
||||||
margin: const EdgeInsets.all(20),
|
margin: const EdgeInsets.only(left: 20, top: 20, right: 20),
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
@ -5,12 +5,16 @@ typedef OnLikeCallback = void Function(bool isLiked)?;
|
|||||||
class _Card extends StatefulWidget {
|
class _Card extends StatefulWidget {
|
||||||
final String _text;
|
final String _text;
|
||||||
final String? description;
|
final String? description;
|
||||||
|
List<String>? descriptionByLines;
|
||||||
|
List<Widget>? descriptionWidgets;
|
||||||
final String? imageUrl;
|
final String? imageUrl;
|
||||||
final OnLikeCallback onLike;
|
final OnLikeCallback onLike;
|
||||||
final VoidCallback? onTap;
|
final VoidCallback? onTap;
|
||||||
|
|
||||||
const _Card(this._text, {Key? key, this.imageUrl, this.description, this.onLike, this.onTap})
|
_Card(this._text, {Key? key, this.imageUrl, this.description, this.onLike, this.onTap})
|
||||||
: super(key: key);
|
: super(key: key){
|
||||||
|
descriptionByLines = (description ?? '').split('\n');
|
||||||
|
}
|
||||||
|
|
||||||
factory _Card.fromData(
|
factory _Card.fromData(
|
||||||
CardData data, {
|
CardData data, {
|
||||||
@ -38,7 +42,7 @@ class _CardState extends State<_Card> {
|
|||||||
onTap: widget.onTap,
|
onTap: widget.onTap,
|
||||||
child: Container(
|
child: Container(
|
||||||
margin: const EdgeInsets.all(10),
|
margin: const EdgeInsets.all(10),
|
||||||
constraints: const BoxConstraints(minHeight: 140, maxHeight: 212),
|
constraints: const BoxConstraints(minHeight: 140, maxHeight: 255),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
color: Colors.amber,
|
color: Colors.amber,
|
||||||
@ -78,14 +82,12 @@ class _CardState extends State<_Card> {
|
|||||||
widget._text,
|
widget._text,
|
||||||
style: Theme.of(context).textTheme.headlineMedium,
|
style: Theme.of(context).textTheme.headlineMedium,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
maxLines: 4,
|
maxLines: 2,
|
||||||
),
|
),
|
||||||
Flexible(
|
...(widget.descriptionByLines ?? ['']).map((e) => Text(
|
||||||
child: Text(
|
e,
|
||||||
widget.description ?? '',
|
|
||||||
style: Theme.of(context).textTheme.bodyLarge,
|
style: Theme.of(context).textTheme.bodyLarge,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
maxLines: 7,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -37,10 +37,15 @@ class _BodyState extends State<Body> {
|
|||||||
final searchController = TextEditingController();
|
final searchController = TextEditingController();
|
||||||
late Future<List<CardData>?> data;
|
late Future<List<CardData>?> data;
|
||||||
final repo = PotterRepository();
|
final repo = PotterRepository();
|
||||||
|
bool isLoading = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
data = repo.loadData(onError: (e) => showErrorDialog(context, error: e));
|
data = repo.loadData(onError: (e) => showErrorDialog(context, error: e));
|
||||||
|
isLoading = true;
|
||||||
|
data.then((_) => setState(() {
|
||||||
|
isLoading = false; // Остановить индикатор при завершении загрузки
|
||||||
|
}));
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +63,13 @@ class _BodyState extends State<Body> {
|
|||||||
);
|
);
|
||||||
cards.children.add(Padding(
|
cards.children.add(Padding(
|
||||||
padding: const EdgeInsets.only(left: 8.0, right: 8),
|
padding: const EdgeInsets.only(left: 8.0, right: 8),
|
||||||
child: CupertinoSearchTextField(),
|
child: CupertinoSearchTextField(
|
||||||
|
borderRadius: BorderRadius.only(
|
||||||
|
bottomLeft: Radius.circular(20),
|
||||||
|
bottomRight: Radius.circular(20),
|
||||||
|
),
|
||||||
|
backgroundColor: Colors.amberAccent,
|
||||||
|
),
|
||||||
));
|
));
|
||||||
cards.children.addAll(
|
cards.children.addAll(
|
||||||
snapshot.data
|
snapshot.data
|
||||||
@ -72,7 +83,7 @@ class _BodyState extends State<Body> {
|
|||||||
.toList() ??
|
.toList() ??
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
return snapshot.hasData
|
return !isLoading
|
||||||
? SingleChildScrollView(
|
? SingleChildScrollView(
|
||||||
child: cards,
|
child: cards,
|
||||||
)
|
)
|
||||||
@ -92,11 +103,18 @@ class _BodyState extends State<Body> {
|
|||||||
backgroundColor: Colors.amberAccent,
|
backgroundColor: Colors.amberAccent,
|
||||||
controller: searchController,
|
controller: searchController,
|
||||||
onChanged: (search) {
|
onChanged: (search) {
|
||||||
|
setState(() {
|
||||||
|
isLoading = true;
|
||||||
|
});
|
||||||
setState(() {
|
setState(() {
|
||||||
data = repo.loadData(
|
data = repo.loadData(
|
||||||
q: search,
|
q: search,
|
||||||
onError: (e) => showErrorDialog(context, error: e),
|
onError: (e) => showErrorDialog(context, error: e),
|
||||||
);
|
);
|
||||||
|
data.then((_) => setState(() {
|
||||||
|
isLoading =
|
||||||
|
false; // Остановить индикатор при завершении загрузки
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user