13일차 과제 - rlatkddbs99/Flutter GitHub Wiki

캡처1

main.dart

import 'package:flutter/material.dart';
import 'package:word_test/page/mainPage.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark(),
      home: MainPage(),
    );
  }
}

MainPage.dart

import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/container.dart';
import 'package:flutter/src/widgets/framework.dart';

class MainPage extends StatelessWidget {
  const MainPage({super.key});

  @override
  Widget build(BuildContext context) {
    var pageController = PageController();
    List<Map<String, String>> words = [
      {"word": "apple", "meaning": "사과", "example": "I want to eat an apple"},
      {
        "word": "paper",
        "meaning": "종이",
        "example": "Could you give me a paper"
      },
      {
        "word": "resilient",
        "meaning": "탄력있는, 회복력있는",
        "example": "She's a resilient girl"
      },
      {
        "word": "revoke",
        "meaning": "취소하다",
        "example":
            "The authorities have revoked their original decision to allow development of this rural area."
      },
      {
        "word": "withdraw",
        "meaning": "철회하다",
        "example":
            "After lunch, we withdrew into her office to finish our discussion in private."
      },
    ];
    return Scaffold(
      floatingActionButton: Stack(
        children: [
          Align(
            alignment: Alignment.bottomLeft,
            child: Padding(
              padding: const EdgeInsets.only(left: 35),
              child: FloatingActionButton(
                  onPressed: () {
                    pageController.previousPage(
                        duration: Duration(seconds: 1), curve: Curves.ease);
                  },
                  child: Icon(Icons.chevron_left)),
            ),
          ),
          Align(
            alignment: Alignment.bottomRight,
            child: Padding(
              padding: const EdgeInsets.only(right: 8.0),
              child: FloatingActionButton(
                onPressed: () {
                  pageController.nextPage(
                      duration: Duration(seconds: 1), curve: Curves.ease);
                },
                child: Icon(Icons.chevron_right),
              ),
            ),
          )
        ],
      ),
      body: SafeArea(
          child: PageView.builder(
              physics: NeverScrollableScrollPhysics(),
              controller: pageController,
              itemCount: words.length,
              itemBuilder: (context, index) {
                return Center(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text(
                        words[index]["word"].toString(),
                        style: TextStyle(
                            letterSpacing: -1,
                            color: Colors.white,
                            fontWeight: FontWeight.bold,
                            fontSize: 36),
                      ),
                      SizedBox(
                        height: 8,
                      ),
                      Text(
                        words[index]["meaning"].toString(),
                        style: TextStyle(
                            letterSpacing: -1,
                            color: Colors.grey,
                            fontSize: 16),
                      ),
                      SizedBox(
                        height: 16,
                      ),
                      Text(
                        '"${words[index]["example"].toString()}"',
                        textAlign: TextAlign.center,
                        style: TextStyle(
                            letterSpacing: 1, color: Colors.grey, fontSize: 16),
                      ),
                    ],
                  ),
                );
              })),
    );
  }
}