ギャラリーから画像をピックアップしてUIに更新しようとしていました。しかし、これを実行すると、56 行目の profile.dart ファイルにエラーが表示されます。
エラーは _image で発生します。
引数の型 'File(File は D:\Softwares\flutter\bin\cache\pkg\sky_engine\lib\html\html_dart2js.dart で定義されています)' は、パラメーターの型 'File(File はここで) に割り当てることはできませんD:\Softwares\flutter\bin\caches\pkg\sky_engine\lib\io\file.dart で定義)'
完全なコード。
Main.dart
import 'package:flutter/material.dart';
import 'package:udharibook/Screens/SplashScreen.dart';
import 'package:udharibook/Screens/UserProfile.dart';
void main(){
runApp(
MaterialApp(
title: 'Udhari Book',
home:UserProfile(),
debugShowCheckedModeBanner: false,
theme: ThemeData(
backgroundColor: Color.fromRGBO(242, 242, 242, 1.0)
),
)
);
}
自己紹介ページ
import 'dart:html';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:image_picker/image_picker.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:path/path.dart';
class UserProfile extends StatefulWidget {
@override
_UserProfileState createState() => _UserProfileState();
}
class _UserProfileState extends State<UserProfile> {
File _image;
TextEditingController nameController =TextEditingController()..text='Mehul Jain';
TextEditingController mobileController =TextEditingController()..text='8856061841';
TextEditingController emailController =TextEditingController()..text='mehuljain3698@gmail.com';
TextEditingController addressController =TextEditingController()..text='Maharashtra';
@override
Widget build(BuildContext context) {
Future getImage() async{
var image=await ImagePicker.pickImage(source: ImageSource.gallery);
setState(() {
_image=image as File;
print('Image Path $_image');
});
}
return Scaffold(
resizeToAvoidBottomPadding: false,
appBar: AppBar(
title: Text('User Profile'),
backgroundColor: Color.fromRGBO(162, 42, 43, 1.0),
),
body: Builder(
builder: (context) => Container(
child: Column(
children: <Widget>[
SizedBox(
height: 20.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Align(
alignment: Alignment.center,
child: CircleAvatar(
radius: 50,
backgroundColor: Color.fromRGBO(162, 42, 43, 1.0),
child: ClipOval(
child: SizedBox(
height: 180.0,
width: 180.0,
child:_image!=null?
Image.file(_image,fit: BoxFit.fill):
Image.network(
'https://randomwordgenerator.com/img/picture-generator/55e4d5464f5ba914f1dc8460962e33791c3ad6e04e5074417d2d73dc934bcd_640.jpg',
fit: BoxFit.fill,
)),
),
),
),
Padding(
padding: EdgeInsets.only(top: 60.0),
child: IconButton(
icon: Icon(Icons.camera_alt), onPressed: () {
getImage();
}),
)
],
),
Padding(
padding: EdgeInsets.only(top:20.0,left: 10.0,right: 10.0),
child:SizedBox(
height: 40.0,
child: TextField(
controller: nameController,
decoration: InputDecoration(
labelText: 'Full Name',
labelStyle:
TextStyle(fontFamily: 'Exo2', color: Colors.grey),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0)
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
borderSide: BorderSide(
color:
Color.fromRGBO(162, 42, 43, 1.0)
)
)
),
),
)),
Padding(
padding: EdgeInsets.only(top:15.0,left: 10.0,right: 10.0),
child:SizedBox(
height: 40.0,
child: TextField(
controller: mobileController,
enabled: false,
keyboardType:TextInputType.phone,
decoration: InputDecoration(
labelText: 'Mobile Number',
labelStyle:
TextStyle(fontFamily: 'Exo2', color: Colors.grey),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0)),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
borderSide: BorderSide(
color:
Color.fromRGBO(162, 42, 43, 1.0)
)
)
),
),
)),
Padding(
padding: EdgeInsets.only(top:15.0,left: 10.0,right: 10.0),
child:SizedBox(
height: 40.0,
child: TextField(
controller: emailController,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
labelText: 'Email (Optional)',
labelStyle:
TextStyle(fontFamily: 'Exo2', color: Colors.grey),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0)
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
borderSide: BorderSide(
color:
Color.fromRGBO(162, 42, 43, 1.0)
)
)
),
),
)),
Padding(
padding: EdgeInsets.only(top:15.0,left: 10.0,right: 10.0,bottom: 30.0),
child: TextField(
maxLines: 3,
maxLengthEnforced: true,
controller: addressController,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
labelText: 'Address (Optional)',
labelStyle:
TextStyle(fontFamily: 'Exo2', color: Colors.grey),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0)
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
borderSide: BorderSide(
color:
Color.fromRGBO(162, 42, 43, 1.0)
)
)
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
SizedBox(
width:130.0,
height: 50.0,
child:RaisedButton(
color: Color.fromRGBO(162, 42, 43, 1.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0)
),
onPressed: (){
Navigator.of(context).pop();
},
elevation: 4.0,
splashColor: Colors.blueGrey,
child: Text(
'Save',
style: TextStyle(
color:Colors.white,fontSize: 22.0,fontFamily: 'Exo2'
),
),
)),
SizedBox(
width:130.0,
height:50.0,
child:RaisedButton(
color: Color.fromRGBO(162, 42, 43, 1.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0)
),
onPressed: (){
Navigator.of(context).pop();
},
elevation: 4.0,
splashColor: Colors.blueGrey,
child: Text(
'Cancel',
style: TextStyle(
color:Colors.white,fontSize: 22.0,fontFamily: 'Exo2'
),
),
))
],
)
],
),
),
),
);
}
}