Abnormal problems: RenderCustomMultiChildLayoutBox object was given an infinite size during layout child layout is not clearly can’t use the size of the Scaffold Scaffold construction of common components using the following way

class LoginWidget extends StatefulWidget { @override State<StatefulWidget> createState() { return _LoginState(); } } class _LoginState extends State<LoginWidget> { final phoneController = TextEditingController(); final pwdController = TextEditingController(); @override Widget build(BuildContext context) {// Scaffolding return Container(Child: Container(Alignment: Child: AlignmentDirectional center, Padding (Padding: EdgeInsets fromLTRB (30.0, 32.0, 30.0, 0), the child: Column( children: <Widget>[ Image( image: AssetImage("images/course_logo.png"), width: 139, height: 38, fit: BoxFit.contain, ), inputPhone(context), inputPassword(context), loginWidget(context), loginByWX(context), ], ), )), ); }Copy the code

Sample introduced common component Widget (login module)

import 'dart:convert'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:micro_course/bean/LoginMsg.dart'; import 'package:micro_course/utils/HexColor.dart'; import 'package:micro_course/http/DioManger.dart'; import 'package:micro_course/http/APIConfig.dart'; import 'package:micro_course/common/eventbus.dart'; import 'package:fluwx/fluwx.dart' as fluwx; class LoginWidget extends StatefulWidget { @override State<StatefulWidget> createState() { return _LoginState(); } } class _LoginState extends State<LoginWidget> { final phoneController = TextEditingController(); final pwdController = TextEditingController(); @override Widget build(BuildContext context) { return Container( child: Container( alignment: Child: AlignmentDirectional center, Padding (Padding: EdgeInsets fromLTRB (30.0, 32.0, 30.0, 0), the child: Column( children: <Widget>[ Image( image: AssetImage("images/course_logo.png"), width: 139, height: 38, fit: BoxFit.contain, ), inputPhone(context), inputPassword(context), loginWidget(context), loginByWX(context), ], ), )), ); } // Widget inputPhone(BuildContext Context) {return Padding(Padding: EdgeInsets. Only (top: 40), child: Container(height: 50, width: 307, padding: EdgeInsets. Only (left: 10.0), alignment: AlignmentDirectional.center, decoration: BoxDecoration( color: Colors.grey[200], borderRadius: BorderRadius.circular(15)), child: TextField( // autofocus: true, controller: phoneController, decoration: InputDecoration(hintText: "Please enter the phone number ", border: InputBorder. None, contentPadding: edgeinset.zero,), onChanged: (v) {// print($v); },),),); } Widget inputPassword(BuildContext Context) {return Padding(Padding: EdgeInsets. Only (top: 20), child: Container(height: 50, width: 307, padding: EdgeInsets. Only (left: 10.0), alignment: AlignmentDirectional.center, decoration: BoxDecoration( color: Colors.grey[200], borderRadius: BorderRadius.circular(15)), child: TextField( // autofocus: true, controller: pwdController, decoration: InputDecoration(hintText: "Please enter password ", border: InputBorder. None, contentPadding: edgeinsets.zero,), onChanged: (v) {// print(" password :$v"); },),),); } /// Widget loginWidget(BuildContext Context) {return GestureDetector(onTap: () {var params = {"phone": phoneController.text, "password": pwdController.text, }; login(params, context); // Scaffold.of(context).showsnackbar (SnackBar(// content: Text(' click login '+ phonecontroller.text), //)); }, child: Padding(Padding: EdgeInsets. FromLTRB (7.5, 0, 7.5, 0), child: height: 120, child: Stack( alignment: AlignmentDirectional.center, children: <Widget>[ Container( height: 50, width: 307, decoration: Color: color.yellow [800], borderRadius: borderRadius. All (Radius. Circular (45)),),), color: color (color: color.yellow [800], borderRadius: borderRadius. TextStyle(fontSize: 18, color: HexColor('#824E00')), ), ], ), ), ), ); } // Widget loginByWX(BuildContext Context) {return GestureDetector(onTap: loginWX, child: Container( // height: 50, alignment: AlignmentDirectional.center, child: Padding( padding: EdgeInsets.all(2), child: Image( image: AssetImage("images/send.png"), width: 139, height: 40, fit: BoxFit.contain, ), ), ), ); } void login(Map<String, String> params, BuildContext context) { DioManger.getInstance().post(APIConfig.LOGIN, params, Null, (data) {setState(() {print(" login successfully: "+ data.toString())); Map<String, dynamic> jsonMsg = json.decode(data.toString()); LoginMsg loginMsg = LoginMsg.fromJson(jsonMsg); Print ("json to entity: "+ loginmsg.tostring ()); / / / UI/update/Navigator. PushReplacement (context, MaterialPageRoute (/ / builder: (context) => BottomNavigationWidget(), // settings: RouteSettings( // arguments:jsonMsg, // ), // )); getUserCourseList(loginMsg); }); }, (error) { setState(() {}); Print (" error: "+ error.tostring ()); }); Void getUserCourseList(LoginMsg LoginMsg) {Map<String, String> parms = {"student_id": loginMsg.data.studentId.toString() }; Map<String, String> headers = { "token": loginMsg.data.loginToken.toString() }; Diomanger.getinstance ().get(APIConfig.GET_COURSE_LIST, parms, headers, (data) {print(" course_list successfully: "+ data.tostring ()); Bus. emit('login', loginMsg); }, (error) {print(" failed to get the course list: "+ error.tostring ()); }); Void loginWX() {print(" loginWX "); fluwx .sendAuth(scope: "snsapi_userinfo", state: "Wechat_sdk_demo_test "). Then ((data) {setState(() {print(" + data.tostring ()); }); }).catchError((e) { print('weChatLogin e $e'); }); }}Copy the code

Introduction of common components

import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:micro_course/widgets/login.dart'; class CourseScreen extends StatefulWidget { @override State<StatefulWidget> createState() { return _LoginState(); } } class _LoginState extends State<CourseScreen> { @override Widget build(BuildContext context) { return Scaffold( ResizeToAvoidBottomPadding: false, appBar: appBar (title: Text (' course selection, style: TextStyle (fontSize: 18, fontWeight: FontWeight.normal, color: Colors.black87), ), centerTitle: true, actions: <Widget>[ IconButton( icon: Icon( Icons.more_horiz, color: Colors.grey, ), onPressed: () { Scaffold.of(context) .showSnackBar(SnackBar(content: Text(' share '));})],), body: ListView(shrinkWrap: true,/// Set the length of the ListView to children: < widgets > [Container (alignment: AlignmentDirectional center, child: LoginWidget (), / / / login into public components),],)); }}Copy the code
  • Note: There is an input box in the Scaffold. The Scaffold should be placed in lisetView or other sliders when the keyboard pops up. If you do not know the size of the Scaffold, you cannot use the Scaffold. Use containers instead.