добавил немного красоты в 5 лабу

This commit is contained in:
Timourka 2024-10-02 14:46:30 +04:00
parent de9e03155d
commit ce3ed67612
3 changed files with 31 additions and 11 deletions

View File

@ -30,7 +30,7 @@ class DetailsPage extends StatelessWidget {
),
),
Container(
margin: const EdgeInsets.all(20),
margin: const EdgeInsets.only(left: 20, top: 20, right: 20),
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),

View File

@ -5,12 +5,16 @@ typedef OnLikeCallback = void Function(bool isLiked)?;
class _Card extends StatefulWidget {
final String _text;
final String? description;
List<String>? descriptionByLines;
List<Widget>? descriptionWidgets;
final String? imageUrl;
final OnLikeCallback onLike;
final VoidCallback? onTap;
const _Card(this._text, {Key? key, this.imageUrl, this.description, this.onLike, this.onTap})
: super(key: key);
_Card(this._text, {Key? key, this.imageUrl, this.description, this.onLike, this.onTap})
: super(key: key){
descriptionByLines = (description ?? '').split('\n');
}
factory _Card.fromData(
CardData data, {
@ -38,7 +42,7 @@ class _CardState extends State<_Card> {
onTap: widget.onTap,
child: Container(
margin: const EdgeInsets.all(10),
constraints: const BoxConstraints(minHeight: 140, maxHeight: 212),
constraints: const BoxConstraints(minHeight: 140, maxHeight: 255),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.amber,
@ -78,14 +82,12 @@ class _CardState extends State<_Card> {
widget._text,
style: Theme.of(context).textTheme.headlineMedium,
overflow: TextOverflow.ellipsis,
maxLines: 4,
maxLines: 2,
),
Flexible(
child: Text(
widget.description ?? '',
...(widget.descriptionByLines ?? ['']).map((e) => Text(
e,
style: Theme.of(context).textTheme.bodyLarge,
overflow: TextOverflow.ellipsis,
maxLines: 7,
),
),
],

View File

@ -37,10 +37,15 @@ class _BodyState extends State<Body> {
final searchController = TextEditingController();
late Future<List<CardData>?> data;
final repo = PotterRepository();
bool isLoading = false;
@override
void initState() {
data = repo.loadData(onError: (e) => showErrorDialog(context, error: e));
isLoading = true;
data.then((_) => setState(() {
isLoading = false; // Остановить индикатор при завершении загрузки
}));
super.initState();
}
@ -58,7 +63,13 @@ class _BodyState extends State<Body> {
);
cards.children.add(Padding(
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(
snapshot.data
@ -72,7 +83,7 @@ class _BodyState extends State<Body> {
.toList() ??
[],
);
return snapshot.hasData
return !isLoading
? SingleChildScrollView(
child: cards,
)
@ -92,11 +103,18 @@ class _BodyState extends State<Body> {
backgroundColor: Colors.amberAccent,
controller: searchController,
onChanged: (search) {
setState(() {
isLoading = true;
});
setState(() {
data = repo.loadData(
q: search,
onError: (e) => showErrorDialog(context, error: e),
);
data.then((_) => setState(() {
isLoading =
false; // Остановить индикатор при завершении загрузки
}));
});
},
),