Flutter application design without AppBar

前端 未结 2 1565
慢半拍i
慢半拍i 2021-02-06 01:52

I tried using this kind of approach to have all of my UI (here only a Text) in the application below the status bar, but witho

相关标签:
2条回答
  • 2021-02-06 02:32

    You can wrap the Scaffold into SafeArea, as below:

    import 'package:flutter/material.dart';
    
    void main() => runApp(MyApp(
      textInput: Text("Text Widget"),
    ));
    
    class MyApp extends StatefulWidget {
      final Widget textInput;
      MyApp({this.textInput});
    
      @override
      State<StatefulWidget> createState() => MyAppState();
    }
    
    class MyAppState extends State<MyApp> {
      bool checkBoxValue = false;
      @override
      Widget build(BuildContext ctxt) {
        return new MaterialApp(
          home: SafeArea(
               child: Scaffold(
                  body: new Center(
                  child: new Column(
                  children: <Widget>[
                    widget.textInput,
                    Checkbox(
                        value: checkBoxValue,
                        onChanged: (bool newValue){
                          setState(() {
                            checkBoxValue = newValue;
                          });
                        }
                    )
                  ],
                ))),
              ),
          );
      }
    }
    

    About the opposite, in case you do not need to keep repeating the AppBar in your multiple screens, you can create separate widget:

    import 'package:flutter/material.dart';
    import 'state.dart';
    
    AppBar commonAppBar(String title, void action()) {
      return new AppBar(
        title: new Text(title),
        actions: [
          new IconButton(icon: new Icon(Icons.flip), onPressed: action),
          new IconButton(icon: new Icon(Icons.exit_to_app), onPressed: () {
            new StateSubject().switchToLogin();
          }),
        ],
      );
    }
    
    0 讨论(0)
  • 2021-02-06 02:40

    Wrap your page content (Text or Scaffold) inside a SafeArea widget

    A widget that insets its child by sufficient padding to avoid intrusions by the operating system.

    return new SafeArea(child: new Text('text widget'));
    
    0 讨论(0)
提交回复
热议问题