Skip to content

Commit

Permalink
TolyInput
Browse files Browse the repository at this point in the history
  • Loading branch information
toly1994328 committed Aug 26, 2024
1 parent 28bfe76 commit e639a05
Show file tree
Hide file tree
Showing 21 changed files with 918 additions and 253 deletions.
3 changes: 0 additions & 3 deletions lib/navigation/menu/form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ Map<String, dynamic> get formMenus => {
'label': 'Input',
'subtitle': '输入框',
'tag': '新',
'isFlutter': true,

// 'icon': Icons.text_fields,
},
{
'path': '/select',
Expand Down
30 changes: 5 additions & 25 deletions lib/view/widgets/form/input/input_demo1.dart
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',
));
}
}
44 changes: 8 additions & 36 deletions lib/view/widgets/form/input/input_demo2.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:toly_ui/view/widgets/display_nodes/display_nodes.dart';
import 'package:tolyui/tolyui.dart';

@DisplayNode(
title: '禁用输入',
Expand All @@ -10,41 +11,12 @@ class InputDemo2 extends StatelessWidget {

@override
Widget build(BuildContext context) {
double height = 32;
TextStyle style = TextStyle(fontSize: 14, height: 1);
double borderWidth = 1;
Color focusedColor = Colors.blue;
Color unFocusedColor = Color(0xffd9d9d9);
OutlineInputBorder focusedBorder =
OutlineInputBorder(borderSide: BorderSide(color: focusedColor, width: borderWidth));
OutlineInputBorder border =
OutlineInputBorder(borderSide: BorderSide(color: unFocusedColor, width: borderWidth));
bool enable = false;

Widget child = TextField(
enabled: enable,
cursorHeight: style.fontSize,
cursorWidth: 1,
style: style,
decoration: InputDecoration(
hintText: 'please input',
focusedBorder: focusedBorder,
isDense: true,
enabledBorder: border,
hoverColor: focusedColor,
border: border,
),
);

if (!enable) {
child = MouseRegion(
cursor: SystemMouseCursors.forbidden,
child: IgnorePointer(child: child),
);
}
return SizedBox(
width: 250,
child: child,
);
return SizedBox(
width: 250,
child: const TolyInput(
enable: false,
hintText: '用户名/手机号/匠心ID',
),
);
}
}
106 changes: 43 additions & 63 deletions lib/view/widgets/form/input/input_demo3.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:toly_ui/view/widgets/display_nodes/display_nodes.dart';
import 'package:tolyui/tolyui.dart';

@DisplayNode(
title: '组合输入框',
Expand All @@ -10,69 +12,47 @@ class InputDemo3 extends StatelessWidget {

@override
Widget build(BuildContext context) {
double height = 32;
TextStyle style = const TextStyle(fontSize: 14, height: 1);
double borderWidth = 1;
Color focusedColor = Colors.blue;
Color unFocusedColor = const Color(0xffd9d9d9);
OutlineInputBorder focusedBorder = OutlineInputBorder(
borderRadius: const BorderRadius.only(
topRight: Radius.circular(4),
bottomRight: Radius.circular(4),
),
borderSide: BorderSide(color: focusedColor, width: borderWidth));
OutlineInputBorder border = OutlineInputBorder(
borderRadius: const BorderRadius.only(
bottomRight: Radius.circular(4),
topRight: Radius.circular(4),
),
borderSide: BorderSide(color: unFocusedColor, width: borderWidth));
return Row(
mainAxisSize: MainAxisSize.min,
children: [
Container(
height: 32,
// width: 70,
padding: const EdgeInsets.symmetric(horizontal: 12),

child: const Center(
child: Text(
'Http://',
style: TextStyle(color: Color(0xff909399), fontSize: 14),
)),
decoration: BoxDecoration(
color: const Color(0xfff5f7fa),
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(4),
bottomLeft: Radius.circular(4),
),
border: Border(
top: BorderSide(color: unFocusedColor),
left: BorderSide(color: unFocusedColor),
bottom: BorderSide(color: unFocusedColor),
// right: BorderSide(),
return SizedBox(
width: 300,
child: Wrap(
spacing: 8,
runSpacing: 8,
// direction: Axis.vertical,
children: [
TolyInput(
hintText: '用户名/手机号/匠心ID',
leadingBuilder: SlotBuilder(
builder: (_, __) =>
const Text('https://', style: TextStyle(color: Color(0xff1e1e1e))),
)),
),
SizedBox(
width: 250,
child: TextField(
cursorHeight: style.fontSize,
cursorWidth: 1,
style: style,
decoration: InputDecoration(
// isDense: true,
hintText: 'Please Input',
hintStyle: style.copyWith(color: unFocusedColor),
constraints: BoxConstraints.tight(Size(0, height)),
// contentPadding: EdgeInsets.only(top: 8),
contentPadding: const EdgeInsets.only(top: 0, right: 12, left: 12),
focusedBorder: focusedBorder,
enabledBorder: border,
hoverColor: focusedColor,
border: border,
),
)),
],
);
TolyInput(
hintText: 'Server Host',
leadingBuilder: SlotBuilder(
builder: (_, __) => const Text('https://', style: TextStyle(color: Color(0xff1e1e1e))),
),
tailingBuilder: SlotBuilder(
builder: (_, __) => const Text('.com', style: TextStyle(color: Color(0xff1e1e1e))),
),
),
TolyInput(
hintText: '选择文件夹',
tailingBuilder: SlotBuilder(
onTap: () => $message.success(message: 'Click Open Finder'),
builder: (_, __) => const Icon(CupertinoIcons.folder, size: 18),
),
),
TolyInput(
hintText: '选择文件夹',
tailingBuilder: SlotBuilder(
onTap: () => $message.success(message: 'Click Open Finder'),
builder: (_, hover) {
Color? color = hover ? Colors.blue : null;
return Icon(CupertinoIcons.folder, size: 18, color: color);
},
),
),
],
),
);;
}
}
8 changes: 8 additions & 0 deletions modules/tolyui/lib/form/form.dart
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';
81 changes: 81 additions & 0 deletions modules/tolyui/lib/form/input/attributes/attributes.dart
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);
// }
32 changes: 32 additions & 0 deletions modules/tolyui/lib/form/input/attributes/input_style.dart
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;
}
1 change: 1 addition & 0 deletions modules/tolyui/lib/form/input/num_change_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import 'package:flutter/material.dart';

import 'attributes/attributes.dart';
import 'toly_input.dart';

class NumChangeHandler extends StatefulWidget {
Expand Down
28 changes: 28 additions & 0 deletions modules/tolyui/lib/form/input/slot/button_slot.dart
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,
);
}
}
Loading

0 comments on commit e639a05

Please sign in to comment.