1

自定义 Appbar 截图:

在此处输入图像描述

我想制作一个像照片中一样的自定义应用程序栏 谁能帮我创建这个我已经搜索了很多但在任何地方都找不到

4

2 回答 2

3

我不认为它是圆形appBar的,而是container它下面的圆形。

我已经添加backgroundColorScaffold与背景颜色匹配的AppBar. 另外,我已将 of 设置elevationAppBar0 以防止出现阴影。

在此处输入图像描述

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,
          ),
        ),
      ),
    );
  }
}
于 2020-04-12T07:10:04.703 回答
0

诀窍是不要弯曲 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"))
            ],
          ),
        ),
      ),
    );
  }
}
于 2020-04-12T06:49:15.313 回答