name27 / flutter

0 stars 0 forks source link

GetX 상태관리 기법 #99

Open name27 opened 1 year ago

name27 commented 1 year ago

페이지 라우팅 -Get.to(()=>NewPage())

스낵바

디바이스 화면 사이즈

name27 commented 1 year ago

image image image image

main.dart

import 'package:flutter/material.dart';
import 'package:get/get_navigation/get_navigation.dart';
import 'package:use_get_x_app/page/main_page.dart';

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

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

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

main_page.dart

import 'package:flutter/material.dart';
import 'package:get/get.dart';

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            ElevatedButton(
                onPressed: () {
                  Get.bottomSheet(
                    SizedBox(
                        height: Get.height * 0.3,
                        child: Column(
                          children: [Text('1'), Text('2')],
                        )),
                    shape: const RoundedRectangleBorder(
                      borderRadius: BorderRadius.only(
                        topRight: Radius.circular(20),
                        topLeft: Radius.circular(20),
                      ),
                    ),
                    backgroundColor: Colors.black,
                    clipBehavior: Clip.hardEdge,
                  );
                },
                child: Text('바텀시트')),
            ElevatedButton(
                onPressed: () {
                  Get.snackbar('title', 'content',
                      backgroundColor: Colors.black,
                      snackPosition: SnackPosition.BOTTOM);
                },
                child: Text('스낵바'))
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(onPressed: () {
        Get.dialog(
          AlertDialog(
            title: Text('title'),
            content: Text('content'),
            actions: [
              TextButton(
                onPressed: Get.back,
                child: Text('cancel'),
              ),
              TextButton(
                onPressed: Get.back,
                child: Text('confirm'),
              ),
            ],
          ),
        );
      }),
    );
  }
}