Skip to content

Instantly share code, notes, and snippets.

@sulmanweb
Created June 21, 2022 09:16
Show Gist options
  • Select an option

  • Save sulmanweb/c9269dafab36b5eafd6a03b43303704c to your computer and use it in GitHub Desktop.

Select an option

Save sulmanweb/c9269dafab36b5eafd6a03b43303704c to your computer and use it in GitHub Desktop.

Revisions

  1. Sulman Baig created this gist Jun 21, 2022.
    16 changes: 16 additions & 0 deletions click_button.dart
    Original 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'),
    );
    }
    }
    57 changes: 57 additions & 0 deletions main.dart
    Original 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),
    ],
    ),
    ),
    ),
    );
    }
    }
    21 changes: 21 additions & 0 deletions text_title.dart
    Original 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,
    ),
    ),
    );
    }
    }