簡體   English   中英

Flutter:我想在屏幕上一起顯示“網格視圖”和其他小部件

[英]Flutter: I want to display "Grid View" and other widgets together on the screen

我能夠使用 GridView 小部件在網格中顯示子小部件,文本和 GridView 小部件等小部件在一個屏幕上一起顯示如何顯示?

例如

//sign_in_page.dart

class SignInPage extends StatelessWidget {

  void _signInAnonymously() async {
    final authResult=await FirebaseAuth.instance.signInAnonymously();

    print('${authResult.user.uid}');

  }

  @override
  Widget build(BuildContext context) {

    List<Widget> list1=[
      SizedBox(
        width:50.0,
        height:50.0,
        child:Container(
          color:Colors.blue,
        ),
      ),
      SizedBox(
        width:100.0,
        height:100.0,
        child:Container(
          color:Colors.red,
        ),
      ),
      SizedBox(
        width:100.0,
        height:100.0,
        child:Container(
          color:Colors.green,
        ),
      ),
      SizedBox(
        width:100.0,
        height:100.0,
        child:Container(
          color:Colors.yellow,
        ),
      ),
    ];

    return Scaffold(
      appBar: AppBar(
        title: Text('title'),
        elevation: 10.0,
      ),
      //body: buildContent(),
      body:Column(    //←This will give an error.
        children: [
          Text('Description of this GridView'),
          GridView.count(
              crossAxisCount: 3,
              children: list1
          ),
        ],
      ),
      backgroundColor: Colors.grey[300],
    );
  }
//main.dart

import 'package:flutter/material.dart';

import 'app/sign_in/sign_in_page.dart';
void main(){
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title:'title',
      theme:ThemeData(
        primarySwatch: Colors.indigo,
      ),
      home:SignInPage(),
    );
  }
}

我想顯示文本和網格視圖,

但是當我嘗試使用上面的列小部件顯示它時,

我收到一個錯誤。

在這種情況下是否有任何合適的小部件可以使用?

我想你應該用 Expanded() 包裹你的 GridView.count() 來指定高度,比如

Expanded(
 child: GridView.count()
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM