From 10ccc8d97bb0d488fefe7df301e25ce866362f94 Mon Sep 17 00:00:00 2001 From: Pawan Kumar Date: Mon, 13 Apr 2020 21:04:52 +0530 Subject: [PATCH] v0.3.2 ready --- CHANGELOG.md | 9 ++++ example/lib/main.dart | 9 ++++ example/pubspec.lock | 6 +-- lib/src/flutter/drop_down_button.dart | 66 +++++++++++++------------ lib/src/flutter/random.dart | 58 ++++++++++++++++++++++ lib/src/flutter/widgets.dart | 8 ++- lib/src/velocity_x_extensions.dart | 1 + lib/src/velocity_xx.dart | 52 +++++++++++++++++++ lib/velocity_x.dart | 1 + pubspec.lock | 6 +-- pubspec.yaml | 2 +- test/flutter/drop_down_button_test.dart | 9 ++-- 12 files changed, 184 insertions(+), 43 deletions(-) create mode 100644 lib/src/flutter/random.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b752a2..f1109f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## [0.3.2] - April 13, 2020 + +- Added VxTextDropDown Widget with textDropDown() ext. +- Added VxRandomBox Widget with randomBox() ext. +- Added Vx.log(), Vx.inspect() utilities. +- Added Vx.isReleaseMode, Vx.isProfileMode, Vx.isDebugMode, Vx.isWeb utilities.. +- Example App updated. +- Bug Fixes + ## [0.3.1] - April 10, 2020 - Added VxSwiper Widget with swiper() ext. diff --git a/example/lib/main.dart b/example/lib/main.dart index b787cf6..3b63f9a 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -12,6 +12,7 @@ void main() => runApp(MaterialApp( class Demo extends StatelessWidget { @override Widget build(BuildContext context) { + Vx.inspect("message"); return Scaffold( appBar: VxAppBar( searchBar: true, @@ -81,6 +82,14 @@ class Demo extends StatelessWidget { ["Decimal Item 1", "Decimal Item 2"], primary: false, ), + ["Item 1", "Item 2", "Item 3"] + .textDropDown( + selectedValue: "Item 1", + onChanged: (value) { + Vx.log(value); + }, + ) + .make(), ]).p16().scrollVertical(), ); } diff --git a/example/pubspec.lock b/example/pubspec.lock index e269f94..69e2aa8 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -108,7 +108,7 @@ packages: name: petitparser url: "https://pub.dartlang.org" source: hosted - version: "3.0.2" + version: "2.4.0" quiver: dependency: transitive description: @@ -190,6 +190,6 @@ packages: name: xml url: "https://pub.dartlang.org" source: hosted - version: "3.7.0" + version: "3.6.1" sdks: - dart: ">=2.7.0 <3.0.0" + dart: ">=2.6.0 <3.0.0" diff --git a/lib/src/flutter/drop_down_button.dart b/lib/src/flutter/drop_down_button.dart index ce63c82..8b0a43f 100644 --- a/lib/src/flutter/drop_down_button.dart +++ b/lib/src/flutter/drop_down_button.dart @@ -11,23 +11,25 @@ * limitations under the License. */ +import 'package:flutter/material.dart'; import 'package:velocity_x/src/flutter/builder.dart'; import 'package:velocity_x/src/velocity_x_extensions.dart'; -import 'package:flutter/material.dart'; -class VxDropDownButton extends VxWidgetBuilder { - VxDropDownButton( +class VxTextDropDown extends VxWidgetBuilder { + VxTextDropDown( this._items, { - @required this.valueHolder, - }) : assert(valueHolder != null); + @required this.selectedValue, + @required this.onChanged, + }) : assert(selectedValue != null), + assert(onChanged != null); /// The List used to create [DropdownMenuItem]. /// /// _items can't be null. final List _items; - /// The value used to define currently selected value of [VxDropDownButton]. - String valueHolder; + /// The value used to define currently selected value of [VxTextDropDown]. + String selectedValue; /// Defines the [TextStyle] for [DropdownMenuItem]. /// @@ -35,7 +37,7 @@ class VxDropDownButton extends VxWidgetBuilder { /// value of the current [ThemeData.textTheme]. TextStyle _textStyle; - /// Defines the widget used to draw underline for [VxDropDownButton] + /// Defines the widget used to draw underline for [VxTextDropDown] Widget _underLine; /// Defines the elevation for menu when drop down is open. @@ -43,12 +45,12 @@ class VxDropDownButton extends VxWidgetBuilder { /// By default, the value of `_elevation` is 8. int _elevation; - /// Defines the size of [VxDropDownButton] icon. + /// Defines the size of [VxTextDropDown] icon. /// /// By default, the value of `_iconSize` is 24. double _iconSize; - /// The [Icon] used for [VxDropDownButton]. + /// The [Icon] used for [VxTextDropDown]. /// /// By default, the icon is [Icons.arrow_drop_down] Icon _dropDownIcon; @@ -67,7 +69,7 @@ class VxDropDownButton extends VxWidgetBuilder { /// The color for the button's Material when it has the input focus. Color _focusColor; - /// If the `_autoFocus` is true, [VxDropDownButton] will be selected as the initial focus when no other node + /// If the `_autoFocus` is true, [VxTextDropDown] will be selected as the initial focus when no other node /// in its scope is currently focused. bool _autoFocus = false; @@ -80,35 +82,34 @@ class VxDropDownButton extends VxWidgetBuilder { bool _isDense = false; /// Called when user selects a value from drop down menu. - ValueChanged _onValueChange; - + ValueChanged onChanged; - VxDropDownButton textStyle(TextStyle style) => this.._textStyle = style; + VxTextDropDown textStyle(TextStyle style) => this.._textStyle = style; - VxDropDownButton underLine(Widget widget) => this.._underLine = widget; + VxTextDropDown underLine(Widget widget) => this.._underLine = widget; - VxDropDownButton elevation(int val) => this.._elevation = val; + VxTextDropDown elevation(int val) => this.._elevation = val; - VxDropDownButton iconSize(double val) => this.._iconSize = val; + VxTextDropDown iconSize(double val) => this.._iconSize = val; - VxDropDownButton icon(Icon _icon) => this.._dropDownIcon = _icon; + VxTextDropDown icon(Icon _icon) => this.._dropDownIcon = _icon; - VxDropDownButton disabledIconColor(Color color) => + VxTextDropDown disabledIconColor(Color color) => this.._disabledIconColor = color; - VxDropDownButton enabledIconColor(Color color) => + VxTextDropDown enabledIconColor(Color color) => this.._enabledIconColor = color; - VxDropDownButton get autoFocus => this.._autoFocus = true; + VxTextDropDown get autoFocus => this.._autoFocus = true; - VxDropDownButton get isExpanded => this.._isExpanded = true; + VxTextDropDown get isExpanded => this.._isExpanded = true; - VxDropDownButton get isDense => this.._isDense = true; + VxTextDropDown get isDense => this.._isDense = true; - VxDropDownButton focusColor(Color color) => this.._focusColor = color; + VxTextDropDown focusColor(Color color) => this.._focusColor = color; - VxDropDownButton onChange(ValueChanged function) => - this.._onValueChange = function; +// VxTextDropDown onChange(ValueChanged function) => +// this..onChanged = function; @override StatefulBuilder make({Key key}) { @@ -116,7 +117,7 @@ class VxDropDownButton extends VxWidgetBuilder { builder: (BuildContext context, StateSetter setState) { return DropdownButton( key: key, - value: valueHolder, + value: selectedValue, style: _textStyle, underline: _underLine, iconEnabledColor: _enabledIconColor, @@ -136,9 +137,9 @@ class VxDropDownButton extends VxWidgetBuilder { .toList(), onChanged: (String value) { setState(() { - valueHolder = value; + selectedValue = value; }); - _onValueChange(value); + onChanged(value); }, ); }, @@ -147,6 +148,9 @@ class VxDropDownButton extends VxWidgetBuilder { } extension DropDownExtension on List { - VxDropDownButton dropDown({@required String value}) => - VxDropDownButton(this, valueHolder: value); + /// The [value] should be a part of the list of strings. + VxTextDropDown textDropDown( + {@required String selectedValue, + @required ValueChanged onChanged}) => + VxTextDropDown(this, selectedValue: selectedValue, onChanged: onChanged); } diff --git a/lib/src/flutter/random.dart b/lib/src/flutter/random.dart new file mode 100644 index 0000000..df4085a --- /dev/null +++ b/lib/src/flutter/random.dart @@ -0,0 +1,58 @@ +import 'dart:math'; + +import 'package:flutter/material.dart'; + +mixin _RandomColor { + static final Random _random = Random(); + + /// Returns a random color. + static Color next() { + return Color(0xFF000000 + _random.nextInt(0x00FFFFFF)); + } +} + +/// A Container Widget that takes up a given [width] and [height] and paints itself with a +/// random color. +class VxRandomBox extends StatefulWidget { + final double width; + final double height; + final Widget child; + final bool changeOnRedraw; + + const VxRandomBox( + {this.width, this.height, this.child, this.changeOnRedraw = true}); + + @override + _VxRandomBoxState createState() => _VxRandomBoxState(); +} + +class _VxRandomBoxState extends State { + Color _randomColor; + + @override + void initState() { + super.initState(); + _randomColor = _RandomColor.next(); + } + + @override + Widget build(BuildContext context) { + return Container( + width: widget.width, + height: widget.height, + color: widget.changeOnRedraw == true ? _RandomColor.next() : _randomColor, + child: widget.child, + ); + } +} + +extension RandomContainerWidgetExtension on Widget { + VxRandomBox randomBox( + {double width, double height, bool changeOnRedraw = true}) => + VxRandomBox( + child: this, + height: height, + width: width, + changeOnRedraw: changeOnRedraw, + ); +} diff --git a/lib/src/flutter/widgets.dart b/lib/src/flutter/widgets.dart index bb407d9..df1f3d5 100644 --- a/lib/src/flutter/widgets.dart +++ b/lib/src/flutter/widgets.dart @@ -38,8 +38,9 @@ extension WidgetsExtension on Widget { child: this, ); - ///Hide a widget - Widget hide({Key key, bool isVisible = false, bool maintainSize = false}) => Visibility( + ///Hides a widget + Widget hide({Key key, bool isVisible = false, bool maintainSize = false}) => + Visibility( key: key, child: this, visible: isVisible, @@ -47,4 +48,7 @@ extension WidgetsExtension on Widget { maintainAnimation: maintainSize, maintainState: maintainSize, ); + + /// Widget to show exception + Widget errorWidget(Object ex) => ErrorWidget(ex); } diff --git a/lib/src/velocity_x_extensions.dart b/lib/src/velocity_x_extensions.dart index 4d2ae31..a142654 100644 --- a/lib/src/velocity_x_extensions.dart +++ b/lib/src/velocity_x_extensions.dart @@ -11,6 +11,7 @@ * limitations under the License. */ +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:velocity_x/src/flutter/selectable_text.dart'; diff --git a/lib/src/velocity_xx.dart b/lib/src/velocity_xx.dart index 89b931e..ebddbcd 100644 --- a/lib/src/velocity_xx.dart +++ b/lib/src/velocity_xx.dart @@ -11,6 +11,10 @@ * limitations under the License. */ +import 'dart:async'; +import 'dart:developer' as dev; + +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; mixin Vx { @@ -299,6 +303,54 @@ mixin Vx { static ShapeBorder withRounded(double radius) => RoundedRectangleBorder(borderRadius: BorderRadius.circular(radius)); + // Emit a log event. + /// + /// This function was designed to map closely to the logging information + /// collected by `package:logging`. + /// + /// - [message] is the log message + /// - [time] (optional) is the timestamp + /// - [sequenceNumber] (optional) is a monotonically increasing sequence number + /// - [level] (optional) is the severity level (a value between 0 and 2000); see + /// the `package:logging` `Level` class for an overview of the possible values + /// - [name] (optional) is the name of the source of the log message + /// - [zone] (optional) the zone where the log was emitted + /// - [error] (optional) an error object associated with this log event + /// - [stackTrace] (optional) a stack trace associated with this log event + static void log(String message, + {DateTime time, + int sequenceNumber, + int level = 0, + String name = '', + Zone zone, + Object error, + StackTrace stackTrace}) => + dev.log(message, + error: error, + level: level, + name: name, + sequenceNumber: sequenceNumber, + stackTrace: stackTrace, + time: time, + zone: zone); + + /// Send a reference to [object] to any attached debuggers. + /// + /// Debuggers may open an inspector on the object. Returns the argument. + static void inspect(Object object) => dev.inspect(object); + + ///Checks whether release mode or not + bool get isReleaseMode => kReleaseMode; + + ///Checks whether debug mode or not + bool get isDebugMode => kDebugMode; + + ///Checks whether profile mode or not + bool get isProfileMode => kProfileMode; + + ///Checks whether profile mode or not + bool get isWeb => kIsWeb; + /// Get color from the hex value static Color hexToColor(String code) { return Color(int.parse(code.substring(1, 7), radix: 16) + 0xFF000000); diff --git a/lib/velocity_x.dart b/lib/velocity_x.dart index ec1b1a1..bb891e4 100644 --- a/lib/velocity_x.dart +++ b/lib/velocity_x.dart @@ -18,6 +18,7 @@ export 'src/flutter/list.dart'; export 'src/flutter/object.dart'; export 'src/flutter/opacity.dart'; export 'src/flutter/padding.dart'; +export 'src/flutter/random.dart'; export 'src/flutter/rich_text.dart'; export 'src/flutter/scroll.dart'; export 'src/flutter/selectable_text.dart'; diff --git a/pubspec.lock b/pubspec.lock index 8a5adbc..4e676e8 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -108,7 +108,7 @@ packages: name: petitparser url: "https://pub.dartlang.org" source: hosted - version: "3.0.2" + version: "2.4.0" quiver: dependency: transitive description: @@ -183,6 +183,6 @@ packages: name: xml url: "https://pub.dartlang.org" source: hosted - version: "3.7.0" + version: "3.6.1" sdks: - dart: ">=2.7.0 <3.0.0" + dart: ">=2.6.0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 838afbd..6d20c88 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: velocity_x description: A minimalist Flutter framework for rapidly building custom designs. -version: 0.3.1 +version: 0.3.2 homepage: https://velocityx.dev repository: https://github.com/iampawan/VelocityX diff --git a/test/flutter/drop_down_button_test.dart b/test/flutter/drop_down_button_test.dart index 578c0e9..ccbb945 100644 --- a/test/flutter/drop_down_button_test.dart +++ b/test/flutter/drop_down_button_test.dart @@ -16,7 +16,6 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:velocity_x/velocity_x.dart'; void main() { - testWidgets('user is able to select value from drop down', (WidgetTester tester) async { String _value = 'HEY'; @@ -25,8 +24,12 @@ void main() { child: MaterialApp( home: Material( child: ['HELLO', 'HEY', 'HOLA'] - .dropDown(value: _value) - .onChange((value) => _value = value) + .textDropDown( + selectedValue: _value, + onChanged: (value) { + _value = value; + }, + ) .make() .centered(), ),