Created
March 7, 2024 14:57
-
-
Save midsonlajeanty/91f1a7d6fc562b85cf9780c7c3c9cff1 to your computer and use it in GitHub Desktop.
L4 EXAM - main.app
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 Application()); | |
| } | |
| class Application extends StatelessWidget { | |
| const Application({super.key}); | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| title: 'Exam App', | |
| theme: ThemeData( | |
| primarySwatch: Colors.blue | |
| ), | |
| home: const Ekran() | |
| ); | |
| } | |
| } | |
| class Ekran extends StatefulWidget { | |
| const Ekran({super.key}); | |
| @override | |
| State<Ekran> createState() => _EkranState(); | |
| } | |
| class _EkranState extends State<Ekran> { | |
| String _text = "Unknown"; | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar( | |
| title: const Text("Exam APP"), | |
| backgroundColor: Colors.blue, | |
| actions: [ | |
| Padding( | |
| padding: const EdgeInsets.all(8.0), | |
| child: IconButton( | |
| onPressed: () { | |
| setState(() { | |
| _text = "Unknown"; | |
| }); | |
| }, | |
| icon: const Icon(Icons.refresh), | |
| ), | |
| ) | |
| ], | |
| ), | |
| body: Container( | |
| padding: const EdgeInsets.all(16.0), | |
| child: Column( | |
| mainAxisAlignment: MainAxisAlignment.center, | |
| children: [ | |
| Text(_text, | |
| style: const TextStyle( | |
| fontSize: 24, | |
| fontWeight: FontWeight.bold | |
| ), | |
| ), | |
| const Divider( | |
| height: 64, | |
| indent: 16, | |
| endIndent: 16, | |
| ), | |
| AppButton( | |
| text: "Button 1", | |
| color: Colors.orange, | |
| onPressed: () { | |
| setState(() { | |
| _text = "Button 1 Klike"; | |
| }); | |
| }, | |
| ), | |
| const SizedBox(height: 16,), | |
| AppButton( | |
| text: "Button 2", | |
| color: Colors.blue, | |
| onPressed: () { | |
| setState(() { | |
| _text = "Button 2 Klike"; | |
| }); | |
| }, | |
| ), | |
| const SizedBox(height: 16,), | |
| AppButton( | |
| text: "Button 1", | |
| color: Colors.red, | |
| onPressed: () { | |
| setState(() { | |
| _text = "Button 3 Klike"; | |
| }); | |
| }, | |
| ) | |
| ], | |
| ), | |
| ), | |
| ); | |
| } | |
| } | |
| class AppButton extends StatelessWidget { | |
| const AppButton({ | |
| super.key, required this.text, required this.onPressed, required this.color, | |
| }); | |
| final String text; | |
| final VoidCallback onPressed; | |
| final Color color; | |
| @override | |
| Widget build(BuildContext context) { | |
| return SizedBox( | |
| width: double.infinity, | |
| height: 56, | |
| child: ElevatedButton( | |
| style: ElevatedButton.styleFrom( | |
| foregroundColor: color == Colors.white ? Colors.black : Colors.white, | |
| backgroundColor: color | |
| ), | |
| onPressed: onPressed, | |
| child: Text(text, | |
| style: const TextStyle( | |
| fontSize: 18, | |
| fontWeight: FontWeight.bold | |
| ), | |
| ) | |
| ) | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment