Created
June 21, 2022 09:16
-
-
Save sulmanweb/c9269dafab36b5eafd6a03b43303704c to your computer and use it in GitHub Desktop.
Flutter Assignment 1
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
// 1) Create a new Flutter App (in this project) and output an AppBar and some text | |
// below it | |
// 2) Add a button which changes the text (to any other text of your choice) | |
// 3) Split the app into three widgets: App, TextControl & Text | |
import 'package:flutter/material.dart'; | |
import './text_title.dart'; | |
import './click_button.dart'; | |
void main() => runApp(const MyApp()); | |
class MyApp extends StatefulWidget { | |
const MyApp({Key? key}) : super(key: key); | |
@override | |
State<MyApp> createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> { | |
static const List<String> _titles = [ | |
'First', | |
'Second', | |
'Third', | |
'Fourth', | |
'Fifth', | |
'Sixth', | |
]; | |
int _titleIndex = 0; | |
void _changeText() { | |
setState(() { | |
_titleIndex += 1; | |
if (_titleIndex >= _titles.length) { | |
_titleIndex = 0; | |
} | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Scaffold( | |
appBar: AppBar( | |
title: const Text('Flutter Assignment 1'), | |
), | |
body: Center( | |
child: Column( | |
children: [ | |
TestTitle(title: _titles[_titleIndex]), | |
ClickButton(onPressedHandler: _changeText), | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
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'; | |
class TestTitle extends StatelessWidget { | |
final String title; | |
const TestTitle({Key? key, required this.title}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
margin: const EdgeInsets.all(10), | |
child: Text( | |
title, | |
style: const TextStyle( | |
fontSize: 20, | |
fontWeight: FontWeight.w400, | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment