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

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

// MyApp is a StatefulWidget. This allows updating the state of the
// widget when an item is removed.
class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  MyAppState createState() {
    return MyAppState();
  }
}

class MyAppState extends State<MyApp> {
  final List<String> items = [
    '신사와 아가씨',
    '빨강 구두',
    '국가대표 와이프',
    '원 더 우먼',
    '홍천기',
    '검은태양',
    '두 번째 남편',
    '연모',
    '달리와 감자탕',
    '원 더 우먼(재방송)',
    '홍천기(재방송)',
    '신사와 아가씨(재방송)',
    '두 번째 남편(재방송)',
    '연모(재방송)',
    'KBS 네트워크 특선',
    '국가대표 와이프(재방송)',
    '드라마스페셜2021-시네마회수',
    '달리와 감자탕(재방송)',
    '검은태양(재방송)',
    '빨강 구두(스페셜)',
  ];

  @override
  Widget build(BuildContext context) {
    const title = '드라마 대본 20선';

    return MaterialApp(
      title: title,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: const Text(title),
        ),
        body: ListView.builder(
          itemCount: items.length,
          itemBuilder: (context, index) {
            final item = items[index];
            return Dismissible(
              // Each Dismissible must contain a Key. Keys allow Flutter to
              // uniquely identify widgets.
              key: Key(item),
              // Provide a function that tells the app
              // what to do after an item has been swiped away.
              onDismissed: (direction) {
                // Remove the item from the data source.
                setState(() {
                  items.removeAt(index);
                });

                // Then show a snackbar.
                ScaffoldMessenger.of(context)
                    .showSnackBar(SnackBar(content: Text('$item dismissed')));
              },
              // Show a red background as the item is swiped away.
              background: Container(color: Colors.red),
              child: ListTile(
                title: Text(item),
              ),
            );
          },
        ),
      ),
    );
  }
}

Dismissible

Leave a comment