스마트시대

widget 모음판 SETTINGS 13.0 ListWheelScrollView 13.1 AboutListTile 13.2 showDateRangePicker 13.3 SwitchListTile 13.4 CupertinoAlertDialog 13.5 CupertinoActionSheet 본문

Programing/Flutter

widget 모음판 SETTINGS 13.0 ListWheelScrollView 13.1 AboutListTile 13.2 showDateRangePicker 13.3 SwitchListTile 13.4 CupertinoAlertDialog 13.5 CupertinoActionSheet

스마트시대 2023. 5. 23. 15:34
728x90

13.0 ListWheelScrollView

 

13.1 AboutListTile

 

13.2 showDateRangePicker

import 'package:flutter/material.dart';

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Settings"),
      ),
      body: ListView(
        children: [
          ListTile(
            onTap: () async {
              final date = await showDatePicker(
                context: context,
                initialDate: DateTime.now(),
                firstDate: DateTime(1980),
                lastDate: DateTime(2030),
              );
              print(date);
              final time = await showTimePicker(
                context: context,
                initialTime: TimeOfDay.now(),
              );
              print(time);
              final booking = await showDateRangePicker(
                context: context,
                firstDate: DateTime(1980),
                lastDate: DateTime(2030),
                builder: (context, child) {
                  return Theme(
                    data: ThemeData(
                      appBarTheme: const AppBarTheme(
                        foregroundColor: Colors.white,
                        backgroundColor: Colors.black,
                      ),
                    ),
                    child: child!,
                  );
                },
              );
              print(booking);
            },
            title: const Text("What is your birthday?"),
          ),
          const AboutListTile(),
        ],
      ),
    );
  }
}

 

13.3 SwitchListTile

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

class SettingsScreen extends StatefulWidget {
  const SettingsScreen({super.key});

  @override
  State<SettingsScreen> createState() => _SettingsScreenState();
}

class _SettingsScreenState extends State<SettingsScreen> {



-------------------
  bool _notifications = false;

  void _onNotificationsChaged(bool? newValue) {
    if (newValue == null) return;
    setState(() {
      _notifications = newValue;
    });
  }
-------------------


@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Settings"),
      ),
      body: ListView(
        children: [
        
        
        
        -------------------
          Switch.adaptive(
            value: _notifications,
            onChanged: _onNotificationsChaged,
          ),
          CupertinoSwitch(
            value: _notifications,
            onChanged: _onNotificationsChaged,
          ),
          SwitchListTile.adaptive(
            value: _notifications,
            onChanged: _onNotificationsChaged,
            title: const Text("Enable notifications"),
            subtitle: const Text("Enable notifications"),
          ),
          Checkbox(
            value: _notifications,
            onChanged: _onNotificationsChaged,
          ),
          CheckboxListTile(
            activeColor: Colors.black,
            value: _notifications,
            onChanged: _onNotificationsChaged,
            title: const Text("Enable notifications"),
          ),
          -------------------
          
          
          
          
          ListTile(
            onTap: () async {

 

13.4 CupertinoAlertDialog

title: const Text("What is your birthday?"),
          ),
          
          -----------------------
          //iOS version
          ListTile(
            title: const Text("Log out (iOS)"),
            textColor: Colors.red,
            onTap: () {
              showCupertinoDialog(
                context: context,
                builder: (context) => CupertinoAlertDialog(
                  title: const Text("Are you sure?"),
                  content: const Text("Please don't go"),
                  actions: [
                    CupertinoDialogAction(
                      onPressed: () => Navigator.of(context).pop(),
                      child: const Text("No"),
                    ),
                    CupertinoDialogAction(
                      onPressed: () => Navigator.of(context).pop(),
                      isDestructiveAction: true,
                      child: const Text("Yes"),
                    ),
                  ],
                ),
              );
            },
          ),
          //Android version
          ListTile(
            title: const Text("Log out (Android)"),
            textColor: Colors.red,
            onTap: () {
              showDialog(
                context: context,
                builder: (context) => AlertDialog(
                  icon: const FaIcon(FontAwesomeIcons.skull),
                  title: const Text("Are you sure?"),
                  content: const Text("Please don't go"),
                  actions: [
                    IconButton(
                      onPressed: () => Navigator.of(context).pop(),
                      icon: const FaIcon(FontAwesomeIcons.car),
                    ),
                    TextButton(
                      onPressed: () => Navigator.of(context).pop(),
                      child: const Text("Yes"),
                    ),
                  ],
                ),
              );
            },
          ),
-----------------------
          const AboutListTile(),

 

13.5 CupertinoActionSheet

-----------------
ListTile(
            title: const Text("Log out (iOS / Bottom)"),
            textColor: Colors.red,
            onTap: () {
              //popup창 바깥쪽 클릭해도 나와지는 함수
              showCupertinoModalPopup(
                context: context,
                builder: (context) => CupertinoActionSheet(
                  title: const Text("Are you sure?"),
                  message: const Text("Plz don't go"),
                  actions: [
                    CupertinoActionSheetAction(
                      // 글짜 빨간색으로 표시 가능
                      isDestructiveAction: true,
                      onPressed: () => Navigator.of(context).pop(),
                      child: const Text("Not log out"),
                    ),
                    CupertinoActionSheetAction(
                      // bold자로 표시 가능
                      isDefaultAction: true,
                      onPressed: () => Navigator.of(context).pop(),
                      child: const Text("Yes please"),
                    ),
                  ],
                ),
              );
            },
          ),
---------------------
          const AboutListTile(),
        ],
      ),

728x90
반응형
Comments