From d2af136aeeefcbc392d161e1a5fb01ec3f6f2b7e Mon Sep 17 00:00:00 2001 From: wangjianxiandev Date: Wed, 8 Apr 2020 10:36:06 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E7=94=A8article=5Fitem=E7=BB=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 6 + lib/page/project/project_list_fragment.dart | 4 +- lib/widget/article_item.dart | 76 ++++++- lib/widget/project_item.dart | 236 -------------------- 4 files changed, 73 insertions(+), 249 deletions(-) delete mode 100644 lib/widget/project_item.dart diff --git a/.gitignore b/.gitignore index cdecf14..14fd4c2 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,9 @@ build/ .android/ .ios/ .flutter-plugins +.flutter-plugins-dependencies +.gitattributes +.metadata +LICENSE +captures/ + diff --git a/lib/page/project/project_list_fragment.dart b/lib/page/project/project_list_fragment.dart index f0f9684..26bb3f8 100644 --- a/lib/page/project/project_list_fragment.dart +++ b/lib/page/project/project_list_fragment.dart @@ -11,9 +11,9 @@ import 'package:wanandroidflutter/theme/app_theme.dart'; import 'package:wanandroidflutter/utils/collect_event.dart'; import 'package:wanandroidflutter/utils/login_event.dart'; import 'package:wanandroidflutter/utils/loginout_event.dart'; +import 'package:wanandroidflutter/widget/article_item.dart'; import 'package:wanandroidflutter/widget/custom_refresh.dart'; import 'package:wanandroidflutter/widget/page_widget.dart'; -import 'package:wanandroidflutter/widget/project_item.dart'; class ProjectListFragment extends StatefulWidget { int _Id; @@ -128,7 +128,7 @@ class ProjectListFragmentState extends State controller: _scrollController, itemCount: projectArticleList.length, itemBuilder: (context, index) { - return ProjectArticleWidget(projectArticleList[index]); + return ArticleWidget(projectArticleList[index]); })), ), floatingActionButton: isShowFab ? FloatingActionButton( diff --git a/lib/widget/article_item.dart b/lib/widget/article_item.dart index 226f7ca..9677fde 100644 --- a/lib/widget/article_item.dart +++ b/lib/widget/article_item.dart @@ -124,18 +124,57 @@ class _ArticleWidgetState extends State { )), ], ), - Align( - alignment: Alignment.centerLeft, - child: Padding( - padding: EdgeInsets.fromLTRB(0, 10, 0, 0), - child: !isHighLight(article.title) - ? Text("${article.title}", - style: Theme.of(context).textTheme.subtitle) - : Html( - data: article.title, - ), + if (article.envelopePic.isEmpty) + Align( + alignment: Alignment.centerLeft, + child: Padding( + padding: EdgeInsets.fromLTRB(0, 15, 0, 0), + child: !isHighLight(article.title) + ? Text("${article.title}", + style: Theme.of(context).textTheme.subtitle) + : Html( + data: article.title, + ), + ), + ) + else + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + height: 5, + ), + ArticleTitleWidget(article.title), + SizedBox( + height: 2, + ), + Text( + article.desc, + style: Theme.of(context).textTheme.caption, + overflow: TextOverflow.ellipsis, + maxLines: 2, + ) + ], + ), + ), + SizedBox( + width: 5, + ), + Padding( + padding: EdgeInsets.fromLTRB(0, 10, 0, 0), + child: Image.network( + article.envelopePic, + height: 60, + width: 60, + fit: BoxFit.cover, + ), + ) + ], ), - ), Row( children: [ Expanded( @@ -211,3 +250,18 @@ class _ArticleWidgetState extends State { }, errorCallBack: (code, msg) {}, context: context); } } + +class ArticleTitleWidget extends StatelessWidget { + final String title; + + ArticleTitleWidget(this.title); + + @override + Widget build(BuildContext context) { + return Html( + padding: EdgeInsets.symmetric(vertical: 5), + data: title, + defaultTextStyle: Theme.of(context).textTheme.subtitle, + ); + } +} diff --git a/lib/widget/project_item.dart b/lib/widget/project_item.dart deleted file mode 100644 index d43fa3c..0000000 --- a/lib/widget/project_item.dart +++ /dev/null @@ -1,236 +0,0 @@ -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; - -import 'package:flutter_html/flutter_html.dart'; -import 'package:provider/provider.dart'; -import 'package:wanandroidflutter/data/article.dart'; -import 'package:wanandroidflutter/http/api.dart'; -import 'package:wanandroidflutter/http/http_request.dart'; -import 'package:wanandroidflutter/page/webview_page.dart'; -import 'package:wanandroidflutter/theme/app_theme.dart'; -import 'package:wanandroidflutter/utils/widget_utils.dart'; - -import 'favourite_animation.dart'; - -//项目item -class ProjectArticleWidget extends StatefulWidget { - Article article; - - ProjectArticleWidget(this.article); - - @override - State createState() { - return _ProjectArticleWidgetState(); - } -} - -class _ProjectArticleWidgetState extends State { - Article article; - - @override - Widget build(BuildContext context) { - article = widget.article; - UniqueKey uniqueKey = UniqueKey(); - var appTheme = Provider.of(context); - return GestureDetector( - onTap: () { - String title = ""; - if (!isHighLight(article.title)) { - title = article.title; - } else { - title = article.title - .replaceAll("", "") - .replaceAll("", ""); - } - Navigator.of(context).push(new MaterialPageRoute(builder: (_) { - return new WebViewPage( - url: article.link, - title: article.title, - id: article.id, - isCollect: article.collect, - ); - })); - }, - child: Card( - elevation: 15.0, - shape: const RoundedRectangleBorder( - borderRadius: BorderRadius.all(Radius.circular(14.0))), - margin: EdgeInsets.all(5), - child: Container( - padding: EdgeInsets.fromLTRB(10, 10, 10, 5), - child: Column( - children: [ - Row( - children: [ - Expanded( - flex: 1, - child: Row( - children: [ - Icon( - article.author == "" - ? Icons.folder_shared - : Icons.person, - size: 20.0, - color: appTheme.themeColor, - ), - Container( - padding: EdgeInsets.only(left: 5), - child: Text( - "${article.author.isNotEmpty ? article.author : article.shareUser}", - overflow: TextOverflow.ellipsis, - maxLines: 1, - style: Theme.of(context).textTheme.caption), - ), - Container( - margin: EdgeInsets.only(left: 5), - child: Offstage( - offstage: !article.fresh ?? true, - child: WidgetUtils.buildStrokeWidget( - "新", - appTheme.themeColor, - FontWeight.w400, - 11.0)), - ), - ], - )), - Align( - alignment: Alignment.centerRight, - child: Row( - children: [ - Container( - child: Icon( - Icons.access_time, - color: Colors.grey, - size: 20, - ), - ), - Container( - padding: EdgeInsets.fromLTRB(5, 0, 5, 0), - child: Text("${article.niceDate}", - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.caption), - ) - ], - )), - ], - ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ArticleTitleWidget(article.title), - SizedBox( - height: 2, - ), - Text( - article.desc, - style: Theme.of(context).textTheme.caption, - overflow: TextOverflow.ellipsis, - maxLines: 1, - ) - ], - ), - ), - SizedBox( - width: 5, - ), - Image.network( - article.envelopePic, - height: 60, - width: 60, - fit: BoxFit.cover, - ), - ], - ), - Row( - children: [ - Expanded( - flex: 1, - child: Container( - alignment: Alignment.centerLeft, - child: Text( - "${article.chapterName}/${article.superChapterName}", - style: TextStyle( - color: appTheme.themeColor, fontSize: 11.0), - ))), - Align( - alignment: Alignment.centerRight, - child: !article.collect - ? IconButton( - alignment: Alignment.centerRight, - padding: EdgeInsets.only(right: 5), - icon: Icon( - Icons.favorite_border, - color: Colors.black45, - ), - onPressed: () => _collect(uniqueKey), - ) - : IconButton( - alignment: Alignment.centerRight, - padding: EdgeInsets.only(right: 5), - icon: Icon( - Icons.favorite, - color: Colors.red, - ), - onPressed: () => _collect(uniqueKey), - ), - ), - ], - ), - ], - ), - ), - ), - ); - } - - //判断title是否有文字需要加斜体 - bool isHighLight(String title) { - RegExp exp = new RegExp(r"([\s\S]*?)"); - return exp.hasMatch(title); - } - - //收藏/取消收藏 - _collect(UniqueKey uniqueKey) { - Navigator.push( - context, - HeroDialogRoute( - builder: (_) => FavouriteAnimation( - tag: uniqueKey, - isAdded: !article.collect, - ))); - String url = ""; - if (!article.collect) { - url = "lg/collect/${article.id}/json"; - } else { - url = "lg/uncollect_originId/${article.id}/json"; - } - HttpRequest.getInstance().post( - article.collect == false - ? "${Api.COLLECT}${article.id}/json" - : "${Api.UN_COLLECT_ORIGIN_ID}${article.id}/json", - successCallBack: (data) { - setState(() { - article.collect = !article.collect; - }); - }, errorCallBack: (code, msg) {}, context: context); - } -} - -class ArticleTitleWidget extends StatelessWidget { - final String title; - - ArticleTitleWidget(this.title); - - @override - Widget build(BuildContext context) { - return Html( - padding: EdgeInsets.symmetric(vertical: 5), - data: title, - defaultTextStyle: Theme.of(context).textTheme.subtitle, - ); - } -}