refactor(scaffold): 更新布局方式

This commit is contained in:
李东云
2023-03-29 14:48:42 +08:00
parent a201fdb91c
commit 6738f0bfde
7 changed files with 79 additions and 153 deletions

View File

@@ -1,10 +1,9 @@
import 'package:bistro/common/global.dart';
import 'package:flutter/material.dart';
import 'package:bistro/layout/layout_scaffold.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
class Life extends StatefulWidget {
const Life({Key? key}) : super(key: key);
final title = '途说';
@override
State<Life> createState() => _LifeState();
@@ -85,7 +84,7 @@ class _LifeState extends State<Life> {
{
'id': '10',
'thumbnail': 'res/assets/images/tiefutu.jpg',
'title': '标题10',
'title': '标题10标题10标题10标题10标题10标题10标题10标题10标题10标题10标题10标题10',
'author': '浅帅',
'hasLiked': true
},
@@ -94,28 +93,14 @@ class _LifeState extends State<Life> {
@override
Widget build(BuildContext context) {
return LayoutScaffold(
appBar: AppBar(
title: Text(widget.title),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.add,
color: Theme.of(context).primaryColor,
),
onPressed: () {},
)
],
),
body: MasonryGridView.count(
shrinkWrap: true,
itemCount: _list.length,
crossAxisCount: 2,
itemBuilder: cardBuilder,
padding: const EdgeInsets.only(top: 8),
mainAxisSpacing: 12.0,
crossAxisSpacing: 6.0,
),
return MasonryGridView.count(
shrinkWrap: true,
itemCount: _list.length,
crossAxisCount: 2,
itemBuilder: cardBuilder,
padding: const EdgeInsets.only(top: 8),
mainAxisSpacing: 6.0,
// crossAxisSpacing: 4.0,
);
}
@@ -123,70 +108,66 @@ class _LifeState extends State<Life> {
var item = _list[index];
return Card(
key: ValueKey(item["id"]),
elevation: 8,
color: Theme.of(context).colorScheme.background,
child: Column(
children: <Widget>[
InkWell(
child: Image.asset(
item["thumbnail"],
),
onTap: () {},
),
ListTile(
title: Text(
item["title"].toString(),
maxLines: 2,
style: const TextStyle(
fontSize: 13,
key: ValueKey(item["id"]),
clipBehavior: Clip.antiAlias,
elevation: 3,
color: Theme.of(context).colorScheme.tertiary,
child: GestureDetector(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset(
item['thumbnail'],
fit: BoxFit.fitWidth,
),
overflow: TextOverflow.ellipsis,
),
isThreeLine: true,
subtitle: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
InkWell(
child: Row(
children: <Widget>[
// Icon(
// Icons.person_outline,
// color: Theme.of(context).primaryColor,
// ),
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 100),
child: Text(
item['author'].toString(),
softWrap: true,
textAlign: TextAlign.left,
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: const TextStyle(
fontSize: 11,
),
ListTile(
title: Text(
item["title"].toString(),
maxLines: 2,
style: const TextStyle(
fontSize: 13,
),
overflow: TextOverflow.ellipsis,
),
// isThreeLine: true,
subtitle: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 100),
child: Text(
item['author'].toString(),
softWrap: true,
textAlign: TextAlign.left,
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: const TextStyle(
fontSize: 11,
),
)
],
),
onTap: () {},
),
),
GestureDetector(
excludeFromSemantics: true,
child: Icon(
item["hasLiked"]
? Icons.favorite
: Icons.favorite_border,
color: Theme.of(context).primaryColor,
),
onTap: () {
setState(() {
_list[index]["hasLiked"] = !item["hasLiked"];
});
},
),
],
),
InkWell(
child: Icon(
item["hasLiked"] ? Icons.favorite : Icons.favorite_border,
color: Theme.of(context).primaryColor,
),
onTap: () {
setState(() {
_list[index]["hasLiked"] = !item["hasLiked"];
});
},
),
],
),
)
],
),
);
)
],
),
onTap: () {
printWhenDebug(123);
},
));
}
}