I'm new to flutter and developing user image and user detail update section using flutter. I'm getting this error in my code. in ProfileScreen.dart file. appriciate your help on this.
Error: The method 'CreateProfile' isn't defined for the class '_ProfileScreenState'.
'_ProfileScreenState' is from 'package:image_uploader/Profile/ProfileScreen.dart' ('lib/Profile/ProfileScreen.dart'). Try correcting the name to the name of an existing method, or defining a method named 'CreateProfile'. MaterialPageRoute(builder: (context) => CreateProfile())) ^^^^^^^^^^^^^
The argument type 'Object' can't be assigned to the parameter type 'ImageProvider?'.
backgroundImage: _imageFile == null? AssetImage("assets/pic.jpg"):FileImage(file(_imageFile.path)),
ProfileScreen.dart
import 'package:flutter/material.dart';
import 'package:image_uploader/Profile/CreateProfile.dart';
class ProfileScreen extends StatefulWidget {
ProfileScreen({ Key? key}) : super(key: key);
@override
_ProfileScreenState createState() => _ProfileScreenState();
}
class _ProfileScreenState extends State<ProfileScreen> {
@override
Widget build(BuildContext context){
return Scaffold(
body: button(),
);
}
Widget button() {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 70),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
"Tap to button to add profile data",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.teal,
fontSize: 15,
),
),
SizedBox(
height: 30,
),
//button
Center(
child: InkWell(
onTap: () => {
Navigator.push(context,
MaterialPageRoute(builder: (context) => CreateProfile()))
},
child: Container(
height: 60,
width: 150,
decoration: BoxDecoration(
color: Colors.teal,
borderRadius: BorderRadius.circular(20),
),
child: Center(
child: Text(
"Add Proile",
style: TextStyle(
color: Colors.white,
fontSize: 18,
),
),
),
),
),
),
],
),
);
}
}
CreateProfile.dart
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'dart:convert';
import 'package:http/http.dart' ;
class CreatProfile extends StatefulWidget {
CreatProfile({required Key key}) : super(key: key);
@override
_CreatProfileState createState() => _CreatProfileState();
}
class _CreatProfileState extends State<CreatProfile> {
bool circular = false;
late PickedFile _imageFile;
final ImagePicker _picker = ImagePicker();
@override
Widget build(BuildContext context) {
return Scaffold(
body: Form(
child: ListView(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 30),
children: <Widget>[
imageProfile(),
SizedBox(
height: 20,
),
nameTextField(),
SizedBox(
height: 20,
),
professionTextField(),
SizedBox(
height: 20,
),
dobField(),
SizedBox(
height: 20,
),
titleTextField(),
SizedBox(
height: 20,
),
aboutTextField(),
SizedBox(
height: 20,
),
],
),
),
);
}
Widget imageProfile() {
return Center(
child: Stack(children: <Widget>[
CircleAvatar(
radius: 80.0,
backgroundImage: _imageFile == null? AssetImage("assets/pic.jpg"):FileImage(file(_imageFile.path)),
),
Positioned(
bottom: 20.0,
right: 20.0,
child: InkWell(
onTap: () {
showModalBottomSheet(
context: context,
builder: ((builder) => bottomSheet()),
);
},
child: Icon(
Icons.camera_alt,
color: Colors.teal,
size: 28.0,
),
),
),
]),
);
}
Widget bottomSheet() {
return Container(
height: 100.0,
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.symmetric(
horizontal: 20,
vertical: 20,
),
child: Column(
children: <Widget>[
Text(
"Choose Profile photo",
style: TextStyle(
fontSize: 20.0,
),
),
SizedBox(
height: 20,
),
Row(mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[
TextButton.icon(
icon: Icon(Icons.camera),
onPressed: () {
takePhoto(ImageSource.camera);
},
label: Text("Camera"),
),
TextButton.icon(
icon: Icon(Icons.image),
onPressed: () {
takePhoto(ImageSource.gallery);
},
label: Text("Gallery"),
),
])
],
),
);
}
void takePhoto(ImageSource source) async {
final pickedFile = await _picker.pickImage(
source: source,
);
setState(() {
_imageFile = pickedFile as PickedFile;
});
}
//starting text fields
Widget nameTextField() {
return TextFormField(
//controller: _name,
validator: (value) {
if (value!.isEmpty) return "Name can't be empty";
return null;
},
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.teal,
)),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.orange,
width: 2,
)),
prefixIcon: Icon(
Icons.person,
color: Colors.green,
),
labelText: "Name",
helperText: "Name can't be empty",
hintText: "Dev Stack",
),
);
}
Widget professionTextField() {
return TextFormField(
//controller: _profession,
validator: (value) {
if (value!.isEmpty) return "Profession can't be empty";
return null;
},
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.teal,
)),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.orange,
width: 2,
)),
prefixIcon: Icon(
Icons.person,
color: Colors.green,
),
labelText: "Profession",
helperText: "Profession can't be empty",
hintText: "Full Stack Developer",
),
);
}
Widget dobField() {
return TextFormField(
// controller: _dob,
validator: (value) {
if (value!.isEmpty) return "DOB can't be empty";
return null;
},
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.teal,
)),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.orange,
width: 2,
)),
prefixIcon: Icon(
Icons.person,
color: Colors.green,
),
labelText: "Date Of Birth",
helperText: "Provide DOB on dd/mm/yyyy",
hintText: "01/01/2020",
),
);
}
Widget titleTextField() {
return TextFormField(
// controller: _title,
validator: (value) {
if (value!.isEmpty) return "Title can't be empty";
return null;
},
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.teal,
)),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.orange,
width: 2,
)),
prefixIcon: Icon(
Icons.person,
color: Colors.green,
),
labelText: "Title",
helperText: "It can't be empty",
hintText: "Flutter Developer",
),
);
}
Widget aboutTextField() {
return TextFormField(
// controller: _about,
validator: (value) {
if (value!.isEmpty) return "About can't be empty";
return null;
},
maxLines: 4,
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.teal,
)),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.orange,
width: 2,
)),
labelText: "About",
helperText: "Write about yourself",
hintText: "I am Dev Stack",
),
);
}
}
main.dart
import 'package:flutter/material.dart';
import 'package:image_uploader/Profile/ProfileScreen.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Profile Section',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: ProfileScreen(),
);
}
}