Created with <3 with dartpad.dev.
Last active
December 28, 2023 02:54
-
-
Save RayyanNafees/5b21aa9dedef85a0e5bbf340e1e34a76 to your computer and use it in GitHub Desktop.
coder-flutter
This file contains hidden or 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( const MyApp()); //run app fills the screen so that apps and screen look cool | |
void answerQuestion() { | |
print('Answer Chosen!'); | |
} | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return const MaterialApp( | |
home: Text('Hello riend'), | |
); | |
} | |
} | |
Widget build(BuildContext context) { | |
void answerQuestion() { | |
print('Answer Chosen!'); | |
} | |
var questions = [ | |
'whats your fav animal', | |
'whats your fav food', | |
]; | |
return MaterialApp( | |
home: Scaffold( | |
appBar: AppBar( | |
title: Text('My first App'), | |
), | |
)); | |
body: | |
Column( | |
children: [ | |
Text(questions[0]), | |
ElevatedButton( | |
child: const Text('Answer 1'), | |
onPressed: | |
answerQuestion, //now this becomes a pointer not a func and runs only when button is pressed. | |
), | |
ElevatedButton( | |
child: const Text('Answer 2'), | |
onPressed: answerQuestion, | |
), | |
ElevatedButton( | |
child: const Text('Answer 3'), | |
onPressed: answerQuestion, | |
) | |
], | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment