Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The method 'map' was called on null. Receiver: null Tried calling: map<Answer>(Closure: (String) => Answer) #218

Open
aymanjr opened this issue Nov 1, 2020 · 0 comments

Comments

@aymanjr
Copy link

aymanjr commented Nov 1, 2020

i'm new the flutter environment
i was watching a course
and this works for the guy and not for me
the code :

import 'package:flutter/material.dart';
import './question.dart';
import './Answer.dart';

void main() {
runApp(Myapp());
}

class Myapp extends StatefulWidget {
@OverRide
State createState() {
return _MyappState();
}
}

class _MyappState extends State {
var questionindex = 0;

void answerTheq() {
setState(() {
if (questionindex >= 2) {
questionindex = 0;
} else {
questionindex += 1;
print('hi answer ');
}
});
}

@OverRide
Widget build(BuildContext context) {
var questions = [
{
'question text': 'what's your fav color : ',
'answers': ['blue', 'green', 'red', 'yellow']
},
{
'question text': 'what's your fav animal : ',
'answers': ['cat', 'dog', 'lion', 'zebra']
},
{
'question text ': 'what's your fav team : ',
'answers': ['rca', 'wac', 'far', 'mat']
},
];

return MaterialApp(
  home: Scaffold(
      appBar: AppBar(
        title: Text('My app'),
        backgroundColor: Colors.blue,
      ),
      body: Column(
        children: [
          Question(questions[questionindex]['question text ']),
          ...(questions[questionindex]['answer'] as List<String>)
                  .map((answer) {
                return Answer(answerTheq, answer);
              })?.toList() ??
              []
        ],
      )),
);

}
}

import 'package:flutter/material.dart';

class Answer extends StatelessWidget {
final Function getthefucntiondata;
final String answertext;

Answer(this.getthefucntiondata, this.answertext);

@OverRide
Widget build(BuildContext context) {
return Container(
width: double.infinity,
child: RaisedButton(
color: Colors.blue,
child: Text(answertext),
onPressed: getthefucntiondata,
));
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant