Scaffold 里面有包含兩個Drawer 一個drawer endDrawer
image.png
/// {@end-tool} 左邊彈出
final Widget drawer;
/// {@end-tool} 右邊彈出
final Widget endDrawer;
endDrawer 與 drawer 同樣都是需要傳一個Widget,所以我們可以任意寫就好了,Drawer默認(rèn)會給我們一個背景的。
Scaffold(
backgroundColor: Colours.hexColor(0xf5f5f5),
appBar: AppBar(),
endDrawer: ScreeningDrawerView(),
body: Container()
);
import 'package:app/app/res/colors.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
class ScreeningDrawerView extends StatefulWidget {
@override
_ScreeningDrawerViewState createState() => _ScreeningDrawerViewState();
}
class _ScreeningDrawerViewState extends State<ScreeningDrawerView> {
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.only(left: 17,right: 17),
color: Colors.white,
height: ScreenUtil().screenHeight,
width: ScreenUtil().screenWidth -44,
child: SafeArea(
child: CustomScrollView(
slivers: [
SliverToBoxAdapter(
child: Text('優(yōu)質(zhì)服務(wù)', style: TextStyle(
color: Colors.black, fontWeight: FontWeight.bold),),
),
SliverToBoxAdapter(
child: SizedBox(height: 20,),
),
SliverGrid(
delegate:
SliverChildBuilderDelegate((BuildContext context, int index) {
return InkWell(
child: Container(
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colours.hexColor(0xebebec),
borderRadius: BorderRadius.circular(4)
),
child: Text('電子發(fā)票'),
),
onTap: () {},
);
}, childCount: 6),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
crossAxisSpacing: 11,
mainAxisSpacing: 12,
childAspectRatio: 3.5)),
],
),
),
);
}
}
在其他按鈕方法里面打開 我們 的endDrawer 断部,需要包一個Builder
Builder(builder: (context){
return InkWell(
onTap: (){
Scaffold.of(context).openEndDrawer();
},
child:Text('data')
);
});