Home flutter 踩坑记
Post
Cancel

flutter 踩坑记

  • 如果需要做 jnifilter ,需要在 as 里设置 –target-platform=android-arm 本质上等同于 –target-platform=android-arm 新版本 flutter run 已移除此参数, 需使用:flutter build apk –target-platform android-arm

今天和同事交流,他说遇到一个问题,键盘的弹出弹回会触发 build 调用。按我理解这个应该是正常的,build 相当于 Android 的 onDraw ,随时都可能被调用。不过他给了 issue 页面我看,发现很多人遇到同样问题,并且在官方项目里 diss 官方开发的回答。不管怎样,还是发现了一个有用的东西:如何避免出现这种问题: https://stackoverflow.com/questions/52249578/how-to-deal-with-unwanted-widget-build


缺失的必要功能!

ListView 无法跳到指定 item (只能跳到指定位移) 2017.Sep!! Provide method and/or config to programmatically scroll to ListView index

TabController 无法动态更改数据, 2018.Aug!! DefaultTabController not working with dynamic data


有临时解决方案的

通过 URL 自外部跳转到 APP Scheme Handler 临时的解决方案:https://pub.dartlang.org/packages/uni_links

ListView 无法获取可视范围的元素 2018.July Returning index of the first visible item in ListView 解决方案:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
class _VideoListState extends State<VideoList> {

  @override
  void initState() {
    super.initState();
  }

  ListView _listView;
  @override
  Widget build(BuildContext context) {
    _listView = ListView.builder(
      itemBuilder: (context,index) {
        var item = widget.list[index];
        return _getChild(item,);
      },
      itemCount: widget.list.length,
    );

    var notificationListener = NotificationListener(
      onNotification: (noti){
        if (noti is ScrollStartNotification) {
          // stop playing
        }else if(noti is ScrollEndNotification){
          // resume playing
          print("end");
          Future.microtask((){
            VideoInfo info = getMeta(0, 10);
            print("scrolling to ${info.title}");
          });
        }
      },
      child: _listView,
    );

    return notificationListener;
  }


  T getMeta<T>(double x,double y){
    var renderBox = context.findRenderObject() as RenderBox;
    var offset = renderBox.localToGlobal(Offset(x,y));

    HitTestResult result = HitTestResult();
    WidgetsBinding.instance.hitTest(result, offset);

    for(var i in result.path){
      if(i.target is RenderMetaData){
        var d = i.target as RenderMetaData;
        if(d.metaData is T) {
          return d.metaData as T;
        }
      }
    }
    return null;
  }


  Widget _getChild(VideoInfo info){
    return MetaData(
      metaData: info,
      child: VideoCard(info:info),
    );
  }
}

class VideoCard extends StatefulWidget{

  final VideoInfo info;

  const VideoCard({Key key, this.info}) : super(key: key);

  @override
  VideoCardState createState() => VideoCardState();
}

class VideoCardState extends State<VideoCard> {
  @override
  Widget build(BuildContext context) {
    return Container(child: Text("hello world ${widget.info.title}"));
  }
}


//-------------data---------------

class VideoInfo {
  final String title;
  VideoInfo(this.title);
}

This post is licensed under CC BY 4.0 by the author.