调用 MediaQuery.of(context).padding.top 即可。
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
title: 'Flutter Tutorial',
home: TutorialHome(),
));
}
class TutorialHome extends StatelessWidget {
@override
Widget build(BuildContext context) {
// Scaffold is a layout for the major Material Components.
return Scaffold(
// body is the majority of the screen.
body: Container(
child: Column(
children: <Widget>[
Container(
child: Text(
'Hello, world!',
),
// margin: EdgeInsets.only(top: 20),
alignment: Alignment.center,
),
],
),
padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
),
);
}
}
网友评论