Skip to content

Instantly share code, notes, and snippets.

@RayyanNafees
Last active December 28, 2023 02:54
Show Gist options
  • Save RayyanNafees/5b21aa9dedef85a0e5bbf340e1e34a76 to your computer and use it in GitHub Desktop.
Save RayyanNafees/5b21aa9dedef85a0e5bbf340e1e34a76 to your computer and use it in GitHub Desktop.
coder-flutter
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