【问题标题】:Synchronization of list view and detail view列表视图和详细视图的同步
【发布时间】:2019-08-14 06:57:51
【问题描述】:

我有一个功能简单的应用程序。身份验证后,用户会看到带有 ListView 小部件的 页面,该小部件在 StreamBuilder 小部件和 BLoC 的帮助下填充。单击 ListView 行打开带有一组详细信息小部件(TextField)的 详细信息页面。现在我需要更改表格的 GUI 设计。由于我们有更多空间,我决定在列表视图附近显示详细信息,即当用户单击 ListView 项目没有打开新页面,但详细信息显示在 ListView 的右侧。我需要知道如何将详细视图小部件与列表视图小部件中的选定项目同步。我发现我可以以某种方式使用 ValueNotifier/ValueListenableBuilder但我无法将我的想法集中在一起。我需要一些想法,请。

【问题讨论】:

    标签: list flutter dart


    【解决方案1】:

    请使用这个包 responsive_scaffold https://pub.dev/packages/responsive_scaffold
    在移动设备上它显示一个列表并推送到详细信息,在平板电脑上它显示列表和所选项目。

    示例代码

    import 'package:flutter/material.dart';
    
    import 'package:responsive_scaffold/responsive_scaffold.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatefulWidget {
      @override
      _MyAppState createState() => _MyAppState();
    }
    
    class _MyAppState extends State<MyApp> {
      var _scaffoldKey = new GlobalKey<ScaffoldState>();
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: ResponsiveListScaffold.builder(
            scaffoldKey: _scaffoldKey,
            detailBuilder: (BuildContext context, int index, bool tablet) {
              return DetailsScreen(
                // appBar: AppBar(
                //   elevation: 0.0,
                //   title: Text("Details"),
                //   actions: [
                //     IconButton(
                //       icon: Icon(Icons.share),
                //       onPressed: () {},
                //     ),
                //     IconButton(
                //       icon: Icon(Icons.delete),
                //       onPressed: () {
                //         if (!tablet) Navigator.of(context).pop();
                //       },
                //     ),
                //   ],
                // ),
                body: Scaffold(
                  appBar: AppBar(
                    elevation: 0.0,
                    title: Text("Details"),
                    automaticallyImplyLeading: !tablet,
                    actions: [
                      IconButton(
                        icon: Icon(Icons.share),
                        onPressed: () {},
                      ),
                      IconButton(
                        icon: Icon(Icons.delete),
                        onPressed: () {
                          if (!tablet) Navigator.of(context).pop();
                        },
                      ),
                    ],
                  ),
                  bottomNavigationBar: BottomAppBar(
                    elevation: 0.0,
                    child: Container(
                      child: IconButton(
                        icon: Icon(Icons.share),
                        onPressed: () {},
                      ),
                    ),
                  ),
                  body: Container(
                    child: Center(
                      child: Text("Item: $index"),
                    ),
                  ),
                ),
              );
            },
            nullItems: Center(child: CircularProgressIndicator()),
            emptyItems: Center(child: Text("No Items Found")),
            slivers: <Widget>[
              SliverAppBar(
                title: Text("App Bar"),
              ),
            ],
            itemCount: 100,
            itemBuilder: (BuildContext context, int index) {
              return ListTile(
                leading: Text(index.toString()),
              );
            },
            bottomNavigationBar: BottomAppBar(
              elevation: 0.0,
              child: Container(
                child: IconButton(
                  icon: Icon(Icons.share),
                  onPressed: () {},
                ),
              ),
            ),
            floatingActionButton: FloatingActionButton(
              child: Icon(Icons.add),
              onPressed: () {
                _scaffoldKey.currentState.showSnackBar(SnackBar(
                  content: Text("Snackbar!"),
                ));
              },
            ),
          ),
        );
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-18
      • 2016-04-14
      • 1970-01-01
      • 1970-01-01
      • 2020-11-20
      • 2012-08-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多