add ASRadioButton

null_safety
小赖 4 years ago
parent 7dac10c093
commit 4cc429d0f8

@ -10,6 +10,7 @@ class ExampleButton extends StatefulWidget {
} }
class _ExampleButtonState extends State<ExampleButton> { class _ExampleButtonState extends State<ExampleButton> {
int groupValue = 0;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ASScaffold( return ASScaffold(
@ -125,6 +126,37 @@ class _ExampleButtonState extends State<ExampleButton> {
onPressed: () {}, onPressed: () {},
), ),
), ),
ListTile(
title: Text('Radio Button'),
),
Wrap(
children: [
ASRadioButton(
groupValue: groupValue,
value: 0,
title: '候选0',
onTap: (_) => setState(() => groupValue = 0),
),
ASRadioButton(
groupValue: groupValue,
value: 1,
title: '候选1',
onTap: (_) => setState(() => groupValue = 1),
),
ASRadioButton(
groupValue: groupValue,
value: 2,
title: '候选2',
onTap: (_) => setState(() => groupValue = 2),
),
ASRadioButton(
groupValue: groupValue,
value: 3,
title: '候选3',
onTap: (_) => setState(() => groupValue = 3),
),
],
),
], ],
), ),
); );

@ -1,11 +1,15 @@
library ansu_ui; library ansu_ui;
//buttons
export 'buttons/as_button.dart'; export 'buttons/as_button.dart';
export 'buttons/as_longbutton.dart'; export 'buttons/as_longbutton.dart';
export 'buttons/as_back_button.dart'; export 'buttons/as_back_button.dart';
export 'buttons/as_numeric_button.dart'; export 'buttons/as_numeric_button.dart';
export 'buttons/as_bottom_button.dart'; export 'buttons/as_bottom_button.dart';
export 'buttons/as_gradientbutton.dart'; export 'buttons/as_gradientbutton.dart';
export 'buttons/as_radio_button.dart';
//scaffold
export 'scaffold/as_scaffold.dart'; export 'scaffold/as_scaffold.dart';
export 'styles/as_colors.dart'; export 'styles/as_colors.dart';

@ -0,0 +1,63 @@
import 'package:ansu_ui/styles/as_colors.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:ansu_ui/extension/num_extension.dart';
class ASRadioButton<T> extends StatefulWidget {
///
final T groupValue;
///
final String title;
///
final T value;
///
final Function(T value) onTap;
ASRadioButton({
Key key,
this.groupValue,
this.title,
this.value,
this.onTap,
}) : super(key: key);
@override
_ASRadioButtonState createState() => _ASRadioButtonState();
}
class _ASRadioButtonState extends State<ASRadioButton> {
bool get _selected => widget.value == widget.groupValue;
@override
Widget build(BuildContext context) {
return InkWell(
onTap: () => widget.onTap(widget.value),
borderRadius: 13.radius,
child: AnimatedContainer(
padding: EdgeInsets.symmetric(
horizontal: _selected ? 17.w : 16.w,
vertical: _selected ? 5.w : 4.w,
),
child: AnimatedDefaultTextStyle(
child: Text(widget.title),
style: TextStyle(
color: _selected ? kLightTextColor : kTextSubColor,
),
duration: Duration(milliseconds: 300),
),
duration: Duration(milliseconds: 300),
decoration: BoxDecoration(
color: _selected ? kPrimaryColor : Colors.transparent,
borderRadius: 13.radius,
border: _selected
? null
: Border.all(
width: 1.w,
color: Color(0xFF979797),
),
),
),
);
}
}
Loading…
Cancel
Save