Skip to content

Commit

Permalink
Merge pull request #2 from KevinZhang19870314/dev
Browse files Browse the repository at this point in the history
Add more wired widgets.
  • Loading branch information
KevinZhang19870314 authored Jul 13, 2021
2 parents acf618d + 97abceb commit daa5497
Show file tree
Hide file tree
Showing 12 changed files with 407 additions and 9 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [0.1.3] - 2021-July-12.

* 1. Add wired widget `wired toggle`.
* 2. doc: add pub pkg, likes, release date and MIT to readme
* 3. Add wired widget `wired progress`.

## [0.1.2] - 2021-July-6.

* Add the dart doc comments.
Expand All @@ -8,5 +14,5 @@

## [0.1.0] - 2021-July-5.

* Initial release
* Support widgets for wired button, wired card, wired checkbox, wired combo, wired dialog, wired divider, wired input, wired radio, wired slider.
* 1. Initial release
* 2. Support widgets for `wired button`, `wired card`, `wired checkbox`, `wired combo`, `wired dialog`, `wired divider`, `wired input`, `wired radio`, `wired slider`.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[![Pub](https://img.shields.io/pub/v/wired_elements?label=wired_elements&color=blue)](https://pub.dev/packages/wired_elements)
[![likes](https://badges.bar/wired_elements/likes)](https://pub.dev/packages/wired_elements/score)
[![GitHub Release Date](https://img.shields.io/github/release-date/KevinZhang19870314/wired_elements)](https://pub.dev/packages/wired_elements)
[![GitHub](https://img.shields.io/github/license/KevinZhang19870314/wired_elements)](https://github.com/KevinZhang19870314/wired_elements/blob/main/LICENSE)

# wired_elements

Wired Elements is a series of basic UI Elements that have a hand drawn look. These can be used for wireframes, mockups, or just the fun hand-drawn look. It's the Flutter implementation of [wired-elements](https://github.com/rough-stuff/wired-elements). It's base on the library of [flutter_rough](https://github.com/sergiandreplace/flutter_rough).
Expand Down Expand Up @@ -28,4 +33,10 @@ Some screenshots of the example app:
<img src="https://raw.githubusercontent.com/KevinZhang19870314/wired_elements/main/example/assets/screenshots/wired_input.jpg" width="187" heght="333" />
<img src="https://raw.githubusercontent.com/KevinZhang19870314/wired_elements/main/example/assets/screenshots/wired_radio.jpg" width="187" heght="333" />
<img src="https://raw.githubusercontent.com/KevinZhang19870314/wired_elements/main/example/assets/screenshots/wired_slider.jpg" width="187" heght="333" />
</p>
</p>
## Others
[flutter_rough](https://github.com/sergiandreplace/flutter_rough) is an awesome library, but its not null safety, there is an [issue](https://github.com/sergiandreplace/flutter_rough/issues/5) linked to it, but with no response until now therefore I have to copy all of the code in project and do null safety myself. As long as the author of flutter_rough do the sound null safety, I will use this library as dependency instead of copying all the source code.
## And, the last, pr is welcome!
14 changes: 14 additions & 0 deletions example/lib/demos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import 'package:example/src/wired_divider_example.dart';
import 'package:flutter/material.dart';
import 'src/wired_button_example.dart';
import 'src/wired_input_example.dart';
import 'src/wired_progress_example.dart';
import 'src/wired_radio_example.dart';
import 'src/wired_slider_example.dart';
import 'src/wired_toggle_example.dart';

final String handWriting1 = 'Shadows Into Light';
final String handWriting2 = 'Architects Daughter';
Expand Down Expand Up @@ -67,6 +69,18 @@ final List<Demo> demos = [
(_) => WiredSliderExample(title: 'Wired slider'),
const Icon(Icons.linear_scale, size: 36),
),
NormalDemo(
'Wired toggle example',
'Wired toggle',
(_) => WiredToggleExample(title: 'Wired toggle'),
const Icon(Icons.toggle_on, size: 36),
),
NormalDemo(
'Wired progress example',
'Wired progress',
(_) => WiredProgressExample(title: 'Wired progress'),
const Icon(Icons.portrait, size: 36),
),
];

abstract class Demo {
Expand Down
81 changes: 81 additions & 0 deletions example/lib/src/wired_progress_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import 'package:flutter/material.dart';
import 'package:wired_elements/wired_elements.dart';

import 'wired_text.dart';

class WiredProgressExample extends StatefulWidget {
final String title;
const WiredProgressExample({Key? key, required this.title}) : super(key: key);

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

class _WiredProgressExampleState extends State<WiredProgressExample>
with TickerProviderStateMixin {
@override
Widget build(BuildContext context) {
final _controller1 = AnimationController(
duration: const Duration(milliseconds: 1000), vsync: this);
final _controller2 = AnimationController(
duration: const Duration(milliseconds: 1000), vsync: this);
return Scaffold(
appBar: AppBar(
title: WiredText(
'${widget.title}',
fontSize: 20.0,
),
),
body: Padding(
padding: EdgeInsets.symmetric(horizontal: 20.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
WiredProgress(controller: _controller1, value: 0.5),
SizedBox(height: 20.0),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
..._example(_controller1),
],
),
SizedBox(height: 50.0),
WiredProgress(controller: _controller2),
SizedBox(height: 20.0),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
..._example(_controller2),
],
),
],
),
),
);
}

List<Widget> _example(AnimationController controller) {
return [
WiredButton(
child: Text('Start'),
onPressed: () {
controller.forward();
},
),
SizedBox(width: 20.0),
WiredButton(
child: Text('Stop'),
onPressed: () {
controller.stop();
},
),
SizedBox(width: 20.0),
WiredButton(
child: Text('Reset'),
onPressed: () {
controller.reset();
},
),
];
}
}
51 changes: 51 additions & 0 deletions example/lib/src/wired_toggle_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import 'package:flutter/material.dart';
import 'package:wired_elements/wired_elements.dart';

import 'wired_text.dart';

class WiredToggleExample extends StatelessWidget {
final String title;
const WiredToggleExample({Key? key, required this.title}) : super(key: key);

@override
Widget build(BuildContext context) {
bool _firstVal = false;
bool _secondVal = true;

return Scaffold(
appBar: AppBar(
title: WiredText(
'$title',
fontSize: 20.0,
),
),
body: Container(
color: Colors.transparent,
padding: EdgeInsets.all(50.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
WiredToggle(
value: _firstVal,
onChange: (val) {
print(val);

return false;
},
),
SizedBox(height: 50.0),
WiredToggle(
value: _secondVal,
onChange: (val) {
print(val);

return true;
},
),
],
),
),
);
}
}
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.1.2"
version: "0.1.3"
sdks:
dart: ">=2.12.0 <3.0.0"
flutter: ">=1.17.0"
11 changes: 9 additions & 2 deletions lib/src/wired_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ class WiredRectangleBase extends WiredPainterBase {
/// The amount of empty space to the trailing edge of the rectangle.
final double rightIndent;

WiredRectangleBase({this.leftIndent = 0.0, this.rightIndent = 0.0});
final Color fillColor;

WiredRectangleBase({
this.leftIndent = 0.0,
this.rightIndent = 0.0,
this.fillColor = filledColor,
});

@override
void paintRough(
Expand All @@ -95,7 +101,8 @@ class WiredRectangleBase extends WiredPainterBase {
size.width - leftIndent - rightIndent,
size.height,
);
canvas.drawRough(figure, WiredBase.pathPaint, WiredBase.fillPaint);
canvas.drawRough(
figure, WiredBase.pathPaint, WiredBase.fillPainter(fillColor));
}
}

Expand Down
111 changes: 111 additions & 0 deletions lib/src/wired_progress.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import 'package:flutter/material.dart';
import 'package:wired_elements/rough/rough.dart';
import 'package:wired_elements/src/const.dart';

import 'canvas/wired_canvas.dart';
import 'wired_base.dart';

/// Wired progress
///
/// Usage:
/// ```dart
/// final _controller = AnimationController(
/// duration: const Duration(milliseconds: 1000), vsync: this);
/// ......
/// WiredProgress(controller: _controller, value: 0.5),
/// ......
/// _controller.forward();
/// _controller.stop();
/// _controller.reset();
/// ```
class WiredProgress extends StatefulWidget {
/// The current progress value, range is 0.0 ~ 1.0.
final double value;

final AnimationController controller;

const WiredProgress({
Key? key,
required this.controller,
this.value = 0.0,
}) : super(key: key);

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

class _WiredProgressState extends State<WiredProgress> with WiredRepaintMixin {
final double _progressHeight = 20.0;
double _width = 0.0;

late Animation<double> _animation;
late Tween<double> _tween;

@override
void initState() {
super.initState();

_tween = Tween<double>(begin: 0, end: 1);
_animation = _tween.animate(
CurvedAnimation(
parent: widget.controller,
curve: Curves.easeIn,
),
)..addListener(() {
setState(() {});
});

// Delay for calculate the width `_getWidth()` during the next frame
Future.delayed(Duration(milliseconds: 0), () {
_tween.begin = widget.value;
setState(() {});
});
}

@override
Widget build(BuildContext context) {
return buildWiredElement(child: _buildWidget());
}

Widget _buildWidget() {
_width = _getWidth();

return Stack(
children: [
SizedBox(
height: _progressHeight,
width: _width * _animation.value,
child: WiredCanvas(
painter: WiredRectangleBase(fillColor: borderColor),
fillerType: RoughFilter.HachureFiller,
fillerConfig: FillerConfig.build(hachureGap: 1.5),
),
),
SizedBox(
height: _progressHeight,
width: _width,
child: WiredCanvas(
painter: WiredRectangleBase(),
fillerType: RoughFilter.NoFiller,
),
),
LinearProgressIndicator(
backgroundColor: Colors.transparent,
minHeight: _progressHeight,
color: Colors.transparent,
value: _animation.value,
),
],
);
}

double _getWidth() {
double width = 0;
try {
var box = context.findRenderObject() as RenderBox;
width = box.size.width;
} catch (e) {}

return width;
}
}
4 changes: 2 additions & 2 deletions lib/src/wired_slider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class _WiredSliderState extends State<WiredSlider> {
),
),
Positioned(
left: _getSliderWidth() * _currentSliderValue / widget.max - 12,
left: _getWidth() * _currentSliderValue / widget.max - 12,
child: SizedBox(
height: 24.0,
width: 24.0,
Expand Down Expand Up @@ -153,7 +153,7 @@ class _WiredSliderState extends State<WiredSlider> {
);
}

double _getSliderWidth() {
double _getWidth() {
double width = 0;
try {
var box = context.findRenderObject() as RenderBox;
Expand Down
Loading

0 comments on commit daa5497

Please sign in to comment.