123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- import 'dart:ui';
- import 'package:flutter/material.dart';
- import 'package:sport/widgets/misc.dart';
- class PrimaryButton extends StatelessWidget {
- final VoidCallback? callback;
- final String content;
- final double width;
- final double height;
- final double? fontSize;
- final Widget? child;
- final bool shadow;
- final bool bold;
- final Color? buttonColor;
- final Key? key;
- PrimaryButton({
- required this.callback,
- required this.content,
- this.child,
- this.width = double.infinity,
- this.height = 35,
- this.fontSize,
- this.shadow = true,
- this.bold = false,
- this.buttonColor, this.key,
- });
- @override
- Widget build(BuildContext context) {
- final height = this.height;
- return Container(
- width: width,
- height: height,
- decoration: callback == null
- ? BoxDecoration(
- color: Color(0xffdcdcdc),
- shape: BoxShape.rectangle,
- borderRadius: BorderRadius.all(Radius.circular(height / 2)),
- )
- : shadow
- ? BoxDecoration(
- shape: BoxShape.rectangle,
- borderRadius: BorderRadius.all(Radius.circular(height / 2)),
- boxShadow: [BoxShadow(offset: Offset(0.0, 3), blurRadius: 3, spreadRadius: 0, color: Color(0x82FF9100))],
- gradient: LinearGradient(
- begin: Alignment.topCenter,
- end: Alignment.bottomCenter,
- colors: <Color>[Color(0xffFFC400), Color(0xffFFAA00)],
- ),
- )
- : buttonColor != null
- ? BoxDecoration(
- color: buttonColor,
- shape: BoxShape.rectangle,
- borderRadius: BorderRadius.all(Radius.circular(height / 2)),
- )
- : BoxDecoration(
- shape: BoxShape.rectangle,
- borderRadius: BorderRadius.all(Radius.circular(height / 2)),
- gradient: LinearGradient(
- begin: Alignment.topCenter,
- end: Alignment.bottomCenter,
- colors: <Color>[Color(0xffFFC400), Color(0xffFFAA00)],
- ),
- ),
- child: ElevatedButton(
- onPressed: () {
- this.callback?.call();
- },
- child: content.isNotEmpty == true
- ? Text(
- content,
- style: Theme.of(context).textTheme.subtitle1!.copyWith(
- color: Colors.white,
- fontSize: fontSize != null
- ? fontSize
- : height >= 40
- ? callback == null
- ? 14.0
- : 16.0
- : 14.0,
- fontWeight: bold ? FontWeight.w600 : FontWeight.normal,),
- )
- : child,
- style: ButtonStyle(
- padding: MaterialStateProperty.all(EdgeInsets.zero),
- elevation: MaterialStateProperty.all(0),
- shape: MaterialStateProperty.all(StadiumBorder()),
- backgroundColor: MaterialStateProperty.all(Colors.transparent),
- ),
- ));
- }
- }
- class MainButton extends StatelessWidget {
- final VoidCallback callback;
- final String content;
- final double width;
- final double height;
- final double? fontSize;
- final Widget? child;
- final bool shadow;
- final bool bold;
- final Color? buttonColor;
- final Color? textColor;
- final String type; // cancel or confirm
- MainButton({
- required this.callback,
- required this.content,
- required this.type,
- this.child,
- this.width = double.infinity,
- this.height = 44,
- this.fontSize,
- this.shadow = true,
- this.bold = false,
- this.buttonColor,
- this.textColor,
- });
- @override
- Widget build(BuildContext context) {
- BoxDecoration cancelDecoration = BoxDecoration(
- color: buttonColor,
- shape: BoxShape.rectangle,
- borderRadius: BorderRadius.all(Radius.circular(height / 2)),
- boxShadow: [BoxShadow(offset: Offset(0.0, 3), blurRadius: 3, spreadRadius: 0, color: Color(0xffF1F1F1))],
- gradient: LinearGradient(
- begin: Alignment.topCenter,
- end: Alignment.bottomCenter,
- colors: <Color>[Color(0xffF0F0F0), Color(0xffF6F6F6)],
- ),
- );
- BoxDecoration confirmDecoration = BoxDecoration(
- color: buttonColor,
- shape: BoxShape.rectangle,
- borderRadius: BorderRadius.all(Radius.circular(height / 2)),
- boxShadow: buttonColor == null ? [BoxShadow(offset: Offset(0.0, 3), blurRadius: 3, spreadRadius: 0, color: Color(0x82FF9100))] : null,
- gradient: buttonColor == null
- ? LinearGradient(
- begin: Alignment.topCenter,
- end: Alignment.bottomCenter,
- colors: <Color>[Color(0xffFFC400), Color(0xffFFAA00)],
- )
- : null,
- );
- var map = {
- "cancel": cancelDecoration,
- "confirm": confirmDecoration,
- };
- return InkWell(
- onTap: callback,
- borderRadius: BorderRadius.all(Radius.circular(height / 2)),
- child: Container(
- width: width,
- height: height,
- alignment: Alignment.center,
- decoration: map['$type'],
- child: content.isNotEmpty == true
- ? Text(
- content,
- style: Theme.of(context).textTheme.subtitle1!.copyWith(
- color: textColor != null ? textColor : Colors.white,
- fontSize: fontSize != null
- ? fontSize
- : height >= 40
- ? callback == null
- ? 14.0
- : 16.0
- : 14.0,
- fontWeight: bold ? FontWeight.w600 : FontWeight.normal,
- height: 1.1),
- )
- : child,
- ),
- );
- }
- }
|