GestureDetector需要添加behavior: HitTestBehavior.opaque
GestureDetector(
behavior: HitTestBehavior.opaque,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: (){
print("hehe");
},
没配合AppBar使用顶部出现空白,ListView头部有一段空白区域,是因为当ListView没有和AppBar一起使用时,头部会有一个padding,为了去掉padding,可以使用MediaQuery.removePadding
Widget _listView(BuildContext context){
return MediaQuery.removePadding(
removeTop: true,
context: context,
child: ListView.builder(
itemCount: 10,
itemBuilder: (context,index){
return _item(context,index);
},
),
);
}
同时使用 mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.stretch
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Align(
alignment: Alignment.centerLeft,
child: GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Container(
height: 45,
child: Image.asset('assets/${StyleConfig.instance.assetsImageMiddlePath}theme_normal_back.png')
),
),
),
Align(
alignment: Alignment.centerLeft,
child: Text(
this.title,
style: TextStyle(
color: Colors.black87,
fontWeight: FontWeight.bold,
fontSize: 25,
),
),
),
],
),
直接在 MaterialApp 中使用 Navigator 是会报 Navigator operation requested with a context that does not include a Navigat. ...
return MaterialApp(
navigatorObservers: [routeObserver],
debugShowCheckedModeBanner: false,
home: Scaffold(
body: BlocProvider(
builder: (context) {
return SettingBloc(settingRepository: SettingRepository());
},
child: BottomButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => LanguagePage(),
),
);
}
),
),
),
builder: (BuildContext context, Widget child) {
return MediaQuery(
child: child,
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0));
},
);
要使用 路由(Navigator),根控件不能直接是 MaterialApp.解决方法:将 MaterialApp 内容再使用 StatelessWeight 或 StatefulWeight 包裹一层;
///点击item index
typedef void OnItemTapCompletion(int index);
@immutable
class CommonList extends StatelessWidget {
List items;
OnItemTapCompletion onTap;
CommonList({this.items, this.onTap});
}
使用
Widget _buildItem(BuildContext context, int index) {
return Column(
children: [
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => this.onTap(index),
child: Container(
padding: const EdgeInsets.only(left: 15.0, right: 15.0),
alignment: AlignmentDirectional.centerStart,
height: 60,
child: _buildItemContent(context, index),
),
),
Divider(
color: StyleConfig.instance.baseColorPrimarySeparator,
height: 1,
indent: 15,
)
],
);
}
6、原生跳转到Flutter页面瞬间显示启动页面
在FlutterBaseViewController设置setSplashScreenView为nil
if ([viewController respondsToSelector:@selector(setSplashScreenView:)]) {
[viewController performSelector:@selector(setSplashScreenView:) withObject:nil];
}