Last active
May 17, 2021 13:16
-
-
Save sodogan/7d0eed49f6849c9e50e552a8f3ec188e to your computer and use it in GitHub Desktop.
Flutter basic app
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(MyMainApp()); | |
} | |
class MyMainApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home:_MyApp() | |
); | |
} | |
} | |
class _MyApp extends StatefulWidget { | |
@override | |
_MyAppState createState()=> new _MyAppState(); | |
} | |
class _MyAppState extends State<_MyApp> { | |
final questions = [ | |
{"question":"whats your favourite color?", | |
"answers":["Red","Green","Blue"] | |
}, | |
{"question":"whats your favourite guy?", | |
"answers":["Myself","Eren","Ozgur"] | |
} | |
]; | |
int _counter = 0; | |
incrementCounter(){ | |
setState(()=>_counter++); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title:Text("Quiz Sample") , actions: [ new Icon(Icons.refresh) ], ), | |
body: Center( | |
child: Column( | |
children: [ | |
Text(questions[_counter]["question"] as String) | |
], | |
), | |
),//end of body | |
floatingActionButton: MyFloatingActionButton(text: "+",pressHandler: incrementCounter), | |
); | |
} | |
} | |
class MyFloatingActionButton extends StatelessWidget{ | |
final String text; | |
final void Function() pressHandler; | |
MyFloatingActionButton({required this.text,required this.pressHandler}); | |
@override | |
Widget build(BuildContext context) | |
{ | |
return FloatingActionButton( onPressed: this.pressHandler, | |
child: Icon(Icons.check_circle) | |
); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment