0

我在将数据发送到第二页时遇到问题,这是我的一段代码

Navigator.push(
  context,MaterialPageRoute(
      builder: (BuildContext context) =>ActivityByDate(
        index: date,
        user: _selectedUser)));

我想将用户发送到第二页(发送到第二页的日期)

    import 'package:flutter_web/material.dart';
import 'package:retgoo_internal/api/user_controller.dart';

class ActivityByDate extends StatefulWidget {
  final DateTime index;
  final user;
  final List list;
  ActivityByDate({this.index, this.user, this.list});
  @override
  _ActivityByDateState createState() => _ActivityByDateState();
}

class _ActivityByDateState extends State<ActivityByDate> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar:
          AppBar(title: Text("Activity berdasarkan tanggal"),
          body: _showActivities(),
    );
  }

  _showActivities() {
    return FutureBuilder(
      future: UserController.getActivityByDate(
          {"date": widget.index.toIso8601String(), "id" : widget.user}),
      builder: (context, snapshot) {
        if (snapshot.hasData) {
          if (snapshot.data != null){
            print(snapshot.data);
          return ListView.builder(
              itemCount: snapshot.data.length,
              itemBuilder: (context, position) {
                var item = snapshot.data.elementAt(position);
                return ListTile(
                  title: Text("${item["activity"]["project"]}"),
                  subtitle: Text(item["created_at"]),
                );
              });
          }

        } 
          return Text("no data displayed");

      },
    );
  }
}

如何将用户发送到第二页,为什么只发送日期

4

2 回答 2

0

在执行以下代码时确保 _selectedUser不为空,或者您可以在此行上调试您的代码

Navigator.push(
  context,MaterialPageRoute(
      builder: (BuildContext context) =>ActivityByDate(
        index: date,
        user: _selectedUser)));
于 2019-07-18T05:37:45.673 回答
0

perhaps _selectedUser Is this a variable or a function?

if it is function

async / await use

于 2019-07-18T04:31:55.437 回答