Multiple widgets used the same GlobalKey

前端 未结 4 1978
清歌不尽
清歌不尽 2020-12-07 01:05

I\'m using Flutter. I have a simple app with 3 tabs. There is a RefreshIndicator in each tab with a ListView. The rows are built in another method. This is the code:

4条回答
  •  余生分开走
    2020-12-07 01:39

    Could you create your keys "by hand" and use static/constant values? e.g. ...

    import 'package:flutter/widgets.dart';
    
    class RIKeys {
      static final riKey1 = const Key('__RIKEY1__');
      static final riKey2 = const Key('__RIKEY2__');
      static final riKey3 = const Key('__RIKEY3__');
    }
    

    then in ...

        body: new TabBarView(
                children: [
                  new RefreshIndicator(new RefreshIndicator(
    // Use the Manual Static Value instead ...
                    key: RIKeys.riKey1,
                    onRefresh: _actualizoData,
                    child: new ListView.builder(
                        padding: new EdgeInsets.only(top: 5.0),
                        itemCount: linea_reservas.length * 2,
                        itemBuilder: (BuildContext context, int position) {
                          if (position.isOdd) return new Divider();
                          final index = position ~/ 2;
                          return _buildRow(index);
                        }),
                  ),
    

    I have done this in a similar situation with some success ... especially with redux or other similar patterns ...

提交回复
热议问题