android - 如何在 flutter 中制作不透明的教程屏幕?

我想制作一开始就向用户显示的教程屏幕。如下所示:

我的具体问题,如何使某些元素正常显示而其他不透明?

还有箭头和文字,如何根据移动设备屏幕尺寸完美指向(移动响应)?

最佳答案

正如 RoyalGriffin 所说,您可以使用 highlighter_coachmark库,我也知道您遇到的错误,错误是因为您使用的是从 2 个不同包导入的 RangeSlider 类。您可以在您的应用中尝试此示例并检查它是否正常工作吗?

  1. highlighter_coachmark 添加到您的 pubspec.yaml 文件

    dependencies:
      flutter:
        sdk: flutter
    
      highlighter_coachmark: ^0.0.3
    
  2. 运行flutter packages get


示例:

import 'package:highlighter_coachmark/highlighter_coachmark.dart';

void main() => runApp(MaterialApp(home: HomePage()));

class HomePage extends StatefulWidget {
  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  GlobalKey _fabKey = GlobalObjectKey("fab"); // used by FAB
  GlobalKey _buttonKey = GlobalObjectKey("button"); // used by RaisedButton

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: FloatingActionButton(
        key: _fabKey, // setting key
        onPressed: null,
        child: Icon(Icons.add),
      ),
      body: Center(
        child: RaisedButton(
          key: _buttonKey, // setting key
          onPressed: showFAB,
          child: Text("RaisedButton"),
        ),
      ),
    );
  }

  // we trigger this method on RaisedButton click
  void showFAB() {
    CoachMark coachMarkFAB = CoachMark();
    RenderBox target = _fabKey.currentContext.findRenderObject();

    // you can change the shape of the mark
    Rect markRect = target.localToGlobal(Offset.zero) & target.size;
    markRect = Rect.fromCircle(center: markRect.center, radius: markRect.longestSide * 0.6);

    coachMarkFAB.show(
      targetContext: _fabKey.currentContext,
      markRect: markRect,
      children: [
        Center(
          child: Text(
            "This is called\nFloatingActionButton",
            style: const TextStyle(
              fontSize: 24.0,
              fontStyle: FontStyle.italic,
              color: Colors.white,
            ),
          ),
        )
      ],
      duration: null, // we don't want to dismiss this mark automatically so we are passing null
      // when this mark is closed, after 1s we show mark on RaisedButton
      onClose: () => Timer(Duration(seconds: 1), () => showButton()),
    );
  }

  // this is triggered once first mark is dismissed
  void showButton() {
    CoachMark coachMarkTile = CoachMark();
    RenderBox target = _buttonKey.currentContext.findRenderObject();

    Rect markRect = target.localToGlobal(Offset.zero) & target.size;
    markRect = markRect.inflate(5.0);

    coachMarkTile.show(
      targetContext: _fabKey.currentContext,
      markRect: markRect,
      markShape: BoxShape.rectangle,
      children: [
        Positioned(
          top: markRect.bottom + 15.0,
          right: 5.0,
          child: Text(
            "And this is a RaisedButton",
            style: const TextStyle(
              fontSize: 24.0,
              fontStyle: FontStyle.italic,
              color: Colors.white,
            ),
          ),
        )
      ],
      duration: Duration(seconds: 5), // this effect will only last for 5s
    );
  }
}

输出:


https://stackoverflow.com/questions/56822288/

相关文章:

dart - 带有快速拨号的 flutter float Action 按钮

dart - 为什么 setState 会关闭?

flutter - 垂直视口(viewport)被赋予了无限的高度

flutter - 在 Flutter 中显示用户友好的错误页面而不是异常

flutter - 点击 AppBar 打开抽屉

dart - 如何检测 Flutter 中布局的方向变化?

flutter - 在 Flutter 中更改 TextField 的下划线

flutter - 如何在 Flutter 中创建 GridView 布局

android - 使用 Flutter 的 Android Studio 中不显示设备列表

dart - 如何在 Flutter 中隐藏 TextField 底部的字母计数器