自定义 Appbar 截图:
我想制作一个像照片中一样的自定义应用程序栏 谁能帮我创建这个我已经搜索了很多但在任何地方都找不到
我不认为它是圆形appBar
的,而是container
它下面的圆形。
我已经添加backgroundColor
了Scaffold
与背景颜色匹配的AppBar
. 另外,我已将 of 设置elevation
为AppBar
0 以防止出现阴影。
import 'package:flutter/material.dart';
class TempMyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Test App',
home: Scaffold(
backgroundColor: Colors.indigo.shade800,
appBar: AppBar(
title: Text(
'Test App',
),
elevation: 0,
backgroundColor: Colors.indigo.shade800,
),
body: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(60),
topRight: Radius.circular(60),
),
color: Colors.white,
),
),
),
);
}
}
诀窍是不要弯曲 appbar,而是弯曲底部容器。看看下面的代码,你就会明白了。
class LoginPage extends StatefulWidget {
@override
_LoginPageState createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
final key = GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xFF012B44),
key: key,
appBar: AppBar(
title: Text("OTP Verification"),
backgroundColor: Colors.transparent,
),
body: SingleChildScrollView(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(15),
topRight: Radius.circular(15),
)
),
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
"Welcome to the login page",
style: Theme.of(context).textTheme.display1,
),
TextField(
decoration: InputDecoration(hintText: "Name"),
),
FlatButton(
onPressed: () {
key.currentState.showSnackBar(SnackBar(
content:
Text("I won't say your name but stay home, stay safe!"),
));
},
child: Text("Say my name"))
],
),
),
),
);
}
}