forked from lxm_flutter/FlutterUnit
进入收藏页,再回到首页,顶部显示不同步的问题。fix--主页item双击黑屏问题.支持详情页【相关链接的栈管理】,
This commit is contained in:
Binary file not shown.
@@ -43,7 +43,7 @@ class Router {
|
||||
switch (settings.name) {
|
||||
//根据名称跳转相应页面
|
||||
case widget_detail:
|
||||
return Right2LeftRouter(child: WidgetDetailPage());
|
||||
return Right2LeftRouter(child: WidgetDetailPage(model: settings.arguments,));
|
||||
case search:
|
||||
return Right2LeftRouter(child: SearchPage());
|
||||
case collect:
|
||||
|
||||
@@ -56,6 +56,6 @@ class CollectPage extends StatelessWidget {
|
||||
|
||||
_toDetailPage(BuildContext context, WidgetModel model) {
|
||||
BlocProvider.of<DetailBloc>(context).add(FetchWidgetDetail(model));
|
||||
Navigator.pushNamed(context, Router.widget_detail);
|
||||
Navigator.pushNamed(context, Router.widget_detail,arguments: model);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_star/flutter_star.dart';
|
||||
import 'package:flutter_unit/app/res/cons.dart';
|
||||
import 'package:flutter_unit/app/router.dart';
|
||||
import 'package:flutter_unit/app/style/TolyIcon.dart';
|
||||
import 'package:flutter_unit/app/utils/Toast.dart';
|
||||
import 'package:flutter_unit/blocs/collect/collect_bloc.dart';
|
||||
@@ -19,77 +20,206 @@ import 'package:flutter_unit/model/widget_model.dart';
|
||||
import 'package:flutter_unit/views/widgets/widgets_map.dart';
|
||||
|
||||
class WidgetDetailPage extends StatefulWidget {
|
||||
final WidgetModel model;
|
||||
|
||||
WidgetDetailPage({this.model});
|
||||
|
||||
@override
|
||||
_WidgetDetailPageState createState() => _WidgetDetailPageState();
|
||||
}
|
||||
|
||||
class _WidgetDetailPageState extends State<WidgetDetailPage> {
|
||||
WidgetModel _model;
|
||||
|
||||
List<WidgetModel> _models=[];
|
||||
|
||||
@override
|
||||
void deactivate() {
|
||||
BlocProvider.of<DetailBloc>(context).add(ResetDetailState());
|
||||
super.deactivate();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_models.add(widget.model);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<DetailBloc, DetailState>(builder: (_, state) {
|
||||
if (state is DetailWithData) {
|
||||
return WillPopScope(
|
||||
onWillPop: () async {
|
||||
// Future.delayed(Duration(milliseconds: 500)).then((v){
|
||||
// BlocProvider.of<DetailBloc>(context).add(ResetDetailState());
|
||||
// });
|
||||
return true;
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(state.widgetModel.name),
|
||||
actions: <Widget>[
|
||||
buildCollectButton(state.widgetModel, context),
|
||||
],
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
child: Container(
|
||||
return WillPopScope(
|
||||
onWillPop: () async{
|
||||
_models.removeLast();
|
||||
if(_models.length>0){
|
||||
setState(() {
|
||||
|
||||
});
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(_models.last.name),
|
||||
actions: <Widget>[
|
||||
IconButton(icon:Icon( Icons.home), onPressed: (){
|
||||
Navigator.of(context).pop();
|
||||
}),
|
||||
buildCollectButton(_models.last, context),
|
||||
|
||||
],
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
child: Container(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Row(
|
||||
children: <Widget>[
|
||||
_buildLeft(state.widgetModel),
|
||||
_buildRight(state.widgetModel),
|
||||
],
|
||||
WidgetDetailTitle(
|
||||
model: _models.last,
|
||||
),
|
||||
Divider(),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 15, right: 5),
|
||||
child: Icon(
|
||||
Icons.link,
|
||||
color: Colors.blue,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'相关组件',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold, fontSize: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
_buildLinkTo(
|
||||
context,
|
||||
state.links,
|
||||
),
|
||||
Divider(),
|
||||
_buildNodes(state.nodes, state.widgetModel.name)
|
||||
BlocBuilder<DetailBloc, DetailState>(builder: (_, state) {
|
||||
if (state is DetailWithData) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.only(left: 15, right: 5),
|
||||
child: Icon(
|
||||
Icons.link,
|
||||
color: Colors.blue,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'相关组件',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold, fontSize: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
_buildLinkTo(
|
||||
context,
|
||||
state.links,
|
||||
),
|
||||
Divider(),
|
||||
_buildNodes(state.nodes, state.widgetModel.name)
|
||||
],
|
||||
);
|
||||
}
|
||||
return Container();
|
||||
})
|
||||
],
|
||||
),
|
||||
)),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Container();
|
||||
});
|
||||
),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildCollectButton(WidgetModel model, BuildContext context) {
|
||||
//监听 CollectBloc 伺机弹出toast
|
||||
return BlocListener<CollectBloc, CollectState>(
|
||||
listener: (ctx, st) {
|
||||
bool collected = st.widgets.contains(model);
|
||||
Toast.toast(ctx,
|
||||
collected ? "收藏【${model.name}】组件成功!" : "已取消【${model.name}】组件收藏!");
|
||||
},
|
||||
child: FeedbackWidget(
|
||||
onPressed: () => BlocProvider.of<CollectBloc>(context)
|
||||
.add(ToggleCollectEvent(id: model.id)),
|
||||
child: BlocBuilder<CollectBloc, CollectState>(builder: (_, s) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 20.0),
|
||||
child: Icon(
|
||||
s.widgets.contains(model)
|
||||
? TolyIcon.icon_star_ok
|
||||
: TolyIcon.icon_star_add,
|
||||
size: 25,
|
||||
),
|
||||
);
|
||||
}),
|
||||
));
|
||||
}
|
||||
|
||||
final List<int> colors = Cons.tabColors;
|
||||
|
||||
Widget _buildNodes(List<NodeModel> nodes, String name) {
|
||||
var globalState = BlocProvider.of<GlobalBloc>(context).state;
|
||||
|
||||
return Column(
|
||||
children: nodes
|
||||
.asMap()
|
||||
.keys
|
||||
.map((i) => WidgetNodePanel(
|
||||
codeStyle: Cons.codeThemeSupport.keys
|
||||
.toList()[globalState.codeStyleIndex],
|
||||
codeFamily: 'Inconsolata',
|
||||
text: nodes[i].name,
|
||||
subText: nodes[i].subtitle,
|
||||
code: nodes[i].code,
|
||||
show: WidgetsMap.map(name)[i],
|
||||
))
|
||||
.toList());
|
||||
}
|
||||
|
||||
_buildLinkTo(BuildContext context, List<WidgetModel> links) {
|
||||
if (links == null || links.isEmpty) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Chip(
|
||||
backgroundColor: Colors.grey.withAlpha(120),
|
||||
labelStyle: TextStyle(fontSize: 12, color: Colors.white),
|
||||
label: Text('暂无链接组件'),
|
||||
));
|
||||
} else {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 10.0, top: 10),
|
||||
child: Wrap(
|
||||
spacing: 5,
|
||||
children: links
|
||||
.map((e) => ActionChip(
|
||||
onPressed: () {
|
||||
BlocProvider.of<DetailBloc>(context)
|
||||
.add(FetchWidgetDetail(e));
|
||||
setState(() {
|
||||
_models.add(e);
|
||||
});
|
||||
},
|
||||
elevation: 2,
|
||||
shadowColor: Colors.orange,
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
labelStyle: TextStyle(fontSize: 12, color: Colors.white),
|
||||
label: Text('${e.name}'),
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class WidgetDetailTitle extends StatelessWidget {
|
||||
final WidgetModel model;
|
||||
|
||||
WidgetDetailTitle({this.model});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Row(
|
||||
children: <Widget>[
|
||||
_buildLeft(model),
|
||||
_buildRight(model),
|
||||
],
|
||||
),
|
||||
Divider(),
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
Widget buildCollectButton(WidgetModel model, BuildContext context) {
|
||||
@@ -163,55 +293,4 @@ class _WidgetDetailPageState extends State<WidgetDetailPage> {
|
||||
)
|
||||
],
|
||||
);
|
||||
|
||||
Widget _buildNodes(List<NodeModel> nodes, String name) {
|
||||
var globalState = BlocProvider.of<GlobalBloc>(context).state;
|
||||
|
||||
return Column(
|
||||
children: nodes
|
||||
.asMap()
|
||||
.keys
|
||||
.map((i) => WidgetNodePanel(
|
||||
codeStyle: Cons.codeThemeSupport.keys
|
||||
.toList()[globalState.codeStyleIndex],
|
||||
codeFamily: 'Inconsolata',
|
||||
text: nodes[i].name,
|
||||
subText: nodes[i].subtitle,
|
||||
code: nodes[i].code,
|
||||
show: WidgetsMap.map(name)[i],
|
||||
))
|
||||
.toList());
|
||||
}
|
||||
|
||||
_buildLinkTo(BuildContext context, List<WidgetModel> links) {
|
||||
if (links == null || links.isEmpty) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Chip(
|
||||
backgroundColor: Colors.grey.withAlpha(120),
|
||||
labelStyle: TextStyle(fontSize: 12, color: Colors.white),
|
||||
label: Text('暂无链接组件'),
|
||||
));
|
||||
} else {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 10.0, top: 10),
|
||||
child: Wrap(
|
||||
spacing: 5,
|
||||
children: links
|
||||
.map((e) => ActionChip(
|
||||
onPressed: () {
|
||||
BlocProvider.of<DetailBloc>(context)
|
||||
.add(FetchWidgetDetail(e));
|
||||
},
|
||||
elevation: 2,
|
||||
shadowColor: Colors.orange,
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
labelStyle: TextStyle(fontSize: 12, color: Colors.white),
|
||||
label: Text('${e.name}'),
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_unit/app/convert.dart';
|
||||
import 'package:flutter_unit/app/res/cons.dart';
|
||||
import 'package:flutter_unit/app/router.dart';
|
||||
import 'package:flutter_unit/blocs/detail/detail_bloc.dart';
|
||||
import 'package:flutter_unit/blocs/detail/detail_event.dart';
|
||||
@@ -36,8 +37,11 @@ class _HomePageState extends State<HomePage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var color = BlocProvider.of<HomeBloc>(context).state.homeColor;
|
||||
|
||||
return Scaffold(
|
||||
appBar: TolyAppBar(
|
||||
selectIndex: Cons.tabColors.indexOf(color.value),
|
||||
preferredSize: Size.fromHeight(_height),
|
||||
onItemClick: _switchTab,
|
||||
),
|
||||
@@ -119,7 +123,6 @@ class _HomePageState extends State<HomePage> {
|
||||
|
||||
_toDetailPage(WidgetModel model) async{
|
||||
BlocProvider.of<DetailBloc>(context).add(FetchWidgetDetail(model));
|
||||
await Future.delayed(Duration(milliseconds: 200));
|
||||
Navigator.pushNamed(context, Router.widget_detail);
|
||||
Navigator.pushNamed(context, Router.widget_detail,arguments: model);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ class TolyAppBar extends StatefulWidget implements PreferredSizeWidget {
|
||||
|
||||
final Size preferredSize;
|
||||
|
||||
TolyAppBar({this.onItemClick, this.preferredSize,});
|
||||
final int selectIndex;
|
||||
TolyAppBar({this.onItemClick, this.preferredSize,this.selectIndex=0});
|
||||
}
|
||||
|
||||
class _TolyAppBarState extends State<TolyAppBar>
|
||||
@@ -24,6 +25,8 @@ class _TolyAppBarState extends State<TolyAppBar>
|
||||
|
||||
AnimationController _controller;
|
||||
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_controller =
|
||||
@@ -34,7 +37,7 @@ class _TolyAppBarState extends State<TolyAppBar>
|
||||
setState(() {});
|
||||
}
|
||||
});
|
||||
|
||||
_selectIndex=widget.selectIndex;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
|
||||
@@ -130,7 +130,6 @@ class _SearchPageState extends State<SearchPage> {
|
||||
|
||||
_toDetailPage(WidgetModel model) {
|
||||
BlocProvider.of<DetailBloc>(context).add(FetchWidgetDetail(model));
|
||||
// BlocProvider.of<CollectBloc>(context).add(EventSetCollect(collect:model.collected));
|
||||
Navigator.pushNamed(context, Router.widget_detail);
|
||||
Navigator.pushNamed(context, Router.widget_detail,arguments: model);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user