【问题标题】:Flutter Onboarding - How to Swipe Two Images at The Same Time?Flutter Onboarding - 如何同时滑动两张图片?
【发布时间】:2020-07-06 21:54:10
【问题描述】:

我想用浮动操作按钮在屏幕底部的末端用一个结束图像向右滑动背景图像,并想像其他入门屏幕一样向右滑动一个带有背景图像的图像列表。这里我需要 3 个屏幕,最后一个屏幕将是登录页面。我为此使用了 Transformer Page View 包。目前,我在浮动操作按钮中使用了一个图像,但它不起作用。我怎么能做到这一点?

 import 'package:flutter/material.dart';
 import 'package:onlycentertainment/pages/splashscreen.dart';
 import 'package:transformer_page_view/transformer_page_view.dart';



class TestPage1 extends StatefulWidget {
  final String title;
  TestPage1({this.title});
  @override
  TestPage1State createState() {
    return new TestPage1State();
  }
}

class TestPage1State extends State<TestPage1> {
  int _slideIndex = 0;
  int _bottomIndex = 0;

  final List<String> images = [
    "assets/images/welcome01.jpg",
    "assets/images/welcome02.jpg",
    "assets/images/welcome01.jpg",
  ];

  final List<String> text0 = [
    "Welcome in your app",
    "Enjoy teaching...",
    "Showcase your skills",
    "Friendship is great"
  ];

  final List<String> text1 = [
    "App for food lovers, satisfy your taste",
    "Find best meals in your area, simply",
    "Have fun while eating your relatives and more",
    "Meet new friends from all over the world"
  ];

  final IndexController controller = IndexController();

  @override
  Widget build(BuildContext context) {

    TransformerPageView transformerPageView = TransformerPageView(
        pageSnapping: true,
        onPageChanged: (index) {
          setState(() {
            this._slideIndex = index;
            this._bottomIndex = index;
          });
        },
        loop: false,
        controller: controller,
        transformer: new PageTransformerBuilder(
            builder: (Widget child, TransformInfo info) {
              return SingleChildScrollView(
                physics: NeverScrollableScrollPhysics(),
                child: new Material(
                  child: new Container(
                    alignment: Alignment.center,
                    color: Colors.white,
                    child: Column(
                      children: <Widget>[
                        new ParallaxContainer(
                          child: new Image.asset(
                            images[info.index],
                            fit: BoxFit.cover,

                          ),
                          position: info.position,
                          translationFactor: 400.0,
                        ),
                        SizedBox(
                          height: 45.0,
                        ),
                        new ParallaxContainer(
                          child: new Text(
                            text1[info.index],
                            textAlign: TextAlign.center,
                            style: new TextStyle(
                                color: Colors.white,
                                fontSize: 28.0,
                                fontFamily: 'Quicksand',
                                fontWeight: FontWeight.bold),
                          ),
                          position: info.position,
                          translationFactor: 300.0,
                        ),
                      ],
                    ),
                  ),
                ),
              );
            }),
        itemCount: 3);

    return Scaffold(
      backgroundColor: Color(0xff243951),
      body: transformerPageView,
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      floatingActionButton: Container(
        height: 70,
        width: MediaQuery.of(context).size.width,
        child: IconButton(icon: Image.asset('assets/images/asset1.png'), onPressed: (){
          Navigator.of(context).push(MaterialPageRoute(builder: (context)=>SplashScreen()));
        }),
      ),
    );

  }
}

【问题讨论】:

    标签: flutter animation splash-screen


    【解决方案1】:

    我不确定我是否理解正确,但是你的代码的问题是“SplashScreen()”部分,它不能为空,我做了一个工作示例,如果我误解了你的意思,请查看并告诉我想做。

    import 'package:flutter/material.dart';
    import 'package:splashscreen/splashscreen.dart';
    import 'package:transformer_page_view/transformer_page_view.dart';
    
    void main() {
      runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return new MaterialApp(
          title: 'Flutter Demo',
          theme: new ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: new TestPage1(title: 'Flutter Demo Home Page'),
        );
      }
    }
    
    class TestPage1 extends StatefulWidget {
      final String title;
      TestPage1({this.title});
      @override
      TestPage1State createState() {
        return new TestPage1State();
      }
    }
    
    class TestPage1State extends State<TestPage1> {
      int _slideIndex = 0;
      int _bottomIndex = 0;
    
      final List<String> images = [
        "assets/images/welcome01.jpg",
        "assets/images/welcome02.jpg",
        "assets/images/welcome01.jpg",
      ];
    
      final List<String> text0 = [
        "Welcome in your app",
        "Enjoy teaching...",
        "Showcase your skills",
        "Friendship is great"
      ];
    
      final List<String> text1 = [
        "App for food lovers, satisfy your taste",
        "Find best meals in your area, simply",
        "Have fun while eating your relatives and more",
        "Meet new friends from all over the world"
      ];
    
      final IndexController controller = IndexController();
    
      @override
      Widget build(BuildContext context) {
    
        TransformerPageView transformerPageView = TransformerPageView(
            pageSnapping: true,
            onPageChanged: (index) {
              setState(() {
                this._slideIndex = index;
                this._bottomIndex = index;
              });
            },
            loop: false,
            controller: controller,
            transformer: new PageTransformerBuilder(
                builder: (Widget child, TransformInfo info) {
                  return SingleChildScrollView(
                    physics: NeverScrollableScrollPhysics(),
                    child: new Material(
                      child: new Container(
                        alignment: Alignment.center,
                        color: Colors.white,
                        child: Column(
                          children: <Widget>[
                            new ParallaxContainer(
                              child: new Image.asset(
                                images[info.index],
                                fit: BoxFit.cover,
    
                              ),
                              position: info.position,
                              translationFactor: 400.0,
                            ),
                            SizedBox(
                              height: 45.0,
                            ),
                            new ParallaxContainer(
                              child: new Text(
                                text1[info.index],
                                textAlign: TextAlign.center,
                                style: new TextStyle(
                                    color: Colors.white,
                                    fontSize: 28.0,
                                    fontFamily: 'Quicksand',
                                    fontWeight: FontWeight.bold),
                              ),
                              position: info.position,
                              translationFactor: 300.0,
                            ),
                          ],
                        ),
                      ),
                    ),
                  );
                }),
            itemCount: 3);
    
        return Scaffold(
          backgroundColor: Color(0xff243951),
          body: transformerPageView,
          floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
          floatingActionButton: Container(
            height: 70,
            width: MediaQuery.of(context).size.width,
            child: IconButton(icon: Image.asset(images[_bottomIndex]), onPressed: (){
              Navigator.of(context).push(MaterialPageRoute(builder: (context)=>SplashScreen(
                  seconds: 4,
                  navigateAfterSeconds: new AfterSplash(),
                  title: new Text('Welcome In SplashScreen',
                    style: new TextStyle(
                        fontWeight: FontWeight.bold,
                        fontSize: 20.0
                    ),
                  )
              )
              )
              );
        }
        ),
              ),
            );
    
      }
    }
    class AfterSplash extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return new Scaffold(
          appBar: new AppBar(
            title: new Text("Welcome In SplashScreen Package"),
            automaticallyImplyLeading: false,
          ),
          body: new Center(
            child: new Text("Succeeded!",
              style: new TextStyle(
                  fontWeight: FontWeight.bold,
                  fontSize: 30.0
              ),
            ),
          ),
        );
      }
    }
    

    【讨论】:

    • 如何更改底部按钮和照片以及入职屏幕?
    • 您是否想根据屏幕上显示的图像更改按钮图像?
    • 这个更改必须处理它“IconButton(icon: Image.asset(images[_bottomIndex])”,我更新了答案中的代码再次检查。
    • 谢谢,它有效!我喜欢从你那里得到另一个答案,我想在刷入入职屏幕的最后一页后自动显示登录/启动屏幕。我想滑动入职界面 1>入职界面 2>入职界面 3>欢迎页面
    • 您可以确认我的回答是否有效 :) 据我所知,您想滑动所有页面一次,然后它将转到另一个屏幕而不是返回第一个屏幕。我不知道transformer_page_view 是否可行
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-07
    • 2015-07-26
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多