Home > Blockchain >  pass snapshot to another page in flutter
pass snapshot to another page in flutter

Time:09-04

I want to pass snapshot data to another page but IDE give an error.

The code is:

TextButton(onPressed: (){
                      Navigator.push(context,MaterialPageRoute(builder: (context)=>reactor(snapshot:snapshot.data![i])));
                    }, child: Text("view likes"))

reactor.dart

class reactor extends StatefulWidget {
  const reactor({Key? key,required this.snapshot}) : super(key: key);
  final snapshot;
  @override
  State<reactor> createState() => _reactorState();
}
class _reactorState extends State<reactor> {
@override
  Widget build(BuildContext context) {
    return Scaffold(
body: Center(
     child: Text(snapshot!.likes.length.toString(),)    
    );

  }
}

I have used Posts model class. How to pass it and thanks in advance.

CodePudding user response:

fix it like this:

Text(widget.snapshot.likes.length.toString(),)
  • Related