如何解决溢出错误

时间:2020-07-09 03:15:52

标签: flutter dart flutter-layout

我一直在网上寻找这个问题,甚至试图通过SingleChildScrollView解决溢出问题。不幸的是,它没有工作。它一直给我一个错误,并说Google登录按钮在右侧溢出了154像素。最好的解决方案是什么?我感谢任何尝试以任何方式提供帮助的人。我是Flutter的初学者。

import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:flutter/rendering.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter_auth_buttons/flutter_auth_buttons.dart';

void main() {
  runApp(LandingPage());
}

class LandingPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      // This takes you to Google Login Button stateful widget
      home: GoogleLoginBtn()
    );
  }
}


final GoogleSignIn _googleSignIn = GoogleSignIn();
final FirebaseAuth _auth = FirebaseAuth.instance;


Future<FirebaseUser> _handleSignIn() async {
  final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
  final GoogleSignInAuthentication googleAuth = await googleUser.authentication;

  final AuthCredential credential = GoogleAuthProvider.getCredential(
    accessToken: googleAuth.accessToken,
    idToken: googleAuth.idToken,
  );

  final FirebaseUser user = (await _auth.signInWithCredential(credential)).user;
  print("signed in " + user.displayName);
  return user;
}


// Just created a stateful widget
// This represents a login button
class GoogleLoginBtn extends StatefulWidget {
  @override
  _LoginState createState() => _LoginState();
}

class _LoginState extends State<GoogleLoginBtn> {

  FirebaseUser user;
  @override
  Widget build(BuildContext context) {
    return  Scaffold(
        backgroundColor: Colors.white10,
        body: Container(
          padding: EdgeInsets.all(166),
          child: SingleChildScrollView(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                Text('ProtoX',
                  style: TextStyle(color: Colors.white, fontSize: 20),
                  textAlign: TextAlign.center,
                ),
                SizedBox(
                  height: 360,
                  width: 360,
                ),
               GoogleSignInButton(
                 onPressed: () {
                   _handleSignIn()
                       .then((FirebaseUser user) => print(user))
                       .catchError((e) => print(e));
                    // Transition to Homepage page

                 },
               ),
              ],
            ),
          ),
        )
    );
  }
}

1 个答案:

答案 0 :(得分:0)

EdgeInsets.all(166)166可能是错字。您可以更改为16

工作演示

enter image description here

完整代码

import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:flutter/rendering.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter_auth_buttons/flutter_auth_buttons.dart';

void main() {
  runApp(LandingPage());
}

class LandingPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        // This takes you to Google Login Button stateful widget
        home: GoogleLoginBtn());
  }
}

final GoogleSignIn _googleSignIn = GoogleSignIn();
final FirebaseAuth _auth = FirebaseAuth.instance;

Future<FirebaseUser> _handleSignIn() async {
  final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
  final GoogleSignInAuthentication googleAuth = await googleUser.authentication;

  final AuthCredential credential = GoogleAuthProvider.getCredential(
    accessToken: googleAuth.accessToken,
    idToken: googleAuth.idToken,
  );

  final FirebaseUser user = (await _auth.signInWithCredential(credential)).user;
  print("signed in " + user.displayName);
  return user;
}

// Just created a stateful widget
// This represents a login button
class GoogleLoginBtn extends StatefulWidget {
  @override
  _LoginState createState() => _LoginState();
}

class _LoginState extends State<GoogleLoginBtn> {
  FirebaseUser user;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.white10,
        body: Container(
          padding: EdgeInsets.all(16),
          child: SingleChildScrollView(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                Text(
                  'ProtoX',
                  style: TextStyle(color: Colors.white, fontSize: 20),
                  textAlign: TextAlign.center,
                ),
                SizedBox(
                  height: 360,
                  width: 360,
                ),
                GoogleSignInButton(
                  onPressed: () {
                    _handleSignIn()
                        .then((FirebaseUser user) => print(user))
                        .catchError((e) => print(e));
                    // Transition to Homepage page
                  },
                ),
              ],
            ),
          ),
        ));
  }
}