当我实现此代码时,显示器显示底部溢出无限像素。有谁知道为什么?我希望图像选择器位于左上角。
Scaffold(
body: Builder(
builder: (context)=> Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(height: 5.0,),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children:<Widget> [
Align(
alignment: Alignment.center,
child: CircleAvatar(
radius: 60.0,
backgroundColor: Colors.white,
child: ClipOval(
child: SizedBox(
width: 110.0,
height: 110.0,
child:(_image!=null)?Image.file(_image,fit:BoxFit.fill)
:Image.network("https://slcp.lk/wp-content/uploads/2020/02/no-profile-photo.png", fit: BoxFit.fill,),
),
),
),
),
Padding(
padding: EdgeInsets.only(top: 100.0, right: 40),
child: IconButton(
icon: Icon(
Icons.camera_alt,
size: 30.0,
),
onPressed: (){
getImage();
},
),
)
],
),
RaisedButton(
color: Colors.white,
onPressed: (){
uploadPic(context);
},
),
],
),
),
),
),
这是现在的样子=>但我希望图像选择器位于左上角
所以我更改了脚本,错误现在消失了,但图像选择器没有显示。这里应该是这样的
Scaffold(
body: Builder(
builder: (context)=> Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(height: 5.0,),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children:<Widget> [
Align(
alignment: Alignment.center,
child: CircleAvatar(
radius: 60.0,
backgroundColor: Colors.white,
child: ClipOval(
child: SizedBox(
width: 110.0,
height: 110.0,
child:(_image!=null)?Image.file(_image,fit:BoxFit.fill)
:Image.network("https://slcp.lk/wp-content/uploads/2020/02/no-profile-photo.png", fit: BoxFit.fill,),
),
),
),
),
Padding(
padding: EdgeInsets.only(top: 100.0, right: 40),
child: IconButton(
icon: Icon(
Icons.camera_alt,
size: 30.0,
),
onPressed: (){
getImage();
},
),
)
],
),
RaisedButton(
color: Colors.white,
onPressed: (){
uploadPic(context);
},
),
],
),
),
),
),
],
),
所以这就是我的整个脚本也许这更好理解。
class HomeScreen extends StatefulWidget {
@override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
File _image;
int _currentTabIndex = 0;
Future getImage() async{
var image = await ImagePicker.pickImage(source: ImageSource.gallery);
setState(() {
_image = image;
print('Image Path $_image');
});
}
Future uploadPic(BuildContext context)async{
String fileName=basename(_image.path);
StorageReference firebaseStorageRef=FirebaseStorage.instance.ref().child(fileName);
StorageUploadTask uploadTask=firebaseStorageRef.putFile(_image);
StorageTaskSnapshot taskSnapshot= await uploadTask.onComplete;
setState(() {
print('Profile Picture uploaded');
Scaffold.of(context).showSnackBar(SnackBar(content: Text('Profile Picture Uploaded')));
});
}
@override
Widget build(BuildContext context) {
Future<DocumentSnapshot> getUserInfo()async{
var firebaseUser = await FirebaseAuth.instance.currentUser;
return await Firestore.instance.collection("SerX").doc(firebaseUser.uid).get();
}
final _kTabPages = <Widget>[
Center(child: Icon(Icons.new_releases, size: 64.0, color: Colors.white)),
Center(child: Icon(Icons.local_grocery_store, size: 64.0, color: Colors.white)),
Center(child: Icon(Icons.chat, size: 64.0, color: Colors.white)),
ListView(
children: <Widget> [
Center(
child: FutureBuilder(
future: getUserInfo(),
builder: (context, AsyncSnapshot<DocumentSnapshot> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return ListView.builder(
shrinkWrap: true,
itemCount: 1,
itemBuilder: (BuildContext context, int index) {
return ListTile(
subtitle: Text(snapshot.data.data()["Email"], style: TextStyle(
color: Colors.white,
fontFamily: 'Orbitron',
fontSize: 10.0,
fontWeight: FontWeight.bold,),textAlign: TextAlign.right,
),
title: Text(snapshot.data.data()["Username"], style: TextStyle(
color: Colors.white,
fontFamily: 'Orbitron',
fontSize: 25.0,
fontWeight: FontWeight.bold),textAlign: TextAlign.right,),
);});
} else if (snapshot.connectionState == ConnectionState.none) {
return Text("No data");}
return Center(
child: SpinKitFadingCircle(color: Colors.white, size: 20.0),heightFactor: 29,
);
},
),
),
Scaffold(
body: Builder(
builder: (context)=> Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(height: 5.0,),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children:<Widget> [
Align(
alignment: Alignment.center,
child: CircleAvatar(
radius: 60.0,
backgroundColor: Colors.white,
child: ClipOval(
child: SizedBox(
width: 110.0,
height: 110.0,
child:(_image!=null)?Image.file(_image,fit:BoxFit.fill)
:Image.network("https://slcp.lk/wp-content/uploads/2020/02/no-profile-photo.png", fit: BoxFit.fill,),
),
),
),
),
Padding(
padding: EdgeInsets.only(top: 100.0, right: 40),
child: IconButton(
icon: Icon(
Icons.camera_alt,
size: 30.0,
),
onPressed: (){
getImage();
},
),
)
],
),
RaisedButton(
color: Colors.white,
onPressed: (){
uploadPic(context);
},
),
],
),
),
),
),
],
),
Center(child: Icon(Icons.settings, size: 64.0, color: Colors.white)),
];
final _kBottmonNavBarItems = <BottomNavigationBarItem>[
BottomNavigationBarItem(icon: Icon(Icons.new_releases, color: Colors.black), activeIcon: Icon(Icons.new_releases,color: Colors.grey) ,title: Text('News', style: TextStyle(
color: Color(0xFF000000),
fontSize: 10.0,
fontWeight: FontWeight.bold,
fontFamily: 'Orbitron',
),),),
BottomNavigationBarItem(icon: Icon(Icons.local_grocery_store ,color: Colors.black),activeIcon: Icon(Icons.local_grocery_store,color: Colors.grey), title: Text('Store', style: TextStyle(
color: Color(0xFF000000),
fontSize: 10.0,
fontWeight: FontWeight.bold,
fontFamily: 'Orbitron',
),),
),
BottomNavigationBarItem(icon: Icon(Icons.chat,color: Colors.black), activeIcon: Icon(Icons.chat,color: Colors.grey), title: Text('Chat', style: TextStyle(
color: Color(0xFF000000),
fontSize: 10.0,
fontWeight: FontWeight.bold,
fontFamily: 'Orbitron',
),),),
BottomNavigationBarItem(icon: Icon(Icons.supervisor_account,color: Colors.black), activeIcon: Icon(Icons.supervisor_account,color: Colors.grey), title: Text('Profile', style: TextStyle(
color: Color(0xFF000000),
fontSize: 10.0,
fontWeight: FontWeight.bold,
fontFamily: 'Orbitron',
),),),
BottomNavigationBarItem(icon: Icon(Icons.settings,color: Colors.black), activeIcon: Icon(Icons.settings,color: Colors.grey), title: Text('Settings', style: TextStyle(
color: Color(0xFF000000),
fontSize: 10.0,
fontWeight: FontWeight.bold,
fontFamily: 'Orbitron',
),),),
];
assert(_kTabPages.length == _kBottmonNavBarItems.length);
final bottomNavBar = BottomNavigationBar(
items: _kBottmonNavBarItems,
fixedColor: Colors.black,
currentIndex: _currentTabIndex,
type: BottomNavigationBarType.fixed,
onTap: (int index) {
setState(() {
_currentTabIndex = index;
});
},
);
return Scaffold(
appBar: AppBar(
bottom: PreferredSize(
child: Container(
color: Colors.white,
height: 4.0,
),
preferredSize: Size.fromHeight(0)),
backgroundColor: Colors.black,
leading: Container(),
title: Text('Ser X' , style: TextStyle(
color: Color(0xFFFFFFFF),
fontSize: 35,
fontWeight: FontWeight.bold,
fontFamily: 'Orbitron',
),),
titleSpacing: -45,
),
body: _kTabPages[_currentTabIndex],
backgroundColor: Colors.black,
bottomNavigationBar: bottomNavBar,
);
}
}
更新
Scaffold(
body: Builder(
builder: (context)=> Container(
height: 200,
child: ListView(
children: <Widget>[
SizedBox(height: 5.0,),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children:<Widget> [
Align(
alignment: Alignment.center,
child: CircleAvatar(
radius: 60.0,
backgroundColor: Colors.white,
child: ClipOval(
child: SizedBox(
width: 110.0,
height: 110.0,
child:(_image!=null)?Image.file(_image,fit:BoxFit.fill)
:Image.network("https://slcp.lk/wp-content/uploads/2020/02/no-profile-photo.png", fit: BoxFit.fill,),
),
),
),
),
Padding(
padding: EdgeInsets.only(top: 100.0, right: 40),
child: IconButton(
icon: Icon(
Icons.camera_alt,
size: 30.0,
),
onPressed: (){
getImage();
},
),
)
],
),
RaisedButton(
color: Colors.white,
onPressed: (){
uploadPic(context);
},
),
],
),
),
),
),
所以我再次升级了我的脚本
ListView(
children: <Widget> [
Center(
child: FutureBuilder(
future: getUserInfo(),
builder: (context, AsyncSnapshot<DocumentSnapshot> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return ListView.builder(
shrinkWrap: true,
itemCount: 1,
itemBuilder: (BuildContext context, int index) {
return ListTile(
subtitle: Text(snapshot.data.data()["Email"], style: TextStyle(
color: Colors.white,
fontFamily: 'Orbitron',
fontSize: 10.0,
fontWeight: FontWeight.bold,),textAlign: TextAlign.right,
),
title: Text(snapshot.data.data()["Username"], style: TextStyle(
color: Colors.white,
fontFamily: 'Orbitron',
fontSize: 25.0,
fontWeight: FontWeight.bold),textAlign: TextAlign.right,),
);});
} else if (snapshot.connectionState == ConnectionState.none) {
return Text("No data");}
return Center(
child: SpinKitFadingCircle(color: Colors.white, size: 20.0),heightFactor: 29,
);
},
),
),
Scaffold(
body: Builder(
builder: (context)=> Container(
height: 100,
child: ListView(
children: <Widget>[
SizedBox(height: 5.0,),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children:<Widget> [
Container(
padding: EdgeInsets.only(left: 0, top: 0),
child: CircleAvatar(
radius: 60.0,
backgroundColor: Colors.white,
child: ClipOval(
child: SizedBox(
width: 110.0,
height: 110.0,
child:(_image!=null)?Image.file(_image,fit:BoxFit.fill)
:Image.network("https://slcp.lk/wp-content/uploads/2020/02/no-profile-photo.png", fit: BoxFit.fill,),
),
),
),
),
Padding(
padding: EdgeInsets.only(top: 100.0, right: 40),
child: IconButton(
icon: Icon(
Icons.camera_alt,
size: 30.0,
),
onPressed: (){
getImage();
},
),
)
],
),
RaisedButton(
color: Colors.white,
onPressed: (){
uploadPic(context);
},
),
],
),
),
),
),
],
),
解决代码!
ListView(
children: <Widget> [
Center(
child: FutureBuilder(
future: getUserInfo(),
builder: (context, AsyncSnapshot<DocumentSnapshot> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return ListView.builder(
shrinkWrap: true,
itemCount: 1,
itemBuilder: (BuildContext context, int index) {
return ListTile(
subtitle: Text(snapshot.data.data()["Email"], style: TextStyle(
color: Colors.white,
fontFamily: 'Orbitron',
fontSize: 10.0,
fontWeight: FontWeight.bold,),textAlign: TextAlign.right,
),
title: Text(snapshot.data.data()["Username"], style: TextStyle(
color: Colors.white,
fontFamily: 'Orbitron',
fontSize: 25.0,
fontWeight: FontWeight.bold),textAlign: TextAlign.right,),
);});
} else if (snapshot.connectionState == ConnectionState.none) {
return Text("No data");}
return Center(
child: SpinKitFadingCircle(color: Colors.white, size: 20.0),heightFactor: 29,
);
},
),
),
SizedBox(height: 5.0,),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children:<Widget> [
Container(
padding: EdgeInsets.only(left: 0, top: 0),
child: CircleAvatar(
radius: 60.0,
backgroundColor: Colors.white,
child: ClipOval(
child: SizedBox(
width: 110.0,
height: 110.0,
child:(_image!=null)?Image.file(_image,fit:BoxFit.fill)
:Image.network("https://slcp.lk/wp-content/uploads/2020/02/no-profile-photo.png", fit: BoxFit.fill,),
),
),
),
),
Padding(
padding: EdgeInsets.only(top: 50.0),
child: IconButton(
icon: Icon(
Icons.camera_alt,
color: Colors.white,
size: 30.0,
),
onPressed: (){
getImage();
},
),
)
],
),
RaisedButton(
color: Colors.white,
onPressed: (){
uploadPic(context);
},
),
],
),