I'm a junior (or less than, just 1 month learner) dart/flutter developer. I try to create an sample proflie applicaiton that - Show user's profile image on the main screen. - User can use in-app camera to take photo or select from album and show as personal profile pic.
I have create 2 main viewController.
main.dart
void main() { runApp(new MaterialApp( home: new MyApp(), routes: <String, WidgetBuilder>{ '/screen1': (BuildContext context) => new MyApp(), '/screen3': (BuildContext context) => new UploadAvatarButton() }, )); } class MyApp extends StatefulWidget { final String _images = ""; MyApp(String _images, {Key key}) : super(key: key); @override State<StatefulWidget> createState() { return new MyHomePage(); } } class MyHomePage extends State<MyApp> { @override Widget build(BuildContext context) { Widget myPhoto = new Container( //Attribute child: new FlatButton( child: new Container( decoration: new BoxDecoration( shape: BoxShape.circle, image: new DecorationImage( fit: BoxFit.cover, image: new AssetImage('images/sample.jpg')), ), ), onPressed: _showPersBottomSheetCallBack, ), ); return new MaterialApp( home: new Scaffold( //Header body: new Center( child: new Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ new Container(child: myPhoto),
and 2. cameraView.dart
class UploadAvatarButton extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return new MakeUploadAvatarButtonState();
}
class MakeUploadAvatarButtonState extends State<UploadAvatarButton> {
File _image;
Future getImage() async {
var image = await ImagePicker.pickImage(source: ImageSource.camera);
setState(() {
_image = image;
//Try to send data or image back to main screen
List<int> imageBytes = image.readAsBytesSync();
String base64Image = BASE64.encode(imageBytes);
//send data back
Navigator.push(context, new MaterialPageRoute(builder: (_) =>
new MyApp(_image.)));
});
}
As you can see, I use method to send image back From camera
List<int> imageBytes = image.readAsBytesSync();
String base64Image = BASE64.encode(imageBytes);
Navigator.push(context, new MaterialPageRoute(builder: (_) =>
new MyApp(_image.)));
in to main
final String _images = "";
MyApp(String _images, {Key key}) : super(key: key);
However, I got the error
[dart] The constructor returns type 'dynamic' that isn't of expected type 'Widget'.
Could you please advise me?
Best regards Thank you