Untitled
Anonymous
dart
12/21/2023 8:53 PM
2.4 KB
15
Indexable
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Изображение из галереи',
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
File? image;
TextEditingController nameController = TextEditingController();
TextEditingController surnameController = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Изображение из галереи'),
),
body: Center(
child: Column(
children: [
image != null
? Image.file(image!)
: Text('Изображение не выбрано'),
TextField(
controller: nameController,
decoration: InputDecoration(
labelText: 'Имя',
),
),
TextField(
controller: surnameController,
decoration: InputDecoration(
labelText: 'Фамилия',
),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () async {
final pickedFile = await ImagePicker().pickImage(source: ImageSource.gallery);
if (pickedFile != null) {
image = File(pickedFile.path);
setState(() {});
}
},
child: Icon(Icons.photo),
),
);
}
}
Editor is loading...
Leave a Comment