license_plate_number 1.1.0 copy "license_plate_number: ^1.1.0" to clipboard
license_plate_number: ^1.1.0 copied to clipboard

outdated

Flutter widget for inputting license plate number. Build-in one light style and one dark style, and the style can be changed.

example/lib/main.dart

import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:license_plate_number/license_plate_number.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  Brightness _brightness = Brightness.light;
  PlateStyles _plateStyles = PlateStyles.light;
  final KeyboardController _keyboardController = KeyboardController();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'License plate number Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
        brightness: _brightness,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: Text('License plate number'),
          actions: [
            /// AppBar 弹出菜单
            PopupMenuButton(
              itemBuilder: (context) => [
                PopupMenuItem(child: Text('dark'), value: 'dark'),
                PopupMenuItem(child: Text('light'), value: 'light'),
              ],
              onSelected: (action) {
                switch (action) {

                  /// 切换成黑暗主题
                  case 'dark':
                    _plateStyles = PlateStyles.dark;
                    _brightness = Brightness.dark;
                    break;

                  /// 切换成明亮主题
                  case 'light':
                    _plateStyles = PlateStyles.light;
                    _brightness = Brightness.light;
                    break;
                }
                setState(() {});
              },
            ),
          ],
        ),
        body: GestureDetector(
          behavior: HitTestBehavior.translucent,
          child: MyHomePage(
            plateStyles: _plateStyles,
            keyboardController: _keyboardController,
          ),
          onTap: () {
            /// 点击键盘外区域收起键盘
            _keyboardController.hideKeyboard();
          },
        ),
      ),
    );
  }
}

class MyHomePage extends StatelessWidget {
  MyHomePage({
    this.plateStyles,
    this.keyboardController,
  });

  final PlateStyles plateStyles;
  final KeyboardController keyboardController;

  @override
  Widget build(BuildContext context) {
    MediaQueryData mediaQuery = MediaQuery.of(context);
    double screenWidth = mediaQuery.size.width;
    double screenHeight = mediaQuery.size.height;
    double inputFieldWidth = min(screenWidth, screenHeight) / 10;
    double inputFieldHeight = inputFieldWidth * 4 / 3;
    if (screenWidth < screenHeight) {
      SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.top, SystemUiOverlay.bottom]);
    } else {
      SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);
    }
    return Container(
      alignment: Alignment.topCenter,
      padding: EdgeInsets.only(top: 30),

      /// 车牌号输入框
      child: PlateInputField(
        styles: plateStyles,
        inputFieldWidth: inputFieldWidth,
        inputFieldHeight: inputFieldHeight,
        keyboardController: keyboardController,
        plateSeparatorPadding: 8,
        plateSeparatorSize: 6,
        onChanged: (List<String> array, String value) {
          debugPrint(array.toString());
          debugPrint(value);
        },
      ),
    );
  }
}
11
likes
40
pub points
70%
popularity

Publisher

unverified uploader

Flutter widget for inputting license plate number. Build-in one light style and one dark style, and the style can be changed.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

dotted_border, flutter

More

Packages that depend on license_plate_number