|
1 | 1 | import 'package:flutter/material.dart'; |
| 2 | +import 'package:gsy_github_app_flutter/common/config/config.dart'; |
2 | 3 | import 'package:gsy_github_app_flutter/common/model/Repository.dart'; |
3 | 4 | import 'package:gsy_github_app_flutter/common/style/gsy_style.dart'; |
4 | 5 | import 'package:gsy_github_app_flutter/common/utils/common_utils.dart'; |
@@ -26,8 +27,8 @@ class ReposHeaderItem extends StatefulWidget { |
26 | 27 |
|
27 | 28 | class _ReposHeaderItemState extends State<ReposHeaderItem> { |
28 | 29 | final GlobalKey layoutKey = new GlobalKey(); |
29 | | - final GlobalKey layoutKey2 = new GlobalKey(); |
30 | | - final GlobalKey layoutKey3 = new GlobalKey(); |
| 30 | + final GlobalKey layoutTopicContainerKey = new GlobalKey(); |
| 31 | + final GlobalKey layoutLastTopicKey = new GlobalKey(); |
31 | 32 |
|
32 | 33 | double widgetHeight = 0; |
33 | 34 |
|
@@ -55,7 +56,7 @@ class _ReposHeaderItemState extends State<ReposHeaderItem> { |
55 | 56 | _renderTopicItem(BuildContext context, String item, index) { |
56 | 57 | return new RawMaterialButton( |
57 | 58 | key: index == widget.reposHeaderViewModel.topics.length - 1 |
58 | | - ? layoutKey3 |
| 59 | + ? layoutLastTopicKey |
59 | 60 | : null, |
60 | 61 | onPressed: () { |
61 | 62 | NavigatorUtils.gotoCommonList(context, item, "repository", "topics", |
@@ -91,7 +92,7 @@ class _ReposHeaderItemState extends State<ReposHeaderItem> { |
91 | 92 | list.add(_renderTopicItem(context, item, i)); |
92 | 93 | } |
93 | 94 | return new Container( |
94 | | - key: layoutKey2, |
| 95 | + key: layoutTopicContainerKey, |
95 | 96 | alignment: Alignment.topLeft, |
96 | 97 | margin: EdgeInsets.only(top: 5.0), |
97 | 98 | child: Wrap( |
@@ -123,20 +124,29 @@ class _ReposHeaderItemState extends State<ReposHeaderItem> { |
123 | 124 | void didUpdateWidget(ReposHeaderItem oldWidget) { |
124 | 125 | super.didUpdateWidget(oldWidget); |
125 | 126 | ///如果没有tag列表,不需要处理 |
126 | | - if(layoutKey2.currentContext == null || layoutKey3.currentContext == null) { |
| 127 | + /*if(layoutTopicContainerKey.currentContext == null || layoutLastTopicKey.currentContext == null) { |
127 | 128 | return; |
128 | | - } |
| 129 | + }*/ |
129 | 130 | ///如果存在tag,根据tag去判断,修复溢出 |
130 | 131 | new Future.delayed(Duration(seconds: 0), (){ |
131 | 132 | /// tag 所在 container |
132 | | - RenderBox renderBox2 = layoutKey2.currentContext.findRenderObject(); |
| 133 | + RenderBox renderBox2 = layoutTopicContainerKey.currentContext?.findRenderObject(); |
133 | 134 | /// 最后面的一个tag |
134 | | - RenderBox renderBox3 = layoutKey3.currentContext.findRenderObject(); |
135 | | - double overflow = (renderBox3.localToGlobal(Offset.zero).dy - |
136 | | - renderBox2.localToGlobal(Offset.zero).dy) - |
137 | | - layoutKey3.currentContext.size.height; |
138 | | - var newSize = layoutKey.currentContext.size.height + overflow; |
139 | | - if (widgetHeight != newSize) { |
| 135 | + RenderBox renderBox3 = layoutLastTopicKey.currentContext?.findRenderObject(); |
| 136 | + double overflow = ((renderBox3?.localToGlobal(Offset.zero)?.dy ?? 0) - |
| 137 | + (renderBox2?.localToGlobal(Offset.zero)?.dy ?? 0)) - |
| 138 | + (layoutLastTopicKey.currentContext?.size?.height ?? 0); |
| 139 | + var newSize; |
| 140 | + if(overflow > 0) { |
| 141 | + newSize = layoutKey.currentContext.size.height + overflow; |
| 142 | + } else { |
| 143 | + newSize = layoutKey.currentContext.size.height + 10.0; |
| 144 | + } |
| 145 | + if(Config.DEBUG) { |
| 146 | + print("newSize $newSize overflow $overflow"); |
| 147 | + } |
| 148 | + if (widgetHeight != newSize && newSize > 0) { |
| 149 | + print("widget?.layoutListener?.call"); |
140 | 150 | widgetHeight = newSize; |
141 | 151 | widget?.layoutListener |
142 | 152 | ?.call(Size(layoutKey.currentContext.size.width, widgetHeight)); |
|
0 commit comments