Флаттер: настройка высоты панели приложения - PullRequest
0 голосов
/ 28 июня 2018

Как я могу просто установить высоту AppBar во флаттере?

Заголовок столбца должен располагаться по центру по вертикали (в этом AppBar).

Ответы [ 5 ]

0 голосов
/ 17 апреля 2019

В дополнение к ответу @ Cinn, вы можете определить класс следующим образом

class MyAppBar extends AppBar with PreferredSizeWidget {
  @override
  get preferredSize => Size.fromHeight(50);

  MyAppBar({Key key, Widget title}) : super(
    key: key,
    title: title,
    // maybe other AppBar properties
  );
}

или так

class MyAppBar extends PreferredSize {
  MyAppBar({Key key, Widget title}) : super(
    key: key,
    preferredSize: Size.fromHeight(50),
    child: AppBar(
      title: title,
      // maybe other AppBar properties
    ),
  );
}

и затем используйте его вместо стандартного

0 голосов
/ 31 октября 2018

Вы можете использовать PreferredSize и flexibleSpace для него:

appBar: PreferredSize(
  preferredSize: Size.fromHeight(100.0),
  child: AppBar(
    automaticallyImplyLeading: false, // hides leading widget
    flexibleSpace: SomeWidget(),
  )
),

Таким образом, вы можете сохранить elevation из AppBar для сохранения его тени видимой и иметь пользовательскую высоту, что я и искал. Вы должны установить интервал в SomeWidget, однако.

0 голосов
/ 29 июня 2018

На момент написания этого я не знал о PreferredSize. Ответ Кинн лучше достичь этого.

Вы можете создать свой собственный виджет с пользовательской высотой:

import "package:flutter/material.dart";

class Page extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Column(children : <Widget>[new CustomAppBar("Custom App Bar"), new Container()],);
  }
}


class CustomAppBar extends StatelessWidget {

  final String title;
  final double barHeight = 50.0; // change this for different heights 

  CustomAppBar(this.title);

  @override
  Widget build(BuildContext context) {
    final double statusbarHeight = MediaQuery
        .of(context)
        .padding
        .top;

    return new Container(
      padding: new EdgeInsets.only(top: statusbarHeight),
      height: statusbarHeight + barHeight,
      child: new Center(
        child: new Text(
          title,
          style: new TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold),
        ),
      ),
    );
  }
}
0 голосов
/ 21 июля 2018

Вы можете использовать PreferredSize :

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Example',
      home: Scaffold(
        appBar: PreferredSize(
          preferredSize: Size.fromHeight(50.0), // here the desired height
          child: AppBar(
            // ...
          )
        ),
        body: // ...
      )
    );
  }
}
0 голосов
/ 28 июня 2018

Если вы находитесь в визуальном коде, Ctrl + клик в функции AppBar.

Widget demoPage() {
  AppBar appBar = AppBar(
    title: Text('Demo'),
  );
  return Scaffold(
    appBar: appBar,
    body: /*
    page body
    */,
  );
}

И отредактируйте этот кусок.

app_bar.dart will open and you can find 
    preferredSize = new Size.fromHeight(kToolbarHeight + (bottom?.preferredSize?.height ?? 0.0)),

Перепад высоты!

sample image

sample image

...