在Flutter內(nèi)部機(jī)制中航夺,默認(rèn)使用自動(dòng)管理導(dǎo)航機(jī)制蕉朵,該機(jī)制在Flutter與原生混和開發(fā)情況下,F(xiàn)lutter頁(yè)面不一定作為項(xiàng)目的首頁(yè)面阳掐,所以出現(xiàn)需要在首個(gè)Flutter頁(yè)面使用導(dǎo)航返回的需求始衅。
解決方案:
Flutter的AppBar中定義有屬性:
final bool automaticallyImplyLeading;
該屬性默認(rèn)為YES,即默認(rèn)為自動(dòng)管理導(dǎo)航欄缭保,該情況下其會(huì)在非第一個(gè)Flutter頁(yè)面創(chuàng)建導(dǎo)航返回按鈕汛闸,我們?cè)贏ppBar中將其設(shè)置為false:
automaticallyImplyLeading: false,
并且手動(dòng)添加導(dǎo)航返回按鈕:
appBar: AppBar(
title: Text('MixStack'),
centerTitle: true,
automaticallyImplyLeading: false,
leading: Builder(
builder: (context) {
return IconButton(icon: Icon(Icons.arrow_back_ios), onPressed: () => router.pop(context));
},
),
),
完成