0

i have a problem with sending data to second page, this is my piece of code

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

I want to send the user to the second page (for the date sent to the second page)

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

      },
    );
  }
}

how to send users to the second page, why only dates are sent

oceany
  • 365
  • 2
  • 5
  • 11

2 Answers2

0

perhaps _selectedUser Is this a variable or a function?

if it is function

async / await use

Junsu Cho
  • 826
  • 7
  • 16
0

while doing execute below code make sure _selectedUser is not null or you can debug your code on this line

Navigator.push(
  context,MaterialPageRoute(
      builder: (BuildContext context) =>ActivityByDate(
        index: date,
        user: _selectedUser)));
Sahil Arora
  • 495
  • 1
  • 3
  • 11