Created
August 9, 2020 17:41
-
-
Save kt-aakash/1615ab4c592b38bd92c09bb720f3c949 to your computer and use it in GitHub Desktop.
Flutter Version : 1.20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(Quizzler()); | |
class Quizzler extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Scaffold( | |
backgroundColor: Colors.grey.shade900, | |
body: SafeArea( | |
child: Padding( | |
padding: EdgeInsets.symmetric(horizontal: 10.0), | |
child: QuizPage(), | |
), | |
), | |
), | |
); | |
} | |
} | |
class QuizPage extends StatefulWidget { | |
@override | |
_QuizPageState createState() => _QuizPageState(); | |
} | |
class _QuizPageState extends State<QuizPage> { | |
List<Icon> scoreKeeper = [ | |
Icon( | |
Icons.check, | |
color: Colors.green, | |
), | |
Icon( | |
Icons.close, | |
color: Colors.red, | |
), | |
]; | |
@override | |
Widget build(BuildContext context) { | |
return Column( | |
mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
crossAxisAlignment: CrossAxisAlignment.stretch, | |
children: <Widget>[ | |
Expanded( | |
flex: 5, | |
child: Padding( | |
padding: EdgeInsets.all(10.0), | |
child: Center( | |
child: Text( | |
'This is where the question text will go.', | |
textAlign: TextAlign.center, | |
style: TextStyle( | |
fontSize: 25.0, | |
color: Colors.white, | |
), | |
), | |
), | |
), | |
), | |
Expanded( | |
child: Padding( | |
padding: EdgeInsets.all(15.0), | |
child: FlatButton( | |
textColor: Colors.white, | |
color: Colors.green, | |
child: Text( | |
'True', | |
style: TextStyle( | |
color: Colors.white, | |
fontSize: 20.0, | |
), | |
), | |
onPressed: () { | |
//The user picked true. | |
}, | |
), | |
), | |
), | |
Expanded( | |
child: Padding( | |
padding: EdgeInsets.all(15.0), | |
child: FlatButton( | |
color: Colors.red, | |
child: Text( | |
'False', | |
style: TextStyle( | |
fontSize: 20.0, | |
color: Colors.white, | |
), | |
), | |
onPressed: () { | |
//The user picked false. | |
}, | |
), | |
), | |
), | |
Row( | |
children: scoreKeeper, | |
), | |
], | |
); | |
} | |
} |
Update:
The solution was :
Either:
Restart Android Studio and run it again
Else:
Adding final keyword to the list i.e :
Replace line no: 29 with:
final List scoreKeeper = [
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Error message:
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following _TypeError was thrown building QuizPage(dirty, state: _QuizPageState#d4471):
type 'List' is not a subtype of type 'List' of 'function result'
The relevant error-causing widget was:
QuizPage file:///home/admantum/AndroidStudioProjects/quizzler-flutter/lib/main.dart:14:20
When the exception was thrown, this was the stack:
#0 _QuizPageState.scoreKeeper (package:quizzler/main.dart)
#1 _QuizPageState.build (package:quizzler/main.dart:102:21)
#2 StatefulElement.build (package:flutter/src/widgets/framework.dart:4663:28)
#3 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4546:15)
#4 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4719:11)