Flutter步进器插件stylish_stepper的使用

Flutter步进器插件stylish_stepper的使用

Stylish Stepper 是一个 Flutter 包,它为您的 Flutter 应用程序提供了可自定义的步进器小部件。它可以轻松创建视觉上吸引人的分步进度指示器。

特性

列出你的包可以做什么。也许包括图片、GIF或视频。

开始使用

要使用此包,请遵循以下步骤:

添加依赖

pubspec.yaml 文件中添加以下依赖:

dependencies:
  stylish_stepper: ^1.0.0

运行 flutter pub get 来安装该包。

导入包

在代码中导入该包:

import 'package:stylish_stepper/stylish_stepper.dart';

开始在您的 Flutter 应用程序中使用 Stylish Stepper 小部件。

使用示例

const StylishStepper(
  dotIconColor: Colors.green,
  verticalLineLeftPadding: 5,
  verticalLineIconHeight: 150,
  gap: 0,
  content: Column(
    crossAxisAlignment: CrossAxisAlignment.start,
    children: [
      Text(
        'My Name is Pradeep Tharu',
        style: TextStyle(color: Colors.white),
      ),
      Text(
        'My Name is Pradeep Tharu',
        style: TextStyle(color: Colors.white),
      ),
      Text(
        'My Name is Pradeep Tharu',
        style: TextStyle(color: Colors.white),
      ),
      Text(
        'My Name is Pradeep Tharu',
        style: TextStyle(color: Colors.white),
      ),
    ],
  ),
  header: Text('How Are You'),
),

更改垂直图标

StylishStepper(
  svgIcon: SStepperIcons.line,
),

StylishStepper(
  svgIcon: SStepperIcons.dot,
),

完整的应用示例

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

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Stylish Stepper',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  [@override](/user/override)
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Stylish Stepper'),
      ),
      body: SingleChildScrollView(
        child: Padding(
          padding: const EdgeInsets.all(10.0),
          child: Column(
            children: [
              ListView.builder(
                itemCount: dataList.length,
                shrinkWrap: true,
                itemBuilder: (context, index) => StylishStepper(
                  contentContainerColor: SSColor.secondary,
                  showLastIcon: true,
                  header: Text(dataList[index]['name']),
                  verticalLineTopPadding: 15,
                  verticalLineLeftPadding: 5.5,
                  verticalLineIconHeight: 200,
                  content: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        dataList[index]['name'],
                        style: const TextStyle(color: Colors.white),
                      ),
                      Text(
                        dataList[index]['profession'],
                        style: const TextStyle(color: Colors.white),
                      ),
                      Text(
                        '${dataList[index]['age']}',
                        style: const TextStyle(color: Colors.white),
                      ),
                    ],
                  ),
                  dotIconColor: SSColor.secondary,
                ),
              ),
              const SizedBox(height: 20),
              const StylishStepper(
                dotIconColor: Colors.amber,
                verticalLineLeftPadding: 2,
                verticalLineIconHeight: 100,
                assetIcon: 'assets/images/line2.png',
                gap: 0,
                content: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      'My Name is Pradeep Tharu',
                      style: TextStyle(color: Colors.white),
                    ),
                    Text(
                      'My Name is Pradeep Tharu',
                      style: TextStyle(color: Colors.white),
                    ),
                    Text(
                      'My Name is Pradeep Tharu',
                      style: TextStyle(color: Colors.white),
                    ),
                    Text(
                      'My Name is Pradeep Tharu',
                      style: TextStyle(color: Colors.white),
                    ),
                  ],
                ),
                header: Text('How Are You'),
              ),
              const SizedBox(height: 20),
              const StylishStepper(
                dotIconColor: Colors.green,
                verticalLineLeftPadding: 5,
                verticalLineIconHeight: 150,
                gap: 0,
                content: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      'My Name is Pradeep Tharu',
                      style: TextStyle(color: Colors.white),
                    ),
                    Text(
                      'My Name is Pradeep Tharu',
                      style: TextStyle(color: Colors.white),
                    ),
                    Text(
                      'My Name is Pradeep Tharu',
                      style: TextStyle(color: Colors.white),
                    ),
                    Text(
                      'My Name is Pradeep Tharu',
                      style: TextStyle(color: Colors.white),
                    ),
                  ],
                ),
                header: Text('How Are You'),
              ),
              const SizedBox(height: 20),
              const StylishStepper(
                svgIcon: SStepperIcons.dot,
                dotIconColor: SSColor.secondary,
                verticalLineLeftPadding: 5,
                verticalLineIconHeight: 500,
                gap: 0,
                content: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      'My Name is Pradeep Tharu',
                      style: TextStyle(color: Colors.white),
                    ),
                    Text(
                      'My Name is Pradeep Tharu',
                      style: TextStyle(color: Colors.white),
                    ),
                    Text(
                      'My Name is Pradeep Tharu',
                      style: TextStyle(color: Colors.white),
                    ),
                    Text(
                      'My Name is Pradeep Tharu',
                      style: TextStyle(color: Colors.white),
                    ),
                  ],
                ),
                header: Text('How Are You'),
              )
            ],
          ),
        ),
      ),
    );
  }
}

List<Map<String, dynamic>> dataList = [
  {"id": 1, "name": "John", "age": 30, "profession": "Software Engineer"},
  {"id": 2, "name": "Alice", "age": 25, "profession": "Doctor"},
  {"id": 3, "name": "Bob", "age": 35, "profession": "Teacher"},
  {"id": 4, "name": "Emily", "age": 28, "profession": "Graphic Designer"},
  {"id": 5, "name": "Michael", "age": 40, "profession": "Marketing Manager"},
];

更多关于Flutter步进器插件stylish_stepper的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html

1 回复

更多关于Flutter步进器插件stylish_stepper的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html


当然,下面是一个关于如何在Flutter项目中使用stylish_stepper插件的示例代码。stylish_stepper是一个用于创建步进器(Stepper)的Flutter插件,它提供了更加美观和灵活的步进器组件。

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

dependencies:
  flutter:
    sdk: flutter
  stylish_stepper: ^latest_version  # 请替换为最新的版本号

然后运行flutter pub get来安装依赖。

接下来是一个简单的使用示例:

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Stylish Stepper Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin {
  final List<Step> steps = [
    Step(
      title: Text('Step 1: Introduction'),
      content: Text('This is the first step of the process.'),
      isActive: true,
    ),
    Step(
      title: Text('Step 2: Personal Info'),
      content: Column(
        children: <Widget>[
          TextField(
            decoration: InputDecoration(labelText: 'Name'),
          ),
          TextField(
            decoration: InputDecoration(labelText: 'Email'),
          ),
        ],
      ),
      isActive: true,
    ),
    Step(
      title: Text('Step 3: Confirmation'),
      content: Text('You have successfully completed the form.'),
      isActive: false,
    ),
  ];

  int currentStep = 0;

  void _nextStep() {
    setState(() {
      if (currentStep < steps.length - 1) {
        currentStep++;
      }
    });
  }

  void _prevStep() {
    setState(() {
      if (currentStep > 0) {
        currentStep--;
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Stylish Stepper Demo'),
      ),
      body: StylishStepper(
        steps: steps,
        currentStep: currentStep,
        onStepTapped: (int index) {
          setState(() {
            currentStep = index;
          });
        },
        onStepContinue: _nextStep,
        onStepCancel: _prevStep,
        type: StylishStepperType.horizontal, // or StylishStepperType.vertical
        stepContinueBtn: Text('Next'),
        stepCancelBtn: Text('Back'),
        doneBtn: Text('Done'),
        doneBtnColor: Colors.blue,
        stepContinueBtnColor: Colors.blue,
        stepCancelBtnColor: Colors.grey,
      ),
    );
  }
}

在这个示例中:

  1. 我们创建了一个包含三个步骤的List<Step>
  2. currentStep变量用于跟踪当前活动的步骤。
  3. _nextStep_prevStep函数用于在步骤之间导航。
  4. StylishStepper组件被用来显示步骤,并且我们配置了一些参数,比如步骤类型(水平或垂直)、按钮文本和颜色等。

这个示例展示了如何使用stylish_stepper插件创建一个简单的步进器。你可以根据需要自定义步骤的内容和样式。

回到顶部