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,5 +1,4 @@
import 'package:flutter/material.dart';
import 'layout/layout_scaffold.dart';
///
/// 应用页
@@ -14,11 +13,6 @@ class App extends StatefulWidget {
class _AppState extends State<App> {
@override
Widget build(BuildContext context) {
return LayoutScaffold(
appBar: AppBar(
title: const Text('满席'),
),
body: null,
);
return Container();
}
}

View File

@@ -1,41 +0,0 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class LayoutScaffold extends StatelessWidget {
final AppBar appBar;
final Widget? body;
const LayoutScaffold({
Key? key,
required this.appBar,
this.body,
}) : super(key: key);
@override
Widget build(BuildContext context) {
Text title = appBar.title as Text;
return Scaffold(
appBar: PreferredSize(
preferredSize: const Size.fromHeight(60),
child: AppBar(
actions: appBar.actions,
leading: appBar.leading,
title: Text(
title.data ?? '',
style: const TextStyle(
fontSize: 25,
),
),
centerTitle: true,
bottom: appBar.bottom,
systemOverlayStyle: const SystemUiOverlayStyle(
statusBarColor: Colors.transparent, //设置为透明
statusBarIconBrightness: Brightness.dark,
),
),
),
body: body,
);
}
}

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(
return MasonryGridView.count(
shrinkWrap: true,
itemCount: _list.length,
crossAxisCount: 2,
itemBuilder: cardBuilder,
padding: const EdgeInsets.only(top: 8),
mainAxisSpacing: 12.0,
crossAxisSpacing: 6.0,
),
mainAxisSpacing: 6.0,
// crossAxisSpacing: 4.0,
);
}
@@ -124,15 +109,16 @@ class _LifeState extends State<Life> {
return Card(
key: ValueKey(item["id"]),
elevation: 8,
color: Theme.of(context).colorScheme.background,
clipBehavior: Clip.antiAlias,
elevation: 3,
color: Theme.of(context).colorScheme.tertiary,
child: GestureDetector(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
InkWell(
child: Image.asset(
item["thumbnail"],
),
onTap: () {},
Image.asset(
item['thumbnail'],
fit: BoxFit.fitWidth,
),
ListTile(
title: Text(
@@ -143,17 +129,10 @@ class _LifeState extends State<Life> {
),
overflow: TextOverflow.ellipsis,
),
isThreeLine: true,
// 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(
@@ -166,14 +145,13 @@ class _LifeState extends State<Life> {
fontSize: 11,
),
),
)
],
),
onTap: () {},
),
InkWell(
GestureDetector(
excludeFromSemantics: true,
child: Icon(
item["hasLiked"] ? Icons.favorite : Icons.favorite_border,
item["hasLiked"]
? Icons.favorite
: Icons.favorite_border,
color: Theme.of(context).primaryColor,
),
onTap: () {
@@ -187,6 +165,9 @@ class _LifeState extends State<Life> {
)
],
),
);
onTap: () {
printWhenDebug(123);
},
));
}
}

View File

@@ -1,20 +1,20 @@
import 'package:flutter/material.dart';
import 'layout/layout_scaffold.dart';
///
/// 【我的】页
///
class Mine extends StatelessWidget {
class Mine extends StatefulWidget {
const Mine({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return LayoutScaffold(
appBar: AppBar(
title: const Text('在下'),
),
State<Mine> createState() => _MineState();
}
);
class _MineState extends State<Mine> {
@override
Widget build(BuildContext context) {
return Container();
// return Container();
}
}

View File

@@ -1,17 +1,10 @@
import 'package:flutter/material.dart';
import 'layout/layout_scaffold.dart';
class News extends StatelessWidget {
const News({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return LayoutScaffold(
appBar: AppBar(
title: const Text('道听'),
),
body: null,
);
return Container();
}
}

View File

@@ -175,7 +175,7 @@ flutter_native_splash:
# platform.
#android: false
#ios: false
web: false
#web: false
# The position of the splash image can be set with android_gravity, ios_content_mode, and
# web_image_mode parameters. All default to center.

View File

@@ -30,7 +30,6 @@
<title>bistro</title>
<link rel="manifest" href="manifest.json">
<script src="splash/splash.js"></script>
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
<link rel="stylesheet" type="text/css" href="splash/style.css">
</head>
<body> <picture id="splash">