提交 b97f8a4f authored 作者: shixiaochen's avatar shixiaochen

1、1.0.0版本

上级 48bf9b5f
......@@ -131,7 +131,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.3"
version: "1.0.0"
flutter_cupertino_datetime_picker:
dependency: transitive
description:
......@@ -183,7 +183,7 @@ packages:
name: get
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.6.1"
version: "4.6.5"
http:
dependency: transitive
description:
......
import 'package:flutter/widgets.dart';
/// 扩展函数 Iterable
extension IterableExt<E> on Iterable<E> {
// 获取元素
E? getElement(int? index) {
if (index == null || index >= length || index < 0) {
return null;
}
int elementIndex = 0;
for (E element in this) {
if (index == elementIndex) return element;
elementIndex++;
}
return null;
}
Iterable<T> mapIndexed<T>(T Function(E e, int i) f) {
var i = 0;
return map((e) => f(e, i++));
}
}
/// 扩展函数 GlobalKey
extension GlobalKeyExt on GlobalKey {
// 获取 widget size
Size get getSize {
final RenderBox? widget = currentContext?.findRenderObject() as RenderBox?;
return widget?.size ?? Size.zero;
}
// 获取 widget offset
Offset get getOffset {
final RenderBox? widget = currentContext?.findRenderObject() as RenderBox?;
return widget?.localToGlobal(Offset.zero) ?? Offset.zero;
}
}
extension DateTimeExt on DateTime {}
extension StringExt on String? {
bool isNullOrEmpty() {
return this == null || this!.isEmpty;
}
}
extension DoubleExt on num? {
String format({nullText = "-"}) {
double num;
try {
num = double.parse(toString());
} catch (e) {
print("转换异常:$e");
return nullText;
}
if ((num.toString().length - num.toString().lastIndexOf(".") - 1) < 2) {
//小数点后有几位小数
return num.toStringAsFixed(2)
.substring(0, num.toString().lastIndexOf(".") + 2 + 1)
.toString();
} else {
return num.toString()
.substring(0, num.toString().lastIndexOf(".") + 2 + 1)
.toString();
}
}
}
import 'package:flutter/material.dart';
/// 水平间隔
const Widget hGap2 = SizedBox(width: 2.0);
const Widget hGap4 = SizedBox(width: 4.0);
const Widget hGap5 = SizedBox(width: 5.0);
const Widget hGap8 = SizedBox(width: 8.0);
const Widget hGap10 = SizedBox(width: 10.0);
const Widget hGap12 = SizedBox(width: 12.0);
const Widget hGap14 = SizedBox(width: 14.0);
const Widget hGap15 = SizedBox(width: 15.0);
const Widget hGap16 = SizedBox(width: 16.0);
const Widget hGap20 = SizedBox(width: 20.0);
const Widget hGap32 = SizedBox(width: 32.0);
const Widget hGap40 = SizedBox(width: 40.0);
const Widget hGap50 = SizedBox(width: 50.0);
const Widget hGap60 = SizedBox(width: 60.0);
const Widget hGap65 = SizedBox(width: 65.0);
const Widget hGap110 = SizedBox(width: 110.0);
/// 垂直间隔
const Widget vGap1 = SizedBox(height: 1.0);
const Widget vGap2 = SizedBox(height: 2.0);
const Widget vGap3 = SizedBox(height: 3.0);
const Widget vGap4 = SizedBox(height: 4.0);
const Widget vGap5 = SizedBox(height: 5.0);
const Widget vGap8 = SizedBox(height: 8.0);
const Widget vGap10 = SizedBox(height: 10.0);
const Widget vGap12 = SizedBox(height: 12.0);
const Widget vGap15 = SizedBox(height: 15.0);
const Widget vGap16 = SizedBox(height: 16.0);
const Widget vGap20 = SizedBox(height: 20.0);
const Widget vGap24 = SizedBox(height: 24.0);
const Widget vGap25 = SizedBox(height: 25.0);
const Widget vGap30 = SizedBox(height: 30.0);
const Widget vGap32 = SizedBox(height: 32.0);
const Widget vGap50 = SizedBox(height: 50.0);
const Widget vGap60 = SizedBox(height: 60.0);
const Widget vGap70 = SizedBox(height: 70.0);
const Widget vGap80 = SizedBox(height: 80.0);
const Widget vGap150 = SizedBox(height: 150.0);
const Widget line = Divider();
const Widget vLine = SizedBox(
width: 0.6,
height: 24.0,
child: VerticalDivider(),
);
const Widget empty = SizedBox.shrink();
import 'dart:async';
library flutter_clx_base;
import 'package:flutter/services.dart';
export 'common/extension.dart';
export 'common/gaps.dart';
export 'common/gaps.dart';
export 'widget/my_app_bar.dart';
export 'widget/my_scaffold.dart';
export 'widget/my_scroll_view.dart';
class FlutterClxBase {
static const MethodChannel _channel = MethodChannel('flutter_clx_base');
static Future<String?> get platformVersion async {
final String? version = await _channel.invokeMethod('getPlatformVersion');
return version;
}
}
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class MyPageAppBar extends StatelessWidget implements PreferredSizeWidget {
final String? title;
final Color? backgroundColor;
final bool showBack;
final bool primary;
final Function()? onBack;
final List<Widget>? actions;
final bool exitApp;
const MyPageAppBar({
Key? key,
this.title,
this.backgroundColor = const Color(0xFF25A1FE),
this.showBack = true,
this.primary = true,
this.onBack,
this.actions,
this.exitApp = false,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return AppBar(
key: key,
centerTitle: true,
title: Text(title ?? ""),
backgroundColor: backgroundColor,
primary: primary,
leading: showBack
? InkWell(
onTap: onBack ??
() {
if (exitApp) {
SystemNavigator.pop();
} else {
Navigator.pop(context);
}
},
child: const Icon(
Icons.arrow_back_ios,
color: Colors.white,
),
)
: null,
actions: actions,
);
}
@override
Size get preferredSize => const Size(double.infinity, 55.0);
}
import 'package:flutter/material.dart';
import 'package:keyboard_actions/keyboard_actions.dart';
import 'my_app_bar.dart';
import 'my_scroll_view.dart';
class MyScaffold extends StatelessWidget {
final PreferredSizeWidget? appBar;
final Color? backgroundColor;
final Widget? body;
final List<Widget>? children;
final EdgeInsetsGeometry? padding;
final String title;
final Widget? bottomButton;
final CrossAxisAlignment crossAxisAlignment;
final KeyboardActionsConfig? keyboardConfig;
const MyScaffold({
Key? key,
this.appBar,
this.backgroundColor,
this.children,
this.title = "",
this.padding,
this.body,
this.bottomButton,
this.crossAxisAlignment = CrossAxisAlignment.start,
this.keyboardConfig,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: appBar ?? MyPageAppBar(title: title),
backgroundColor: backgroundColor ?? const Color(0xFFf2f3f3),
body: body ??
MyScrollView(
children: children,
padding: padding,
bottomButton: bottomButton,
crossAxisAlignment: crossAxisAlignment,
keyboardConfig: keyboardConfig,
),
);
}
}
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:keyboard_actions/keyboard_actions.dart';
/// 本项目通用的布局(SingleChildScrollView)
/// 1.底部存在按钮
/// 2.底部没有按钮
class MyScrollView extends StatelessWidget {
/// 注意:同时存在底部按钮与keyboardConfig配置时,为保证软键盘弹出高度正常。需要在`Scaffold`使用 `resizeToAvoidBottomInset: defaultTargetPlatform != TargetPlatform.iOS,`
/// 除非Android与iOS平台均使用keyboard_actions
const MyScrollView({
Key? key,
required this.children,
this.padding,
this.physics = const BouncingScrollPhysics(),
this.crossAxisAlignment = CrossAxisAlignment.start,
this.bottomButton,
this.keyboardConfig,
this.tapOutsideToDismiss = false,
this.overScroll = 16.0,
}) : super(key: key);
final List<Widget>? children;
final EdgeInsetsGeometry? padding;
final ScrollPhysics physics;
final CrossAxisAlignment crossAxisAlignment;
final Widget? bottomButton;
final KeyboardActionsConfig? keyboardConfig;
/// 键盘外部按下将其关闭
final bool tapOutsideToDismiss;
/// 默认弹起位置在TextField的文字下面,可以添加此属性继续向上滑动一段距离。用来露出完整的TextField。
final double overScroll;
@override
Widget build(BuildContext context) {
Widget contents = Column(
crossAxisAlignment: crossAxisAlignment,
children: children!,
);
if (defaultTargetPlatform == TargetPlatform.iOS && keyboardConfig != null) {
/// iOS 键盘处理
if (padding != null) {
contents = Padding(padding: padding!, child: contents);
}
contents = KeyboardActions(
isDialog: bottomButton != null,
overscroll: overScroll,
config: keyboardConfig!,
tapOutsideBehavior: TapOutsideBehavior.opaqueDismiss,
child: contents);
} else {
contents = SingleChildScrollView(
padding: padding,
physics: physics,
child: contents,
);
if (keyboardConfig != null) {
contents = KeyboardActions(
config: keyboardConfig!,
tapOutsideBehavior: TapOutsideBehavior.opaqueDismiss,
child: contents);
}
}
if (bottomButton != null) {
contents = Column(
children: <Widget>[
Expanded(child: contents),
SafeArea(child: bottomButton!)
],
);
}
return contents;
}
}
name: flutter_clx_base
description: A new base library
version: 0.0.3
version: 1.0.0
homepage:
environment:
......@@ -9,29 +9,33 @@ environment:
dependencies:
flutter:
sdk: flutter
# dio https://pub.dev/packages/dio
dio: 4.0.6
# 时间选择器 https://pub.dev/packages/flutter_cupertino_datetime_picker
flutter_cupertino_datetime_picker: 3.0.0
# 键盘工具类 https://pub.dev/packages/keyboard_actions
keyboard_actions: ^3.4.7
# Flutter常用工具类库 https://pub.dev/packages/flustars
flustars: ^2.0.1
# sp https://pub.dev/packages/sp_util
sp_util: ^2.0.3
get: 4.6.1
# get https://pub.dev/packages/get
get: 4.6.5
# 日志打印 https://pub.dev/packages/logger
logger: ^1.1.0
# toast https://pub.dev/packages/fluttertoast
fluttertoast: ^8.0.9
# webview https://pub.dev/packages/webview_flutter
webview_flutter: ^3.0.2
# 包信息 https://pub.dev/packages/package_info_plus
package_info_plus: 1.4.2
# 权限 https://pub.dev/packages/permission_handler
permission_handler: 9.2.0
# https://pub.dev/packages/url_launcher
url_launcher: 6.1.2
# loading https://pub.dev/packages/flutter_easyloading
flutter_easyloading: 3.0.5
# https://pub.dev/packages/auto_size_text
auto_size_text: 3.0.0
......
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_clx_base/flutter_clx_base.dart';
void main() {
const MethodChannel channel = MethodChannel('flutter_clx_base');
TestWidgetsFlutterBinding.ensureInitialized();
setUp(() {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
return '42';
});
});
tearDown(() {
channel.setMockMethodCallHandler(null);
});
void main() {
test('getPlatformVersion', () async {
expect(await FlutterClxBase.platformVersion, '42');
});
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论