flutter實現(xiàn)底部抽屜效果
本文實例為大家分享了flutter實現(xiàn)底部抽屜效果的具體代碼,供大家參考,具體內(nèi)容如下
安卓:showModalBottomSheet
IOS:showCupertinoModalPopup
效果圖

完整代碼
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
///@作者: Q.L
///@創(chuàng)建日期: 2021-09-09 10:55
///@描述: {底部抽屜}
class ActionSheetPage extends StatefulWidget {
? const ActionSheetPage({Key? key}) : super(key: key);
? @override
? _ActionSheetPageState createState() => _ActionSheetPageState();
}
class _ActionSheetPageState extends State<ActionSheetPage> {
? @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, // 設(shè)置最小的彈出
? ? ? ? ? ? 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('是否要編輯當(dāng)前項?'),
? ? ? ? ? ? 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 ?? '點擊了屏幕取消'}');
? }
}以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android使用相機實現(xiàn)拍照存儲及展示功能詳解
這篇文章主要介紹了Android使用相機實現(xiàn)拍照存儲及展示功能,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2023-01-01
獲取控件大小和設(shè)置調(diào)整控件的位置XY示例
我需要的設(shè)置控件相對屏幕左上角的X 、Y位置,而不是自己本身位置的偏移,下面與大家介紹下怎么獲取設(shè)置控件的信息2013-06-06
Android App支付系列(二):支付寶SDK接入詳細指南(附官方支付demo)
本篇文章介紹了Android App支付系列(二):支付寶SDK接入詳細指南(附官方支付demo) ,有興趣的同學(xué)可以了解一下。2016-11-11
Android貝塞爾曲線實現(xiàn)加入購物車拋物線動畫
這篇文章主要為大家詳細介紹了Android貝塞爾曲線實現(xiàn)加入購物車拋物線動畫,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-06-06
Android中解決WebView上下滑動監(jiān)聽問題
本篇文章主要介紹了Android中解決WebView滑動監(jiān)聽問題,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-04-04
詳解Android App中ViewPager使用PagerAdapter的方法
這篇文章主要介紹了詳解Android App中ViewPager使用PagerAdapter的方法,同時附帶了一個ViewPager的PagerAdapter不能更新數(shù)據(jù)的問題解決方法,需要的朋友可以參考下2016-03-03
Android編程之?dāng)?shù)據(jù)庫的創(chuàng)建方法詳解
這篇文章主要介紹了Android編程之?dāng)?shù)據(jù)庫的創(chuàng)建方法,結(jié)合實例形式分析了Android數(shù)據(jù)庫創(chuàng)建的步驟、實現(xiàn)技巧與相關(guān)注意事項,需要的朋友可以參考下2017-08-08

