使用flutter 写一个简单的购买电影票app

概要

这个案例没有使用任何插件,所以写着有点麻烦, 

整体架构流程

综合使用flutter中的各种widget

这个页面是通过pageView来实现的,左右滑动切换主页概括,使用堆叠布局给图片加一点遮罩效果,然后当切换的时候获取 索引值,然后切换, 数据是模拟动态数据

import 'package:flutter/material.dart';
import 'package:movie/data.dart';
import 'package:movie/widget/start.dart';

import 'details.dart';

class HomeScreen extends StatefulWidget {
  const HomeScreen({Key? key}) : super(key: key);

  @override
  State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
  var _movieData = MovieData().movieList;

  int currentIndex = 0;
  @override
  void initState() {
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView.builder(
        physics: BouncingScrollPhysics(),
        itemCount: _movieData.length,
          itemBuilder: (context,index){
        return listPageView(index);
      })
    );
  }
  Widget listPageView(int index){
    return Stack(
      children: [
        Container(
          height: double.infinity,
          width: double.infinity,
          decoration: BoxDecoration(
              image: DecorationImage(
                  image: AssetImage("${_movieData[index].image}"),fit: BoxFit.cover
              )
          ),
        ),
        Container(
          color: Colors.black.withOpacity(0.5),
        ),
        Container(
          height: double.infinity,
          width: double.infinity,
          child: Column(
            children: [
              SizedBox(height: 20),
              Row(
                children: [
                  Expanded(
                      flex: 1,
                      child: Container(
                        margin: EdgeInsets.only(left: 15),
                        height: 50,
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(8),
                            border: Border.all(color: Colors.white.withOpacity(0.5),width: 2)
                        ),
                        child: Icon(Icons.clear_all,color: Colors.white,),
                      )
                  ),
                  Expanded(
                      flex: 6,
                      child: Container(
                        margin: EdgeInsets.symmetric(horizontal: 25),
                        height: 50,
                        decoration: BoxDecoration(
                            border: Border.all(color: Colors.white.withOpacity(0.7),width: 2),
                            borderRadius: BorderRadius.circular(8)
                        ),
                        child: TextField(
                          decoration: InputDecoration(
                              hintText: "Search Movies",
                              contentPadding: EdgeInsets.only(left: 15,top: 15),
                              hintStyle: TextStyle(color: Colors.white),
                              suffixIcon: Icon(Icons.search,color: Colors.white,)
                          ),
                        ),
                      )
                  )
                ],
              ),
              SizedBox(height: 70),
              Image.asset("assets/image/togologo.png",height: 100,width: 150),
              SizedBox(height: 10),
              Text("Drama",style: TextStyle(color: Colors.white)),
              Container(
                height: 20,
                width: 100,
                child: StartWidget(rating: _movieData[index].rating),
              ),
              SizedBox(height: 20),
              GestureDetector(
                onTap: (){
                  Navigator.push(context, MaterialPageRoute(
                    builder: (context){
                      return DetailsScreen(movie: _movieData[index],);
                    }
                  ));
                },
                child: Container(
                  height: 35,
                  width: 80,
                  decoration:BoxDecoration(
                      color: Color(0xffb63831),
                      borderRadius: BorderRadius.circular(12)
                  ),
                  alignment: Alignment.center,
                  child: Text("BUY TICKET",style: TextStyle(fontSize: 12,color: Colors.white,fontWeight: FontWeight.bold),),
                ),
              ),
              SizedBox(height: 10),
              Container(
                height: 260,
                width: 180,
                decoration: BoxDecoration(
                    image: DecorationImage(
                        image: AssetImage("${_movieData[index].image}"),fit: BoxFit.cover
                    ),
                    borderRadius: BorderRadius.circular(20)
                ),
              ),
              SizedBox(height: 20),
              Text("${_movieData[index].name}",
                style: TextStyle(fontSize: 20,color: Colors.white,fontWeight: FontWeight.bold),)
            ],
          ),
        )
      ],
    );
  }
}

当写完这个页面时,点击buy ticket按钮进入到详情页出现一个动画, 使用TweenAnimation

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值