Skip to content

Commit

Permalink
didUpdateWidget prop
Browse files Browse the repository at this point in the history
  • Loading branch information
Notsfsssf committed Jul 11, 2020
1 parent 898fc28 commit 1c21f6f
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions lib/component/illust_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ class _IllustCardState extends State<IllustCard> {
super.initState();
}

@override
void didUpdateWidget(IllustCard oldWidget) {
illustStore = widget.store;
super.didUpdateWidget(oldWidget);
}

@override
Widget build(BuildContext context) {
return Observer(builder: (_) {
Expand Down Expand Up @@ -123,8 +129,9 @@ class _IllustCardState extends State<IllustCard> {
});
}

String heroString =
DateTime.now().millisecondsSinceEpoch.toString(); //两个作品可能出现在相邻页,用时间保证唯一herotag
String heroString = DateTime.now()
.millisecondsSinceEpoch
.toString(); //两个作品可能出现在相邻页,用时间保证唯一herotag
Widget buildInkWell(BuildContext context) {
return InkWell(
onTap: () => {
Expand Down Expand Up @@ -160,7 +167,7 @@ class _IllustCardState extends State<IllustCard> {
alignment: Alignment.topCenter,
child: (illustStore.illusts.height.toDouble() /
illustStore.illusts.width.toDouble()) >
2
3
? Hero(
tag:
'${illustStore.illusts.imageUrls.medium}${heroString}',
Expand Down
12 changes: 9 additions & 3 deletions lib/lighting/lighting_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,23 +181,29 @@ class _LightingListState extends State<LightingList> {
? StaggeredGridView.countBuilder(
padding: EdgeInsets.all(0.0),
itemBuilder: (context, index) {
final data = _store.iStores[index].illusts;
// final data = _store.iStores[index].illusts;
// if (needToBan(data))
// return Visibility(
// visible: false,
// child: Container(),
// );
return IllustCard(
store: _store.iStores[index],
iStores: _store.iStores,
);
},
staggeredTileBuilder: (int index) {
if (needToBan(_store.iStores[index].illusts))
return StaggeredTile.extent(1, 0.0);
double screanWidth = MediaQuery.of(context).size.width;
double itemWidth = (screanWidth / 2.0) - 32.0;
double radio = _store.iStores[index].illusts.height.toDouble() /
_store.iStores[index].illusts.width.toDouble();
double mainAxisExtent;
if (radio > 2)
if (radio > 3)
mainAxisExtent = itemWidth;
else
mainAxisExtent = itemWidth * radio;

return StaggeredTile.extent(1, mainAxisExtent + 80.0);
},
itemCount: _store.iStores.length,
Expand Down
4 changes: 2 additions & 2 deletions lib/page/history/history_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class HistoryPage extends StatelessWidget {
child: PixivImage(reIllust[index].pictureUrl)));
});
return Center(
child: CircularProgressIndicator(),
child: Container(),
);
});

Expand All @@ -91,7 +91,7 @@ class HistoryPage extends StatelessWidget {
_store.fetch();
return Scaffold(
appBar: AppBar(
title: Text("History"),
title: Text(I18n.of(context).History),
actions: <Widget>[
IconButton(
icon: Icon(Icons.delete),
Expand Down
25 changes: 25 additions & 0 deletions lib/page/picture/illust_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:pixez/component/ban_page.dart';
import 'package:pixez/component/painter_avatar.dart';
import 'package:pixez/component/pixiv_image.dart';
import 'package:pixez/component/star_icon.dart';
Expand Down Expand Up @@ -317,6 +318,30 @@ class _IllustPageState extends State<IllustPage> {
@override
Widget build(BuildContext context) {
return Observer(builder: (_) {
for (var i in muteStore.banillusts) {
if (i.illustId == widget.id.toString()) {
return BanPage(
name: I18n.of(context).Illust,
);
}
}
if (_illustStore.illusts != null) {
for (var j in muteStore.banUserIds) {
if (j.userId == _illustStore.illusts.user.id.toString()) {
return BanPage(
name: I18n.of(context).Painter,
);
}
}
for (var t in muteStore.banTags) {
for (var t1 in _illustStore.illusts.tags) {
if (t.name == t1.name)
return BanPage(
name: I18n.of(context).Tag,
);
}
}
}
if (_illustStore.illusts != null) {
final data = _illustStore.illusts;
return Scaffold(
Expand Down
7 changes: 2 additions & 5 deletions lib/page/search/result_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import 'package:pixez/main.dart';
import 'package:pixez/models/tags.dart';
import 'package:pixez/page/search/result/painter/search_result_painter_page.dart';
import 'package:pixez/page/search/result_illust_list.dart';
import 'package:pixez/page/search/search_page.dart';
import 'package:pixez/page/search/suggest/search_suggestion_page.dart';

class ResultPage extends StatefulWidget {
final String word;
Expand Down Expand Up @@ -50,10 +50,7 @@ class _ResultPageState extends State<ResultPage> {
child: Text(widget.word),
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => Scaffold(
body: SearchPage(
preWord: widget.word,
))));
builder: (context) => SearchSuggestionPage(preword: widget.word,)));
},
),
bottom: TabBar(tabs: [
Expand Down
7 changes: 1 addition & 6 deletions lib/page/search/search_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@ import 'package:pixez/main.dart';
import 'package:pixez/models/trend_tags.dart';
import 'package:pixez/network/api_client.dart';
import 'package:pixez/page/picture/illust_page.dart';
import 'package:pixez/page/picture/picture_page.dart';
import 'package:pixez/page/preview/preview_page.dart';
import 'package:pixez/page/search/bloc/bloc.dart';
import 'package:pixez/page/search/result_page.dart';
import 'package:pixez/page/search/suggest/search_suggestion_page.dart';

class SearchPage extends StatefulWidget {
final String preWord;

const SearchPage({Key key, this.preWord}) : super(key: key);
const SearchPage({Key key}) : super(key: key);

@override
_SearchPageState createState() => _SearchPageState();
Expand All @@ -46,15 +44,13 @@ class _SearchPageState extends State<SearchPage>

@override
void initState() {
_filter = TextEditingController(text: widget.preWord);
_tabController = TabController(length: 3, vsync: this);
super.initState();
tagHistoryStore.fetch();
}

@override
void dispose() {
_filter?.dispose();
_tabController?.dispose();
super.dispose();
}
Expand Down Expand Up @@ -116,7 +112,6 @@ class _SearchPageState extends State<SearchPage>
});
}

TextEditingController _filter;
TabController _tabController;

ListView _buildListView(TrendTagsState state) {
Expand Down
10 changes: 6 additions & 4 deletions lib/page/search/suggest/search_suggestion_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import 'package:pixez/page/search/result_page.dart';
import 'package:pixez/page/user/users_page.dart';

class SearchSuggestionPage extends StatefulWidget {
final String preword;

const SearchSuggestionPage({Key key, this.preword}) : super(key: key);
@override
_SearchSuggestionPageState createState() => _SearchSuggestionPageState();
}
Expand All @@ -38,7 +41,7 @@ class _SearchSuggestionPageState extends State<SearchSuggestionPage>

@override
void initState() {
_filter = TextEditingController();
_filter = TextEditingController(text: widget.preword??'');
_tabController = TabController(length: 3, vsync: this);
super.initState();
}
Expand Down Expand Up @@ -96,7 +99,7 @@ class _SearchSuggestionPageState extends State<SearchSuggestionPage>
Navigator.of(context, rootNavigator: true).push(
MaterialPageRoute(
builder: (BuildContext context) =>
IllustPage(id:int.parse(segment[1]))));
IllustPage(id: int.parse(segment[1]))));
_filter.clear();
}
if (segment[0] == 'users') {
Expand Down Expand Up @@ -134,8 +137,7 @@ class _SearchSuggestionPageState extends State<SearchSuggestionPage>
var id = int.tryParse(word);
if (id != null) {
Navigator.of(context, rootNavigator: true).push(
MaterialPageRoute(
builder: (_) => IllustPage(id:id)));
MaterialPageRoute(builder: (_) => IllustPage(id: id)));
} else {
_filter.clear();
}
Expand Down

0 comments on commit 1c21f6f

Please sign in to comment.