123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:sport/widgets/button_cancel.dart';
- import 'package:sport/widgets/button_primary.dart';
- import 'package:sport/widgets/misc.dart';
- class CustomAlertDialog extends StatelessWidget {
- final String title;
- final Widget? child;
- final String textCancel;
- final String textOk;
- final Function ok;
- final bool addClose;
- final bool isLine;
- final ValueNotifier? onChanged;
- final bool cancelable;
- final Key? okKey;
- final Key? cancelKey;
- CustomAlertDialog({
- this.title = "",
- this.child,
- this.textCancel = "取消",
- this.textOk = "确定",
- required this.ok,
- this.addClose = false,
- this.isLine = false,
- this.onChanged,
- this.cancelable = true,
- this.okKey,
- this.cancelKey,
- });
- @override
- Widget build(BuildContext context) {
- var _width = MediaQuery.of(context).size.shortestSide * (child != null ? 0.70 : 0.66);
- return Material(
- type: MaterialType.transparency,
- child: Scaffold(
- backgroundColor: Colors.transparent,
- body: Center(
- child: Container(
- width: _width,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.all(Radius.circular(10.0)),
- color: Colors.white,
- ),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: <Widget>[
- if (addClose)
- Align(
- alignment: Alignment.topRight,
- child: IconButton(
- icon: Image.asset("lib/assets/img/btn_close_big.png"),
- onPressed: () => Navigator.pop(context, false),
- )),
- if (title.isNotEmpty == true)
- Stack(
- children: <Widget>[
- Padding(
- padding: EdgeInsets.fromLTRB(
- 0,
- child != null
- ? addClose
- ? 0
- : 16.0
- : 32.0,
- 0,
- isLine ? 15.0 : 20),
- child: Column(
- children: <Widget>[
- isLine
- ? Padding(
- child: Text(
- title,
- style: Theme.of(context).textTheme.headline3,
- ),
- padding: EdgeInsets.only(top: 5.0, bottom: 8.0, left: 16.0, right: 16.0),
- )
- : Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16.0),
- child: Text(
- title,
- style: Theme.of(context).textTheme.headline3,
- ),
- ),
- if (isLine)
- Divider(
- endIndent: 20.0,
- indent: 20.0,
- )
- ],
- ))
- ],
- ),
- //
- if (child != null)
- ConstrainedBox(
- constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height - 250),
- child: SingleChildScrollView(
- child: child,
- )),
- Padding(
- padding: const EdgeInsets.fromLTRB(16.0, 20.0, 16.0, 20.0),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- if (cancelable == true)
- Expanded(
- child: CancelButton(
- key: cancelKey,
- height: 35,
- callback: () {
- Navigator.of(context).pop(false);
- },
- content: textCancel),
- ),
- if (cancelable == true)
- const SizedBox(
- width: 20.0,
- ),
- Expanded(
- child: PrimaryButton(
- key: okKey,
- height: 35,
- callback: () {
- ok();
- },
- content: textOk))
- ],
- ),
- )
- ],
- ),
- ),
- ),
- ),
- );
- }
- }
|