Skip to content

csabika98/flutter_hello_world

Repository files navigation

logo.svg

Hello World Flutter App

This is a simple Flutter app that generates random word pairings and allows users to generate a new word pairing by pressing a button.

My first app built in Flutter.

Screenshots

alt text

alt text

Getting Started

Prerequisites

Installation

  1. Clone the repository:
   git clone https://github.com/csabika98/hello_world_flutter.git
  1. Navigate to the project directory:
   cd hello_world_flutter
  1. Get the dependencies:
   flutter pub get

Launching the App

1. Open `lib/main.dart` in VS Code.
2. Select your target device in the bottom right corner of VS Code.
3. Click the "play" button in the upper right-hand corner of VS Code.
4. The app will launch in debug mode.

Changelog

Adding a Button

  1. Add the following button code to lib/main.dart:
   ElevatedButton(
     onPressed: () {
       appState.getNext();
     },
     child: Text('Next'),
   );
  1. Save the file. The app will update with a new button.

Hot Reload

  1. Modify the string in the first Text widget: Text('A random AWESOME idea:'),
  2. Save the file to see the changes immediately.

State Management

1. Add a `getNext` method in `MyAppState`:
   void getNext() {
     current = WordPair.random();
     notifyListeners();
   }
  1. Update the button's onPressed callback to call getNext():
    onPressed: () {
     appState.getNext();
   },

UI Enhancements

  1. Extract the word pair display into a separate widget BigCard.

  2. Wrap the BigCard with Padding and Card widgets for better styling.

  3. Apply a theme to the card and text:

 
   final theme = Theme.of(context);
   final style = theme.textTheme.displayMedium!.copyWith(
     color: theme.colorScheme.onPrimary,
   );

Accessibility

  1. Improve screen reader support by setting the semanticsLabel:
   semanticsLabel: "${pair.first} ${pair.second}",

Center the UI

  1. Center the contents vertically and horizontally using mainAxisAlignment and Center widget:
   mainAxisAlignment: MainAxisAlignment.center,

Final Code Example

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var appState = context.watch<MyAppState>();
    var pair = appState.current;

    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            BigCard(pair: pair),
            SizedBox(height: 10),
            ElevatedButton(
              onPressed: () {
                appState.getNext();
              },
              child: Text('Next'),
            ),
          ],
        ),
      ),
    );
  }
}

Additional Resources

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published