更新placeholder-重写社区话题页面

hmxc
小赖 4 years ago
parent 49f9d8a8fe
commit 238fd09bc7

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

@ -530,6 +530,10 @@ class R {
static const String ASSETS_IMAGES_PHONE_LOGO_PNG = static const String ASSETS_IMAGES_PHONE_LOGO_PNG =
'assets/images/phone_logo.png'; 'assets/images/phone_logo.png';
/// ![preview](file:///Users/akufe/Documents/akuCommunity/assets/images/placeholder.webp)
static const String ASSETS_IMAGES_PLACEHOLDER_WEBP =
'assets/images/placeholder.webp';
/// ![preview](file:///Users/akufe/Documents/akuCommunity/assets/images/white.png) /// ![preview](file:///Users/akufe/Documents/akuCommunity/assets/images/white.png)
static const String ASSETS_IMAGES_WHITE_PNG = 'assets/images/white.png'; static const String ASSETS_IMAGES_WHITE_PNG = 'assets/images/white.png';

@ -14,6 +14,14 @@ class CommunityTopicModel {
List<ImgModel> headSculptureImgUrl; List<ImgModel> headSculptureImgUrl;
List<GambitThemeCommentVoList> gambitThemeCommentVoList; List<GambitThemeCommentVoList> gambitThemeCommentVoList;
String get firstImg {
var firstImg = '';
if (imgUrls?.isNotEmpty ?? false) {
firstImg = imgUrls?.first?.url ?? '';
}
return firstImg;
}
CommunityTopicModel( CommunityTopicModel(
{this.id, {this.id,
this.createId, this.createId,

@ -53,7 +53,7 @@ class _GoodsManagePageState extends State<GoodsManagePage> {
margin: EdgeInsets.only(right: 20.w), margin: EdgeInsets.only(right: 20.w),
child: ClipRRect( child: ClipRRect(
child: FadeInImage.assetNetwork( child: FadeInImage.assetNetwork(
placeholder: R.ASSETS_IMAGES_LOGO_PNG, placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
image: API.image( image: API.image(
model.imgUrls.isEmpty ? '' : model.imgUrls.first.url))), model.imgUrls.isEmpty ? '' : model.imgUrls.first.url))),
), ),

@ -48,7 +48,7 @@ class ActivityCard extends StatelessWidget {
child: Material( child: Material(
color: Colors.grey, color: Colors.grey,
child: FadeInImage.assetNetwork( child: FadeInImage.assetNetwork(
placeholder: R.ASSETS_IMAGES_LOGO_PNG, placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
image: API.image(firstPath), image: API.image(firstPath),
height: 210.w, height: 210.w,
width: double.infinity, width: double.infinity,

@ -119,7 +119,7 @@ class _ActivityDetailPageState extends State<ActivityDetailPage> {
), ),
clipBehavior: Clip.antiAlias, clipBehavior: Clip.antiAlias,
child: FadeInImage.assetNetwork( child: FadeInImage.assetNetwork(
placeholder: R.ASSETS_IMAGES_LOGO_PNG, placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
image: e.url, image: e.url,
), ),
), ),

@ -50,7 +50,7 @@ class _ActivityPeopleListPageState extends State<ActivityPeopleListPage> {
96.hb, 96.hb,
20.wb, 20.wb,
FadeInImage.assetNetwork( FadeInImage.assetNetwork(
placeholder: R.ASSETS_IMAGES_LOGO_PNG, placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
image: API.image(model.imgUrl.first.url), image: API.image(model.imgUrl.first.url),
height: 60.w, height: 60.w,
width: 60.w, width: 60.w,

@ -21,19 +21,17 @@ class _TopicCommunityViewState extends State<TopicCommunityView>
EasyRefreshController _refreshController = EasyRefreshController(); EasyRefreshController _refreshController = EasyRefreshController();
_buildItem(CommunityTopicModel model) { _buildItem(CommunityTopicModel model) {
var firstImg = '';
if (model?.imgUrls?.isNotEmpty ?? false) {
firstImg = model?.imgUrls?.first?.url ?? '';
}
return MaterialButton( return MaterialButton(
padding: EdgeInsets.symmetric(horizontal: 53.w, vertical: 20.w), padding: EdgeInsets.symmetric(horizontal: 53.w, vertical: 20.w),
onPressed: () { onPressed: () {
Get.to(TopicDetailPage(id: model.id)); Get.to(TopicDetailPage(model: model));
}, },
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Container( Hero(
tag: "${model.firstImg}_${model.id}",
child: Container(
clipBehavior: Clip.antiAlias, clipBehavior: Clip.antiAlias,
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8.w), borderRadius: BorderRadius.circular(8.w),
@ -42,10 +40,11 @@ class _TopicCommunityViewState extends State<TopicCommunityView>
child: Stack( child: Stack(
children: [ children: [
FadeInImage.assetNetwork( FadeInImage.assetNetwork(
placeholder: R.ASSETS_IMAGES_LOGO_PNG, placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
image: API.image(firstImg), image: API.image(model.firstImg),
height: 160.w, height: 160.w,
width: 250.w, width: 250.w,
fit: BoxFit.cover,
), ),
Positioned( Positioned(
bottom: 0, bottom: 0,
@ -72,6 +71,7 @@ class _TopicCommunityViewState extends State<TopicCommunityView>
], ],
), ),
), ),
),
12.wb, 12.wb,
Column( Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,

@ -1,10 +1,12 @@
import 'package:akuCommunity/ui/community/community_views/topic/topic_scrollable_text.dart'; import 'package:akuCommunity/model/community/community_topic_model.dart';
import 'package:akuCommunity/ui/community/community_views/topic/topic_sliver_header.dart';
import 'package:akuCommunity/utils/headers.dart'; import 'package:akuCommunity/utils/headers.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class TopicDetailPage extends StatefulWidget { class TopicDetailPage extends StatefulWidget {
final int id; final CommunityTopicModel model;
TopicDetailPage({Key key, @required this.id}) : super(key: key);
TopicDetailPage({Key key, this.model}) : super(key: key);
@override @override
_TopicDetailPageState createState() => _TopicDetailPageState(); _TopicDetailPageState createState() => _TopicDetailPageState();
@ -16,17 +18,14 @@ class _TopicDetailPageState extends State<TopicDetailPage> {
return Scaffold( return Scaffold(
body: CustomScrollView( body: CustomScrollView(
slivers: [ slivers: [
SliverAppBar( SliverPersistentHeader(
expandedHeight: 500.w, delegate: TopicSliverHeader(
backgroundColor: Colors.transparent, id: widget.model.id,
elevation: 0, title: 'TEST',
pinned: true, imgPath: widget.model.firstImg,
flexibleSpace: FlexibleSpaceBar( subTitle: widget.model.content,
title: TopicScrollableText(title: '#TEST'),
titlePadding: EdgeInsets.zero,
collapseMode: CollapseMode.pin,
background: Container(color: Colors.red),
), ),
pinned: true,
), ),
SliverToBoxAdapter( SliverToBoxAdapter(
child: 40000.hb, child: 40000.hb,

@ -1,47 +0,0 @@
import 'package:akuCommunity/utils/headers.dart';
import 'package:flutter/material.dart';
class TopicScrollableText extends StatefulWidget {
final String title;
TopicScrollableText({Key key, @required this.title}) : super(key: key);
@override
_TopicScrollableTextState createState() => _TopicScrollableTextState();
}
class _TopicScrollableTextState extends State<TopicScrollableText> {
ScrollPosition _scrollPosition;
_positionListener() {
setState(() {});
}
@override
void dispose() {
_scrollPosition?.removeListener(_positionListener);
super.dispose();
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
_scrollPosition = Scrollable.of(context)?.position;
_scrollPosition?.addListener(_positionListener);
}
double get offset {
if (_scrollPosition.pixels >= 500.w) return 1;
if (_scrollPosition.pixels < 500.w && _scrollPosition.pixels >= 0) {
return _scrollPosition.pixels / 500.w;
} else
return 0;
}
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.only(bottom: 202.w - offset * 160.w),
child: Text(widget.title),
);
}
}

@ -0,0 +1,114 @@
import 'package:akuCommunity/constants/api.dart';
import 'package:akuCommunity/utils/headers.dart';
import 'package:akuCommunity/widget/bee_back_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
class TopicSliverHeader extends SliverPersistentHeaderDelegate {
final String imgPath;
final String title;
final String subTitle;
final int id;
TopicSliverHeader({
this.imgPath,
this.title,
this.subTitle,
@required this.id,
});
_buildOverlay(double shrinkOffset) {
return Positioned(
left: 0,
right: 0,
top: 0,
bottom: 0,
child: Material(
color: Colors.white.withOpacity(0 + 0.5 * _offset(shrinkOffset)),
),
);
}
_buildBackButton() {
return Positioned(
left: 0,
top: ScreenUtil().statusBarHeight,
child: BeeBackButton().material(
color: Colors.transparent,
clipBehavior: Clip.antiAlias,
borderRadius: BorderRadius.circular(24),
),
);
}
_buildTitle(double shrinkOffset) {
return Positioned(
bottom: 202.w - 195.w * _filterOffset(shrinkOffset),
left: 32.w + (95.w - 32.w) * _offset(shrinkOffset),
child: '#$title'.text.bold.size(52.sp).make(),
);
}
_buildSubTitle(double shrinkOffset) {
return Positioned(
bottom: 104.w - 104.w * _offset(shrinkOffset) * 2,
left: 32.w,
child: Opacity(
opacity: 1 - _offset(shrinkOffset),
child: subTitle.text.size(24.sp).make(),
),
);
}
@override
Widget build(
BuildContext context, double shrinkOffset, bool overlapsContent) {
return Container(
color: Colors.white,
child: Stack(
fit: StackFit.expand,
children: [
Hero(
tag: "$imgPath\_$id",
child: FadeInImage.assetNetwork(
placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
image: API.image(imgPath),
fit: BoxFit.cover,
),
),
_buildOverlay(shrinkOffset),
_buildBackButton(),
_buildTitle(shrinkOffset),
_buildSubTitle(shrinkOffset),
],
),
);
}
double _offset(double shrinkOffset) {
if (shrinkOffset <= 0)
return 0;
else if (shrinkOffset > 0 && shrinkOffset <= maxExtent)
return shrinkOffset / maxExtent;
else
return 1;
}
double _filterOffset(double shrinkOffset) {
var offset = _offset(shrinkOffset);
if (offset <= 0) return 0;
if (offset < 0.7) return offset / 0.7;
return 1;
}
@override
double get maxExtent => 460.w + ScreenUtil().statusBarHeight;
@override
double get minExtent => 48 + ScreenUtil().statusBarHeight;
@override
bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) {
return true;
}
}

@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
class ChatCard extends StatefulWidget {
final String name;
final String title;
ChatCard({Key key, this.name, this.title}) : super(key: key);
@override
_ChatCardState createState() => _ChatCardState();
}
class _ChatCardState extends State<ChatCard> {
@override
Widget build(BuildContext context) {
return Container();
}
}

@ -96,7 +96,7 @@ class NoticeCard extends StatelessWidget {
borderRadius: BorderRadius.circular(8.w), borderRadius: BorderRadius.circular(8.w),
), ),
child: FadeInImage.assetNetwork( child: FadeInImage.assetNetwork(
placeholder: R.ASSETS_IMAGES_LOGO_PNG, placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
image: API.image(model.imgUrls.first.url), image: API.image(model.imgUrls.first.url),
width: 152.w, width: 152.w,
height: 152.w, height: 152.w,

@ -99,7 +99,7 @@ class _NoticeDetailPageState extends State<NoticeDetailPage> {
color: Colors.black12, color: Colors.black12,
), ),
child: FadeInImage.assetNetwork( child: FadeInImage.assetNetwork(
placeholder: R.ASSETS_IMAGES_LOGO_PNG, placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
image: API.image(e.url), image: API.image(e.url),
fit: BoxFit.cover, fit: BoxFit.cover,
), ),

@ -32,7 +32,7 @@ class StackAvatar extends StatelessWidget {
child: FadeInImage.assetNetwork( child: FadeInImage.assetNetwork(
height: 44.w, height: 44.w,
width: 44.w, width: 44.w,
placeholder: R.ASSETS_IMAGES_LOGO_PNG, placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
image: API.image(avatars[index]), image: API.image(avatars[index]),
), ),
), ),

@ -33,7 +33,7 @@ class _BeeImagePreviewState extends State<BeeImagePreview> {
return Hero( return Hero(
tag: widget.path, tag: widget.path,
child: FadeInImage.assetNetwork( child: FadeInImage.assetNetwork(
placeholder: R.ASSETS_IMAGES_LOGO_PNG, placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
image: API.image(widget.path), image: API.image(widget.path),
), ),
); );

@ -44,7 +44,7 @@ class BeeGridImageView extends StatelessWidget {
child: FadeInImage.assetNetwork( child: FadeInImage.assetNetwork(
height: 184.w, height: 184.w,
width: 184.w, width: 184.w,
placeholder: R.ASSETS_IMAGES_LOGO_PNG, placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
image: API.image(urls[index]), image: API.image(urls[index]),
fit: BoxFit.cover, fit: BoxFit.cover,
), ),

@ -43,7 +43,7 @@ class HorizontalImageView extends StatelessWidget {
child: FadeInImage.assetNetwork( child: FadeInImage.assetNetwork(
height: 184.w, height: 184.w,
width: 184.w, width: 184.w,
placeholder: R.ASSETS_IMAGES_LOGO_PNG, placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
image: API.image(urls[index]), image: API.image(urls[index]),
fit: BoxFit.cover, fit: BoxFit.cover,
), ),

Loading…
Cancel
Save