flutter3.0学习笔记

SimpleDialog

Preview
  • SimpleDialog

SimpleDialog

其构造:

const SimpleDialog({
    super.key,
    this.title,//标题
    this.titlePadding = const EdgeInsets.fromLTRB(24.0, 24.0, 24.0, 0.0),
    this.titleTextStyle,//标题样式
    this.children, // 消息内容
    this.contentPadding = const EdgeInsets.fromLTRB(0.0, 12.0, 0.0, 16.0),
    this.backgroundColor,
    this.elevation,
    this.semanticLabel,
    this.insetPadding = _defaultInsetPadding,
    this.clipBehavior = Clip.none,
    this.shape,
    this.alignment,
  })

常用例子:

 ElevatedButton(
    onPressed: (){
      showDialog(context: context,
          builder: (context) {
            return SimpleDialog(
                title: const Text('SimpleDialog', style: TextStyle(color: Colors.blueAccent)),
                children: <Widget>[
                  const Padding(child: Text('我是 SimpleDialog 对话框?'), padding: EdgeInsets.all(20.0)),
                  SimpleDialogOption(child: Text('选项1'), onPressed: () => Navigator.pop(context)),
                  SimpleDialogOption(child: Text('选项2'), onPressed: () => Navigator.pop(context))
                ]
            );
          });
    },
    child: const Text('SimpleDialog')
)

image.png

List SimpleDialog:

ElevatedButton(
   onPressed: (){
     showDialog(context: context,
         builder: (context) {
           return SimpleDialog(
               title: Row(children: const <Widget>[
                 Padding(padding: EdgeInsets.only(left: 12.0), child: Text('Simple List'))
               ]),
               elevation: 10.0,
               shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(14.0))),
               children: <Widget>[
                 SizedBox(height: 400.0,
                     child: ListView.builder(
                         itemCount: 30,
                         itemBuilder: (BuildContext context, int index) {
                           return ListTile(title: Text('当前 index = $index'), onTap: () => Navigator.of(context).pop(index));
                         }
                    )
                 )
               ]
           );
         });
   },
   child: const Text('SimpleDialog')
)