upgrade ext example

null_safety
小赖 4 years ago
parent fbeee06d4a
commit fee8376942

@ -0,0 +1,89 @@
import 'package:ansu_ui/ansu_ui.dart';
import 'package:flutter/material.dart';
class ExampleNumExt extends StatefulWidget {
ExampleNumExt({Key key}) : super(key: key);
@override
_ExampleNumExtState createState() => _ExampleNumExtState();
}
class _ExampleNumExtState extends State<ExampleNumExt> {
@override
Widget build(BuildContext context) {
return ASScaffold(
title: 'Num Ext',
body: ListView(
children: [
ListTile(title: Text('Comma')),
ListTile(
leading: Chip(label: Text('.comma')),
title: Text('1000'),
subtitle: Text(1000.comma()),
),
ListTile(
leading: Chip(label: Text('.comma')),
title: Text('1000000'),
subtitle: Text(1000000.comma()),
),
ListTile(
leading: Chip(label: Text('.comma')),
title: Text('100.00'),
subtitle: Text(100.00.comma()),
),
ListTile(
leading: Chip(label: Text('.comma')),
title: Text('0.123456'),
subtitle: Text(0.123456.comma()),
),
ListTile(
leading: Chip(label: Text('.comma')),
title: Text('123456.789'),
subtitle: Text(123456.789.comma()),
),
ListTile(
leading: Chip(label: Text('.comma')),
title: Text('123456.7899999'),
subtitle: Text(123456.7899999.comma(fixed: -1)),
trailing: Chip(label: Text('without Fixed')),
),
ListTile(title: Text('SizedBox')),
ListTile(
leading: Chip(label: Text('.wb')),
title: Text('Width Box'),
subtitle: Text('40.wb'),
trailing: Container(
height: 2.w,
width: 40.w,
color: Colors.red,
),
),
ListTile(
leading: Chip(label: Text('.hb')),
title: Text('Height Box'),
subtitle: Text('40.hb'),
trailing: Container(
height: 40.w,
width: 2.w,
color: Colors.red,
),
),
ListTile(title: Text('Radius')),
ListTile(
leading: Chip(label: Text('.radius')),
title: Text('Radius Gen'),
subtitle: Text('10.radius'),
trailing: Container(
height: 30.w,
width: 30.w,
decoration: BoxDecoration(
borderRadius: 10.radius,
color: Colors.pink,
),
),
),
],
),
);
}
}

@ -0,0 +1,27 @@
import 'package:ansu_ui/ansu_ui.dart';
import 'package:flutter/material.dart';
class ExampleStringExt extends StatefulWidget {
ExampleStringExt({Key key}) : super(key: key);
@override
_ExampleStringExtState createState() => _ExampleStringExtState();
}
class _ExampleStringExtState extends State<ExampleStringExt> {
@override
Widget build(BuildContext context) {
return ASScaffold(
title: 'String Ext',
body: ListView(
children: [
ListTile(
leading: Chip(label: Text('.phone')),
title: Text('18888888888'),
subtitle: Text('18888888888'.phone),
),
],
),
);
}
}

@ -1,47 +0,0 @@
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}'),
),
],
),
);
}
}

@ -1,4 +1,8 @@
import 'package:example/data/extension/example_num_ext.dart';
import 'package:example/data/extension/example_string_ext.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:ansu_ui/ansu_ui.dart';
import 'package:get/get.dart';
class MainExtention extends StatefulWidget { class MainExtention extends StatefulWidget {
MainExtention({Key key}) : super(key: key); MainExtention({Key key}) : super(key: key);
@ -8,8 +12,39 @@ class MainExtention extends StatefulWidget {
} }
class _MainExtentionState extends State<MainExtention> { class _MainExtentionState extends State<MainExtention> {
_innerButton({
VoidCallback onPressed,
Widget child,
Widget icon,
}) {
return TextButton(
onPressed: onPressed,
child: Row(
children: [
Expanded(child: icon),
child,
Spacer(),
],
),
);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ListView(); return ListView(
padding: EdgeInsets.all(16.w),
children: [
_innerButton(
onPressed: () => Get.to(ExampleNumExt()),
child: Text('Num Ext'),
icon: Icon(Icons.filter_9),
),
_innerButton(
onPressed: () => Get.to(ExampleStringExt()),
child: Text('String Ext'),
icon: Icon(Icons.text_fields),
),
],
);
} }
} }

@ -3,7 +3,6 @@ import 'package:example/example_bottom_button.dart';
import 'package:example/example_box.dart'; import 'package:example/example_box.dart';
import 'package:example/example_dialog.dart'; import 'package:example/example_dialog.dart';
import 'package:example/example_drawer.dart'; import 'package:example/example_drawer.dart';
import 'package:example/example_extension.dart';
import 'package:example/example_listtile.dart'; import 'package:example/example_listtile.dart';
import 'package:example/example_refresh.dart'; import 'package:example/example_refresh.dart';
import 'package:example/example_tag.dart'; import 'package:example/example_tag.dart';
@ -79,10 +78,6 @@ class _MainHomeState extends State<MainHome> {
title: '选框 Box', title: '选框 Box',
onPressed: () => Get.to(ExampleBox()), onPressed: () => Get.to(ExampleBox()),
), ),
ASButton.info(
title: '插件 Extension',
onPressed: () => Get.to(ExampleExtension()),
),
], ],
); );
} }

@ -13,8 +13,10 @@ extension NumExt on num {
BorderRadius get radius => BorderRadius.circular(this.w); BorderRadius get radius => BorderRadius.circular(this.w);
/// ///
String comma ({int fixed}){ String comma({int fixed = 2}) {
String _num = this.toStringAsFixed(fixed??2); bool notUseFixedFlag = fixed == -1;
String _num =
notUseFixedFlag ? this.toString() : this.toStringAsFixed(fixed);
String str = ''; String str = '';
int count = 0; int count = 0;
if (_num.indexOf('.') == -1) { if (_num.indexOf('.') == -1) {

Loading…
Cancel
Save