Created
June 21, 2022 09:16
-
-
Save sulmanweb/c9269dafab36b5eafd6a03b43303704c to your computer and use it in GitHub Desktop.
Revisions
-
Sulman Baig created this gist
Jun 21, 2022 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ import 'package:flutter/material.dart'; class ClickButton extends StatelessWidget { final VoidCallback onPressedHandler; const ClickButton({Key? key, required this.onPressedHandler}) : super(key: key); @override Widget build(BuildContext context) { return ElevatedButton( onPressed: onPressedHandler, child: const Text('Click Me'), ); } } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,57 @@ // 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 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ 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, ), ), ); } }