代码之家  ›  专栏  ›  技术社区  ›  rv7284

带常规大小导航栏的列中的材质应用程序

  •  0
  • rv7284  · 技术社区  · 7 年前

    我想在我的整个应用程序上显示一个图像。所以我在Main.dart文件的一列中放置了一个图像和我的仪表板

    我的 main.dart 文件。

    void main() => runApp(new MyApp());
    
    class MyApp extends StatefulWidget {
      @override
      _MyAppState createState() => _MyAppState();
    }
    
    class _MyAppState extends State<MyApp> {   
      @override
      Widget build(BuildContext context) {
          return new MaterialApp(
            home: new Scaffold(
              body: new SafeArea(
                child: Column(
                  children: <Widget>[
                    new Image.asset('assets/ads.png'),
                    new Expanded(
                      child: Dashboard(),
                    )
                  ],
                ),
              ),
            ),
          );
      }
    }
    

    Dashboard.dart

    import 'package:flutter/material.dart';
    
    class Dashboard extends StatefulWidget {
      @override
      _DashboardState createState() => _DashboardState();
    }
    
    class _DashboardState extends State<Dashboard> {
      @override
      Widget build(BuildContext context) {
        return new MaterialApp(
          title: 'Flutter Demo',
          theme: new ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: new Scaffold(
            appBar: new AppBar(title: new Text('Books')),
            body: new Container(
              child: new Center(
                child: new Text('data'),
              ),
            ),
          ),
        );
      }
    }
    

    现在,这个代码生成这样的输出。

    enter image description here

    1 回复  |  直到 7 年前
        1
  •  1
  •   Rakesh Lanjewar    7 年前

    这样做:-

    import 'package:flutter/material.dart';
    void main() => runApp(new MyApp());
    
    class MyApp extends StatefulWidget {
      @override
      _MyAppState createState() => _MyAppState();
    }
    
    class _MyAppState extends State<MyApp> {
      @override
      Widget build(BuildContext context) {
        return new MaterialApp(
          debugShowCheckedModeBanner: false,
          home: new Scaffold(
            body: new SafeArea(
              child: Column(
                children: <Widget>[
                  new Image.network("https://via.placeholder.com/350x100"),
                  new Expanded(
                    child: Dashboard(),
                  )
                ],
              ),
            ),
          ),
        );
      }
    }
    
    
    class Dashboard extends StatefulWidget {
      @override
      _DashboardState createState() => _DashboardState();
    }
    
    class _DashboardState extends State<Dashboard> {
      @override
      Widget build(BuildContext context) {
        return  new Scaffold(
            appBar: new AppBar(title: new Text('Books')),
            body: new Container(
              child: new Center(
                child: new Text('data'),
              ),
            ),
        );
      }
    }
    

    enter image description here