Flutter iOS风格确认对话框插件ios_style_ok_dialog的使用

Flutter iOS风格确认对话框插件 ios_style_ok_dialog 的使用

安装

  1. 如果你还没有创建 juneflow 项目,请根据以下指南创建: juneflow 创建指南

  2. juneflow 项目的根目录打开终端,输入以下命令来添加插件:

    june add ios_style_ok_dialog
    
  3. 启动项目,输入以下命令:

    flutter run lib/app/_/_/interaction/view.blueprint.popup/dialog/ios_style_ok_dialog/_/view.dart -d chrome
    

使用示例

以下是一个完整的示例代码,展示如何在 Flutter 中使用 ios_style_ok_dialog 插件:

import 'package:flutter/material.dart';
import 'package:ios_style_ok_dialog/ios_style_ok_dialog.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  void _showDialog(BuildContext context) {
    // 显示 iOS 风格的确认对话框
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return IosStyleOkDialog(
          title: "提示",
          message: "您确定要执行此操作吗?",
          onOkPressed: () {
            // 确认按钮点击事件
            print("用户点击了确认按钮");
            Navigator.of(context).pop(); // 关闭对话框
          },
        );
      },
    );
  }

  [@override](/user/override)
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("iOS 风格确认对话框示例"),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () => _showDialog(context),
          child: Text("显示对话框"),
        ),
      ),
    );
  }
}

更多关于Flutter iOS风格确认对话框插件ios_style_ok_dialog的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html

1 回复

更多关于Flutter iOS风格确认对话框插件ios_style_ok_dialog的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html


ios_style_ok_dialog 是一个 Flutter 插件,用于在应用中显示 iOS 风格的确认对话框。它提供了一个简单的方式来创建与 iOS 原生对话框类似的 UI,帮助开发者保持应用在 iOS 平台上的视觉一致性。

安装插件

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

dependencies:
  flutter:
    sdk: flutter
  ios_style_ok_dialog: ^1.0.0  # 请使用最新版本

然后运行 flutter pub get 来安装插件。

使用示例

以下是一个简单的示例,展示如何使用 ios_style_ok_dialog 来显示一个 iOS 风格的确认对话框。

import 'package:flutter/material.dart';
import 'package:ios_style_ok_dialog/ios_style_ok_dialog.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('iOS Style OK Dialog Example'),
        ),
        body: Center(
          child: ElevatedButton(
            onPressed: () {
              // 显示 iOS 风格的确认对话框
              showIosStyleOkDialog(
                context: context,
                title: '确认',
                message: '你确定要执行此操作吗?',
                okButtonText: '确定',
                onPressed: () {
                  // 当用户点击“确定”按钮时的回调
                  print('用户点击了确定');
                },
              );
            },
            child: Text('显示对话框'),
          ),
        ),
      ),
    );
  }
}
回到顶部