如何将id_user发送到第二页

时间:2019-07-18 03:43:56

标签: flutter flutter-web

我无法将数据发送到第二页,这是我的代码

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");

      },
    );
  }
}

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

2 个答案:

答案 0 :(得分:0)

也许_selectedUser这是变量还是函数?

如果是函数

异步/等待使用

答案 1 :(得分:0)

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

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