forked from TolyFx/toly_ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
28bfe76
commit e639a05
Showing
21 changed files
with
918 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,20 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:toly_ui/view/widgets/display_nodes/display_nodes.dart'; | ||
import 'package:tolyui/tolyui.dart'; | ||
|
||
@DisplayNode( | ||
title: '基础用法', | ||
desc: '通过 Flutter 内置的 TextField 组件展示输入框。', | ||
desc: '通过 TolyInput 展示最基本输入框样式。', | ||
) | ||
class InputDemo1 extends StatelessWidget { | ||
const InputDemo1({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
double height = 32; | ||
TextStyle style = const TextStyle(fontSize: 14, height: 1); | ||
double width = 1; | ||
Color focusedColor = Colors.blue; | ||
Color unFocusedColor = const Color(0xffd9d9d9); | ||
OutlineInputBorder focusedBorder = | ||
OutlineInputBorder(borderSide: BorderSide(color: focusedColor, width: width)); | ||
OutlineInputBorder border = | ||
OutlineInputBorder(borderSide: BorderSide(color: unFocusedColor, width: width)); | ||
|
||
return SizedBox( | ||
return const SizedBox( | ||
width: 250, | ||
child: TextField( | ||
cursorHeight: style.fontSize, | ||
cursorWidth: 1, | ||
style: style, | ||
decoration: InputDecoration( | ||
hintText: 'please input', | ||
hintStyle: style.copyWith(color: unFocusedColor), | ||
isDense: true, | ||
focusedBorder: focusedBorder, | ||
enabledBorder: border, | ||
hoverColor: focusedColor, | ||
border: border, | ||
), | ||
child: TolyInput( | ||
hintText: '用户名/手机号/匠心ID', | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
export 'input/toly_input_area.dart'; | ||
export 'select/toly_select.dart'; | ||
|
||
export 'input/toly_input.dart'; | ||
export 'input/attributes/attributes.dart'; | ||
export 'input/attributes/input_style.dart'; | ||
export 'input/slot/button_slot.dart'; | ||
export 'input/slot/number_slot.dart'; | ||
export 'input/slot/slot_decoration.dart'; | ||
export 'input/slot/option_slot_decoration.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
sealed class DisplaySize { | ||
final BoxConstraints constraints; | ||
|
||
const DisplaySize(this.constraints); | ||
|
||
@override | ||
bool operator ==(Object other) => | ||
identical(this, other) || | ||
other is DisplaySize && runtimeType == other.runtimeType && constraints == other.constraints; | ||
|
||
@override | ||
int get hashCode => constraints.hashCode; | ||
} | ||
|
||
class DefaultSize extends DisplaySize { | ||
const DefaultSize() : super(const BoxConstraints.tightFor(height: 32)); | ||
} | ||
|
||
class SmallSize extends DisplaySize { | ||
const SmallSize() : super(const BoxConstraints.tightFor(height: 24)); | ||
} | ||
|
||
class LargeSize extends DisplaySize { | ||
const LargeSize() : super(const BoxConstraints.tightFor(height: 40)); | ||
} | ||
|
||
class CustomSize extends DisplaySize { | ||
const CustomSize(super.constraints); | ||
|
||
CustomSize.height(double height) : super(BoxConstraints.tightFor(height: height)); | ||
} | ||
|
||
sealed class InputType {} | ||
|
||
class NumberInput extends InputType { | ||
final num step; | ||
final num min; | ||
final num? max; | ||
final num? errorDefault; | ||
|
||
NumberInput({ | ||
this.step = 1, | ||
this.min = 0, | ||
this.max, | ||
this.errorDefault = 0, | ||
}); | ||
|
||
String plus(String value) { | ||
num count = num.tryParse(value) ?? errorDefault ?? 0; | ||
return (count + step).clamp(min, max ?? 99999999).toString(); | ||
} | ||
|
||
String minus(String value) { | ||
num count = num.tryParse(value) ?? errorDefault ?? 0; | ||
return (count - step).clamp(min, max ?? 99999999).toString(); | ||
} | ||
} | ||
// | ||
// abstract interface class Slot{ | ||
// Widget build(BuildContext context); | ||
// } | ||
// | ||
// class BuilderSlot implements Slot{ | ||
// final WidgetBuilder builder; | ||
// | ||
// BuilderSlot(this.builder); | ||
// | ||
// @override | ||
// Widget build(BuildContext context) { | ||
// return builder(context); | ||
// } | ||
// } | ||
|
||
|
||
// class ClearAble{ | ||
// final IconData icon; | ||
// | ||
// ClearAble(this.icon); | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'dart:ui'; | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
import 'attributes.dart'; | ||
|
||
class TolyInputStyle { | ||
final Color? hoverColor; | ||
final DisplaySize inputSize; | ||
final Radius radius; | ||
final InputDecoration? decoration; | ||
|
||
TolyInputStyle({ | ||
this.hoverColor, | ||
this.decoration = const InputDecoration(), | ||
this.radius = const Radius.circular(4), | ||
this.inputSize = const DefaultSize(), | ||
}); | ||
|
||
bool get enableHoverBorder => hoverColor != null; | ||
|
||
@override | ||
bool operator ==(Object other) => | ||
identical(this, other) || | ||
other is TolyInputStyle && | ||
runtimeType == other.runtimeType && | ||
hoverColor == other.hoverColor && | ||
inputSize == other.inputSize; | ||
|
||
@override | ||
int get hashCode => hoverColor.hashCode ^ inputSize.hashCode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'slot.dart'; | ||
|
||
class ButtonSlot extends Slot { | ||
final Widget child; | ||
|
||
ButtonSlot({ | ||
required this.child, | ||
super.onTap, | ||
super.padding = const EdgeInsets.symmetric(horizontal: 8), | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context, SlotMeta meta) { | ||
return ElevatedButton( | ||
style: ElevatedButton.styleFrom( | ||
backgroundColor: Colors.blue, | ||
foregroundColor: Colors.white, | ||
elevation: 0, | ||
padding: padding, | ||
shadowColor: Colors.transparent, | ||
minimumSize: Size(32, meta.height), | ||
shape: RoundedRectangleBorder(borderRadius: meta.borderRadius)), | ||
onPressed: onTap, | ||
child: child, | ||
); | ||
} | ||
} |
Oops, something went wrong.