flutter_lock_widget 0.1.4

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 51

Flutter 手势密码

Flutter 手势密码 Widget。

效果

使用

  • pubspec.yaml 中添加以下依赖
dependencies:
  flutter_lock_widget: '^0.1.1'
  • 安装
flutter packages get

在 VS Code 下会自动安装

  • 在文件中导入
import 'package:flutter_lock_widget/lock_container.dart';
import 'package:flutter_lock_widget/circle.dart';

说明

circle.dart

该文件中主要包括手势密码的基本控件及样子属性设置

  • class CircleAttribute:用于设置手势密码的整体样式;
  • class Circle:九宫格中圆的数据结构;
  • enum CircleState:圆的状态,分普通状态和选中状态;
  • enum LockState:手势密码整体的状态,分普通状态和出错状态;

circle_painter.dart

  • class CirclePainter:绘制圆

lock_widget.dart

  • class LockWidget:手势密码区域 Widget。在此类中检测手势操作,并绘制手势路线;

lock_container.dart

  • class LockContainer:手势密码容器,可以根据需要修改;目前只包含一个提示文本和手势密码;

示例

详细示例可以查看 example 目录下的工程,以下是 set.dart 的代码

import 'package:flutter/material.dart';

import 'package:flutter_lock_widget/lock_container.dart';
import 'package:flutter_lock_widget/circle.dart';

import './confirm.dart';

class LockSetPage extends StatefulWidget {

  @override
  State<StatefulWidget> createState() {
    return _LockSetPageState();
  }
}

class _LockSetPageState extends State<LockSetPage> {

  LockState _lockState = LockState.normal;

  GlobalKey<ScaffoldState> scaffoldState = GlobalKey<ScaffoldState>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('设置手势密码'),
      ),
      body: Column(
        children: <Widget>[
          LayoutBuilder(
            builder: (BuildContext context, BoxConstraints constraints) {
              return Container(
                // color: Colors.red,
                margin: const EdgeInsets.only(top: 100.0),
                child: LockContainer(
                  initMessage: '请设置手势密码',
                  errorMessage: '手势密码最少 4 位',
                  completeCallback: _checkPassword,
                ),
              );
            },
          )
        ],
      ),
    );
  }

  bool _checkPassword(String password) {

    if (password.length < 4) {
      return false;
    }

    Navigator.push(context, MaterialPageRoute(
      builder: (context) => LockConfirmPage(password: password,)
    ));

    return true;
  }
}

参考

flutter_gesture_password

[0.0.1] - TODO: Add release date.

  • TODO: Describe initial release.

example/lib/main.dart

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

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or press Run > Flutter Hot Reload in IntelliJ). Notice that the
        // counter didn't reset back to zero; the application is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: LockSetPage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return new Scaffold(
      appBar: new AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: new Text(widget.title),
      ),
      body: new Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: new Column(
          // Column is also layout widget. It takes a list of children and
          // arranges them vertically. By default, it sizes itself to fit its
          // children horizontally, and tries to be as tall as its parent.
          //
          // Invoke "debug paint" (press "p" in the console where you ran
          // "flutter run", or select "Toggle Debug Paint" from the Flutter tool
          // window in IntelliJ) to see the wireframe for each widget.
          //
          // Column has various properties to control how it sizes itself and
          // how it positions its children. Here we use mainAxisAlignment to
          // center the children vertically; the main axis here is the vertical
          // axis because Columns are vertical (the cross axis would be
          // horizontal).
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            new Text(
              'You have pushed the button this many times:',
            ),
            new Text(
              '$_counter',
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: new FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: new Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_lock_widget: ^0.1.4

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_lock_widget/circle.dart';
import 'package:flutter_lock_widget/circle_painter.dart';
import 'package:flutter_lock_widget/lock_container.dart';
import 'package:flutter_lock_widget/lock_widget.dart';
  
Version Uploaded Documentation Archive
0.1.4 Sep 12, 2018 Go to the documentation of flutter_lock_widget 0.1.4 Download flutter_lock_widget 0.1.4 archive
0.1.3 Aug 16, 2018 Go to the documentation of flutter_lock_widget 0.1.3 Download flutter_lock_widget 0.1.3 archive
0.1.2 Aug 2, 2018 Go to the documentation of flutter_lock_widget 0.1.2 Download flutter_lock_widget 0.1.2 archive
0.1.1 Jul 27, 2018 Go to the documentation of flutter_lock_widget 0.1.1 Download flutter_lock_widget 0.1.1 archive
0.1.0 Jul 27, 2018 Go to the documentation of flutter_lock_widget 0.1.0 Download flutter_lock_widget 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
10
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
51
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7
  • Flutter: 1.0.0

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/lock_container.dart. (-0.50 points)

Analysis of lib/lock_container.dart reported 1 hint:

line 27 col 9: The value of the field '_messageColor' isn't used.

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test