Skip to content

Commit

Permalink
v0.3.2 ready
Browse files Browse the repository at this point in the history
  • Loading branch information
iampawan committed Apr 13, 2020
1 parent c058a91 commit 10ccc8d
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 43 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
9 changes: 9 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
);
}
Expand Down
6 changes: 3 additions & 3 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
66 changes: 35 additions & 31 deletions lib/src/flutter/drop_down_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,46 @@
* 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<StatefulBuilder> {
VxDropDownButton(
class VxTextDropDown extends VxWidgetBuilder<StatefulBuilder> {
VxTextDropDown(
this._items, {
@required this.valueHolder,
}) : assert(valueHolder != null);
@required this.selectedValue,
@required this.onChanged,
}) : assert(selectedValue != null),
assert(onChanged != null);

/// The List<String> used to create [DropdownMenuItem].
///
/// _items can't be null.
final List<String> _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].
///
/// By default the value of `_textStyle` is [TextTheme.subhead]
/// 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.
///
/// 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;
Expand All @@ -67,7 +69,7 @@ class VxDropDownButton extends VxWidgetBuilder<StatefulBuilder> {
/// 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;

Expand All @@ -80,43 +82,42 @@ class VxDropDownButton extends VxWidgetBuilder<StatefulBuilder> {
bool _isDense = false;

/// Called when user selects a value from drop down menu.
ValueChanged<String> _onValueChange;

ValueChanged<String> 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<String> function) =>
this.._onValueChange = function;
// VxTextDropDown onChange(ValueChanged<String> function) =>
// this..onChanged = function;

@override
StatefulBuilder make({Key key}) {
return StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return DropdownButton<String>(
key: key,
value: valueHolder,
value: selectedValue,
style: _textStyle,
underline: _underLine,
iconEnabledColor: _enabledIconColor,
Expand All @@ -136,9 +137,9 @@ class VxDropDownButton extends VxWidgetBuilder<StatefulBuilder> {
.toList(),
onChanged: (String value) {
setState(() {
valueHolder = value;
selectedValue = value;
});
_onValueChange(value);
onChanged(value);
},
);
},
Expand All @@ -147,6 +148,9 @@ class VxDropDownButton extends VxWidgetBuilder<StatefulBuilder> {
}

extension DropDownExtension on List<String> {
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<String> onChanged}) =>
VxTextDropDown(this, selectedValue: selectedValue, onChanged: onChanged);
}
58 changes: 58 additions & 0 deletions lib/src/flutter/random.dart
Original file line number Diff line number Diff line change
@@ -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<VxRandomBox> {
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,
);
}
8 changes: 6 additions & 2 deletions lib/src/flutter/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ 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,
maintainSize: maintainSize,
maintainAnimation: maintainSize,
maintainState: maintainSize,
);

/// Widget to show exception
Widget errorWidget(Object ex) => ErrorWidget(ex);
}
1 change: 1 addition & 0 deletions lib/src/velocity_x_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
52 changes: 52 additions & 0 deletions lib/src/velocity_xx.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions lib/velocity_x.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
6 changes: 3 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Loading

0 comments on commit 10ccc8d

Please sign in to comment.