【问题标题】:Swipe circle to open new Activity(page) in flutter滑动圆圈以在颤动中打开新的活动(页面)
【发布时间】:2020-07-05 13:08:14
【问题描述】:

我想在屏幕中间滑动圆圈时打开新页面。也就是说,当我向左滑动蓝色圆圈时,应该会打开一个新页面,而当我向右滑动时,应该会打开另一个新页面。

同样,当我在粉红色圆圈底部滑动时,应该会打开另一个新页面

这是我的代码:

import 'package:flutter/material.dart';

class FirstRoute extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Container(
          height: 300.0,
          width: 150.0,
          child: Stack(
            children: <Widget>[
              Positioned(
                top: 25,
                  child: Container(
                  height: 150.0,
                  width: 150.0,
                  decoration: BoxDecoration(
                    shape:BoxShape.circle,
                    color:Colors.lightBlue,
                  ),
                ),
              ),
              Positioned(
                bottom: 25,
                child: Opacity(
                  opacity: 0.45,
                    child: Container(
                    height: 150.0,
                  width: 150.0,
                  decoration: BoxDecoration(
                    shape:BoxShape.circle,
                    color:Colors.pinkAccent,
                  ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

【问题讨论】:

    标签: flutter gesture swipe-gesture


    【解决方案1】:

    SwipeDetector() 小部件包装Positioned()

    看看这个例子

        SwipeDetector(
         onSwipeRight: () {
           //push new page
           Navigator.of(context).push(new MaterialPageRoute(builder: (BuildContext context) => new YourNewPage())); 
          },
         child: //Your circle here
                Positioned(
                    top: 25,
                      child: Container(
                      height: 150.0,
                      width: 150.0,
                      decoration: BoxDecoration(
                        shape:BoxShape.circle,
                        color:Colors.lightBlue,
                      ),
                    ),
                  ),
             )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-15
      • 2020-01-04
      • 2021-10-03
      • 1970-01-01
      相关资源
      最近更新 更多