Flutter电影票务卡片展示插件movie_ticket_card的使用

Flutter电影票务卡片展示插件movie_ticket_card的使用

movie_ticket_card 是一个用于展示电影票务卡片样式的 Flutter 插件。

使用

要使用此插件,在 pubspec.yaml 文件中添加 movie_ticket_card 作为依赖项。

组件

TicketCard

TicketCard 是主要组件,用于创建电影票务卡片。它包含以下属性:

属性名 描述
lineFromTop 分割线距离顶部的距离
lineRadius 分割线两端圆角的半径
lineColor 分割线的颜色
decoration 票卡装饰器
child 票卡的子组件

示例

// 导入包
import 'package:movie_ticket_card/movie_ticket_card.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // 这是应用的根部件
  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  [@override](/user/override)
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  [@override](/user/override)
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: SingleChildScrollView(
          child: Padding(
            padding: const EdgeInsets.all(20),
            child: TicketCard(
              decoration: TicketDecoration(
                  shadow: [TicketShadow(color: Colors.grey, elevation: 6)]),
              lineFromTop: 150,
              child: Container(
                width: double.infinity,
                color: Colors.grey.shade300,
                height: 500,
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Container(
                      height: 140,
                      child: Padding(
                        padding: const EdgeInsets.all(20.0),
                        child: Row(
                          children: [
                            Expanded(
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                                children: [
                                  Text(
                                    "复仇者联盟4:终局之战",
                                    style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
                                  ),
                                  Text("2019-11-21 19:00 开始,成龙耀莱影城(板前店),六号激光厅"),
                                  Text(
                                    "6排7座",
                                    style: TextStyle(color: Colors.grey),
                                  )
                                ],
                              ),
                            ),
                            AspectRatio(
                              aspectRatio: 1,
                              child: Container(color: Colors.grey),
                            )
                          ],
                        ),
                      ),
                    ),
                    Expanded(
                      child: Container(
                        margin: const EdgeInsets.only(top: 20),
                        child: Column(
                          children: [
                            Text(
                              "扫码入场",
                              style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
                            ),
                            SizedBox(
                              height: 30,
                            ),
                            Container(
                              height: 150,
                              width: 150,
                              color: Colors.grey,
                            )
                          ],
                        ),
                      ),
                    )
                  ],
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}

更多关于Flutter电影票务卡片展示插件movie_ticket_card的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html

1 回复

更多关于Flutter电影票务卡片展示插件movie_ticket_card的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html


movie_ticket_card 是一个用于在 Flutter 应用中展示电影票务卡片的插件。它可以帮助你快速创建一个美观的电影票务卡片,提供类似于电影票的布局和设计。这个插件通常用于电影票务应用、购票确认页面等场景。

以下是一个基本的使用示例,展示如何使用 movie_ticket_card 插件创建一个电影票务卡片。

1. 添加依赖

首先,你需要在 pubspec.yaml 文件中添加 movie_ticket_card 插件的依赖:

dependencies:
  flutter:
    sdk: flutter
  movie_ticket_card: ^1.0.0  # 请查看最新的版本号

然后运行 flutter pub get 来安装依赖。

2. 导入插件

在你的 Dart 文件中导入 movie_ticket_card 插件:

import 'package:movie_ticket_card/movie_ticket_card.dart';

3. 创建电影票务卡片

使用 MovieTicketCard 组件来创建电影票务卡片。你可以传递各种参数来自定义卡片的样式和内容。

class MovieTicketPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Movie Ticket'),
      ),
      body: Center(
        child: MovieTicketCard(
          movieName: 'Inception',
          date: '2023-10-15',
          time: '19:00',
          seat: 'A12',
          cinema: 'AMC Theater',
          qrCode: 'https://example.com/qr-code.png', // 二维码图片的URL
          onTap: () {
            print('Movie ticket tapped!');
          },
        ),
      ),
    );
  }
}

4. 参数说明

MovieTicketCard 组件接受以下参数:

  • movieName: 电影的名称。
  • date: 电影的放映日期。
  • time: 电影的放映时间。
  • seat: 座位号。
  • cinema: 电影院名称。
  • qrCode: 二维码图片的URL或本地路径。
  • onTap: 点击卡片的回调函数。

5. 自定义样式

你可以通过传递额外的参数来自定义卡片的样式,例如背景颜色、文字样式等。请参考插件的文档来查看所有可用的自定义选项。

6. 运行应用

现在你可以运行你的 Flutter 应用,并看到创建的电影票务卡片。

flutter run
回到顶部