日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

flutter實現底部抽屜效果_Android

作者:齊安郡晚秋 ? 更新時間: 2022-05-26 編程語言

本文實例為大家分享了flutter實現底部抽屜效果的具體代碼,供大家參考,具體內容如下

安卓:showModalBottomSheet
IOS:showCupertinoModalPopup

效果圖

完整代碼

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

///@作者: Q.L
///@創建日期: 2021-09-09 10:55
///@描述: {底部抽屜}
class ActionSheetPage extends StatefulWidget {
? const ActionSheetPage({Key? key}) : super(key: key);

? @override
? _ActionSheetPageState createState() => _ActionSheetPageState();
}

class _ActionSheetPageState extends State {
? @override
? Widget build(BuildContext context) {
? ? return Scaffold(
? ? ? appBar: AppBar(
? ? ? ? title: Text('底部抽屜彈出'),
? ? ? ),
? ? ? body: Center(
? ? ? ? child: Column(
? ? ? ? ? mainAxisAlignment: MainAxisAlignment.center,
? ? ? ? ? children: [
? ? ? ? ? ? ElevatedButton(
? ? ? ? ? ? ? ? onPressed: () {
? ? ? ? ? ? ? ? ? _showModalBottomSheet();
? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? child: Text('安卓彈出')),
? ? ? ? ? ? ElevatedButton(
? ? ? ? ? ? ? ? onPressed: () {
? ? ? ? ? ? ? ? ? _showCupertinoModalPopup();
? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? child: Text('IOS彈出')),
? ? ? ? ? ],
? ? ? ? ),
? ? ? ),
? ? );
? }

? _showModalBottomSheet() async {
? ? var _result = await showModalBottomSheet(
? ? ? ? context: context,
? ? ? ? backgroundColor: Colors.greenAccent, //背景顏色
? ? ? ? // elevation: 500, //陰影
? ? ? ? shape: RoundedRectangleBorder(
? ? ? ? ? ? // borderRadius: BorderRadius.all(Radius.circular(10)),//所有圓角邊框
? ? ? ? ? ? borderRadius:
? ? ? ? ? ? ? ? BorderRadius.only(topLeft: Radius.circular(10), topRight: Radius.circular(10))),
? ? ? ? isScrollControlled: false, //是否是全屏還是半屏,true全屏,默認false半屏
? ? ? ? isDismissible: true, //外部是否可以點擊,false不可以點擊,true可以點擊,點擊后消失
? ? ? ? builder: (BuildContext context) {
? ? ? ? ? return Column(
? ? ? ? ? ? mainAxisSize: MainAxisSize.min, // 設置最小的彈出
? ? ? ? ? ? children: [
? ? ? ? ? ? ? ListTile(
? ? ? ? ? ? ? ? leading: Icon(Icons.photo_camera),
? ? ? ? ? ? ? ? title: Text("拍照"),
? ? ? ? ? ? ? ? onTap: () {
? ? ? ? ? ? ? ? ? Navigator.of(context).pop('拍照');
? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ),
? ? ? ? ? ? ? ListTile(
? ? ? ? ? ? ? ? leading: Icon(Icons.photo_library),
? ? ? ? ? ? ? ? title: Text("相冊"),
? ? ? ? ? ? ? ? onTap: () {
? ? ? ? ? ? ? ? ? Navigator.of(context).pop('相冊');
? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ),
? ? ? ? ? ? ],
? ? ? ? ? );
? ? ? ? });
? ? print('選擇了安卓==>>${_result ?? '點擊了屏幕取消'}');
? }

? _showCupertinoModalPopup() async {
? ? var result = await showCupertinoModalPopup(
? ? ? ? context: context,
? ? ? ? builder: (context) {
? ? ? ? ? return CupertinoActionSheet(
? ? ? ? ? ? title: Text('提示'),
? ? ? ? ? ? message: Text('是否要編輯當前項?'),
? ? ? ? ? ? actions: [
? ? ? ? ? ? ? CupertinoActionSheetAction(
? ? ? ? ? ? ? ? child: Text('編輯'),
? ? ? ? ? ? ? ? onPressed: () {
? ? ? ? ? ? ? ? ? Navigator.of(context).pop('編輯');
? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? isDefaultAction: true,
? ? ? ? ? ? ? ),
? ? ? ? ? ? ? CupertinoActionSheetAction(
? ? ? ? ? ? ? ? child: Text('刪除'),
? ? ? ? ? ? ? ? onPressed: () {
? ? ? ? ? ? ? ? ? Navigator.of(context).pop('刪除');
? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? isDestructiveAction: true,
? ? ? ? ? ? ? ),
? ? ? ? ? ? ],
? ? ? ? ? ? cancelButton: CupertinoActionSheetAction(
? ? ? ? ? ? ? child: Text('取消'),
? ? ? ? ? ? ? onPressed: () {
? ? ? ? ? ? ? ? Navigator.of(context).pop('取消');
? ? ? ? ? ? ? },
? ? ? ? ? ? ),
? ? ? ? ? );
? ? ? ? });
? ? print('選擇了IOS==>>${result ?? '點擊了屏幕取消'}');
? }
}

原文鏈接:https://blog.csdn.net/qq_36926045/article/details/120196621

欄目分類
最近更新