Code Monkey home page Code Monkey logo

flutter_extensions's People

Contributors

brex900 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

flutter_extensions's Issues

Add KeyboardRemover

class KeyboardRemover extends StatefulWidget {
  final Widget child;

  const KeyboardRemover({Key key, @required this.child}) : super(key: key);

  @override
  _KeyboardRemoverState createState() => _KeyboardRemoverState();
}

class _KeyboardRemoverState extends State<KeyboardRemover> {
  FocusNode _focusPuller;

  final _focusNode = FocusNode();

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    _focusPuller = Focus.of(context);
  }

  void _requestFocus() {
    if (_focusNode.hasFocus) return;
    _focusPuller.requestFocus(_focusNode);
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: _requestFocus,
      child: widget.child,
    );
  }
}

Add InkStack

class InkStack extends StatelessWidget {
  final VoidCallback onTap;
  final List<Widget> background;
  final List<Widget> foreground;

  const InkStack({
    Key key,
    this.onTap,
    this.background = const <Widget>[],
    this.foreground = const <Widget>[],
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        ...background,
        Positioned.fill(
          child: Material(
            color: Colors.transparent,
            child: InkWell(
              onTap: onTap,
            ),
          ),
        ),
        ...foreground,
      ],
    );
  }
}

Add SizeFlutterExtensions

extension SizeFlutterExtensions on Size {
  Size copyWith({double width, double height}) {
    return Size(width ?? this.width, height ?? this.height);
  }
}

Add ButtonStyleBuilder

class ButtonStyleBuilder {
  /// [ButtonStyle.textStyle]
  final TextStyle textStyle;

  /// [ButtonStyle.backgroundColor]
  final Color backgroundColor;

  /// [ButtonStyle.foregroundColor]
  final Color foregroundColor;

  /// [ButtonStyle.overlayColor]
  final Color overlayColor;

  /// [ButtonStyle.shadowColor]
  final Color shadowColor;

  /// [ButtonStyle.elevation]
  final double elevation;

  /// [ButtonStyle.padding]
  final EdgeInsetsGeometry padding;

  /// [ButtonStyle.minimumSize]
  final Size minimumSize;

  /// [ButtonStyle.side]
  final BorderSide side;

  /// [ButtonStyle.shape]
  final OutlinedBorder shape;

  /// [ButtonStyle.mouseCursor]
  final MouseCursor mouseCursor;

  /// [ButtonStyle.visualDensity]
  final VisualDensity visualDensity;

  /// [ButtonStyle.tapTargetSize]
  final MaterialTapTargetSize tapTargetSize;

  /// [ButtonStyle.animationDuration]
  final Duration animationDuration;

  /// [ButtonStyle.enableFeedback]
  final bool enableFeedback;

  const ButtonStyleBuilder({
    this.textStyle,
    this.backgroundColor,
    this.foregroundColor,
    this.overlayColor,
    this.shadowColor,
    this.elevation,
    this.padding,
    this.minimumSize,
    this.side,
    this.shape,
    this.mouseCursor,
    this.visualDensity,
    this.tapTargetSize,
    this.animationDuration,
    this.enableFeedback,
  });

  ButtonStyleBuilder copyWith({
    TextStyle textStyle,
    Color backgroundColor,
    Color foregroundColor,
    Color overlayColor,
    Color shadowColor,
    double elevation,
    EdgeInsetsGeometry padding,
    Size minimumSize,
    BorderSide side,
    OutlinedBorder shape,
    MouseCursor mouseCursor,
    VisualDensity visualDensity,
    MaterialTapTargetSize tapTargetSize,
    Duration animationDuration,
    bool enableFeedback,
  }) {
    return new ButtonStyleBuilder(
      textStyle: textStyle ?? this.textStyle,
      backgroundColor: backgroundColor ?? this.backgroundColor,
      foregroundColor: foregroundColor ?? this.foregroundColor,
      overlayColor: overlayColor ?? this.overlayColor,
      shadowColor: shadowColor ?? this.shadowColor,
      elevation: elevation ?? this.elevation,
      padding: padding ?? this.padding,
      minimumSize: minimumSize ?? this.minimumSize,
      side: side ?? this.side,
      shape: shape ?? this.shape,
      mouseCursor: mouseCursor ?? this.mouseCursor,
      visualDensity: visualDensity ?? this.visualDensity,
      tapTargetSize: tapTargetSize ?? this.tapTargetSize,
      animationDuration: animationDuration ?? this.animationDuration,
      enableFeedback: enableFeedback ?? this.enableFeedback,
    );
  }

  ButtonStyle build() {
    return ButtonStyle(
      textStyle: MaterialStateProperty.all(textStyle),
      backgroundColor: MaterialStateProperty.all(backgroundColor),
      foregroundColor: MaterialStateProperty.all(foregroundColor),
      overlayColor: MaterialStateProperty.all(overlayColor),
      shadowColor: MaterialStateProperty.all(shadowColor),
      elevation: MaterialStateProperty.all(elevation),
      padding: MaterialStateProperty.all(padding),
      minimumSize: MaterialStateProperty.all(minimumSize),
      side: MaterialStateProperty.all(side),
      shape: MaterialStateProperty.all(shape),
      mouseCursor: MaterialStateProperty.all(mouseCursor),
      visualDensity: visualDensity,
      tapTargetSize: tapTargetSize,
      animationDuration: animationDuration,
      enableFeedback: enableFeedback,
    );
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.