parent
2f4c29535f
commit
65f7a9c914
@ -0,0 +1,47 @@
|
||||
import 'package:ansu_ui/ansu_ui.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ansu_ui/ansu_ui.dart';
|
||||
|
||||
class ExampleExtension extends StatefulWidget {
|
||||
ExampleExtension({Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_ExampleExtensionState createState() => _ExampleExtensionState();
|
||||
}
|
||||
|
||||
class _ExampleExtensionState extends State<ExampleExtension> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ASScaffold(
|
||||
title: 'Extension',
|
||||
body: ListView(
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text('.phone'),
|
||||
trailing: Text('17855823545 => ${'17855823545'.phone}'),
|
||||
),
|
||||
ListTile(
|
||||
title: Text('.comma'),
|
||||
trailing: Text('1000 => ${1000.comma}'),
|
||||
),
|
||||
ListTile(
|
||||
title: Text('.comma'),
|
||||
trailing: Text('1000000 => ${1000000.comma}'),
|
||||
),
|
||||
ListTile(
|
||||
title: Text('.comma'),
|
||||
trailing: Text('100.00 => ${100.00.comma}'),
|
||||
),
|
||||
ListTile(
|
||||
title: Text('.comma'),
|
||||
trailing: Text('0.123456 => ${0.123456.comma}'),
|
||||
),
|
||||
ListTile(
|
||||
title: Text('.comma'),
|
||||
trailing: Text('123456.789 => ${123456.789.comma}'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
import 'package:ansu_ui/ansu_ui.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
|
||||
extension NumExt on num {
|
||||
///获取宽 SizedBox
|
||||
Widget get wb => SizedBox(width: this.w);
|
||||
|
||||
///获取高 SizedBox
|
||||
Widget get hb => SizedBox(height: this.w);
|
||||
|
||||
///圆角
|
||||
BorderRadius get radius => BorderRadius.circular(this.w);
|
||||
|
||||
///每三位数加逗号
|
||||
String get comma {
|
||||
String _num = this.toString();
|
||||
String str = '';
|
||||
int count = 0;
|
||||
if (_num.indexOf('.') == -1) {
|
||||
for (var i = _num.length - 1; i >= 0; i--) {
|
||||
if (count % 3 == 0 && count != 0) {
|
||||
str = _num.substring(i, i + 1) + ',' + str;
|
||||
} else {
|
||||
str = _num.substring(i, i + 1) + str;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
return str;
|
||||
} else {
|
||||
for (var i = _num.indexOf('.') - 1; i >= 0; i--) {
|
||||
if (count % 3 == 0 && count!= 0) {
|
||||
str = _num.substring(i, i + 1) + ',' + str;
|
||||
} else {
|
||||
str = _num.substring(i, i + 1) + str;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
str=str+(_num.substring(_num.indexOf('.'),_num.length));
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
import 'package:ansu_ui/ansu_ui.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
|
||||
extension NumExt on num {
|
||||
///获取宽 SizedBox
|
||||
Widget get wb => SizedBox(width: this.w);
|
||||
|
||||
///获取高 SizedBox
|
||||
Widget get hb => SizedBox(height: this.w);
|
||||
|
||||
///圆角
|
||||
BorderRadius get radius => BorderRadius.circular(this.w);
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
extension PhoneExt on String {
|
||||
String get phone {
|
||||
///电话号码加分隔线
|
||||
return (this.substring(0, 3) +
|
||||
'-' +
|
||||
this.substring(3, 7) +
|
||||
'-' +
|
||||
this.substring(7, 11));
|
||||
}
|
||||
}
|
Loading…
Reference in new issue