Flutter set image after selecting from gallery - flutter

File profileImg;
Widget profilePic() {
return Stack(
children: <Widget>[
new Image.file(profileImg),
Positioned(
left: 50.0,
right: 50.0,
bottom: 40.0,
height: 64.0,
child: RaisedGradientButton(
onPressed: () async {
File image= await ImagePicker.pickImage(source:ImageSource.gallery);
image=profileImg;
print(image.path);
},
child: new Text(
"Upload",
style: TextStyle(fontSize: 20.0, color: Colors.white),
),
gradient: LinearGradient(
colors: <Color>[
const Color(0xFF000000),
const Color(0xFF000000),
const Color(0xFF40079B)
],
),
), // child widget
),
]);
}
I have created one image and at the bottom of the image i have one button to select image from the gallery.Before selecting the image from gallery i want to set background color for the image after selecting the image from gallery i want to set the selected image in the imageview

A Minimal Example Of Using Image_picker & FutureBuilder for showing the picked Gallery Image.
Future<File> profileImg;
#override
Widget build(BuildContext context) {
return new Scaffold(
appBar: AppBar(
title: Text("Gallery Image Picker"),
),
body: profilePic());
}
Widget profilePic() {
return ListView(children: <Widget>[
FutureBuilder(
builder: (context, data) {
if (data.hasData) {
return Container(
height: 200.0,
child: Image.file(
data.data,
fit: BoxFit.contain,
height: 200.0,
),
color: Colors.blue,
);
}
return Container(
height: 200.0,
child: Image.network('https://via.placeholder.com/150'),
color: Colors.blue,
);
},
future: profileImg,
),
RaisedButton(
color: Colors.blue,
onPressed: () {
profileImg = ImagePicker.pickImage(source: ImageSource.gallery)
.whenComplete(() {
setState(() {});
});
},
child: new Text(
"Pick Gallery Image",
style: TextStyle(fontSize: 20.0, color: Colors.white),
),
),
]);
}

Related

how to add a fullscreen image in flutter

here's my code and i want a fullscreen image with a centerd button but i won't get that result , screenshot of app in below the code
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Kings of Iran',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: WelcomePage(),
);
}
}
class WelcomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text(
"Kings of Iran",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 40.0,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/back.jpg"),
fit: BoxFit.cover,
alignment: Alignment.center)),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
height: 50.0,
),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => HomePage()),
);
},
child: Text(
"Explore",
style: TextStyle(
fontSize: 20.0, color: Color.fromARGB(255, 191, 211, 9)),
),
)
],
),
),
);
}
}
and this is the result
How can I make this image fullscreen and button centered?
You can use Stack for display image and display button at center of the screen.
Stack : https://api.flutter.dev/flutter/widgets/Stack-class.html
Stack useful if you want to overlap several children in a simple way, for example having some text and an image, overlaid with a gradient and a button attached to the center.
Example :
class WelcomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text(
"Kings of Iran",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 40.0,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
body: Stack(
children: [
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/back.jpg"), fit: BoxFit.cover, alignment: Alignment.center))),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
height: 50.0,
),
Center(child: ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => HomePage()),
);
},
child: Text(
"Explore",
style: TextStyle(fontSize: 20.0, color: Color.fromARGB(255, 191, 211, 9)),
),
))
],
),
],
)
}
}
Just add width: MediaQuery.of(context).size.width in Container

how to show music bar in flutter audio player application

I am developing an audio player application using flutter, I m using on_audio_query package to fetch audio files from storage, and just_audio package for the audio player.
I want to know how to create something like the bar that is shown in this image
thanks in advance
I wrote one solution in a dartpad for you: https://dartpad.dev/?id=491a65532b2f92590c71a48be4836135
As in my example, you can use a stream to update the progress indicator around the play button. Look at my getSecondsFromCurrentMinute method. Replace this with the stream from your package.
Full code:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: Colors.black,
),
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: Colors.black,
body: Align(
alignment: Alignment.bottomCenter,
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
// Get the the seconds from current minute.
//
// TODO: Make this your actual progress indicator
Stream<int> getSecondsFromCurrentMinute() async* {
final now = DateTime.now();
final seconds = now.second;
yield seconds;
await Future.delayed(Duration(seconds: 1 - seconds));
yield* getSecondsFromCurrentMinute();
}
#override
Widget build(BuildContext context) {
return FractionallySizedBox(
heightFactor: .15,
widthFactor: 1,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Song cover
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.white, borderRadius: BorderRadius.circular(10)),
),
// Padding
SizedBox(width: 15),
// Title and artist
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Title
Text(
"AUD-20190208-WA0007",
style: Theme.of(context).textTheme.headline5,
),
// Artist
Text(
"Unknown artist",
style: Theme.of(context)
.textTheme
.bodyText2
?.copyWith(color: Colors.grey.withOpacity(.6)),
),
],
),
// Padding between first 2 columns and Icons
Expanded(child: SizedBox.expand()),
//
// Play button and progress indicator
//
StreamBuilder<int>(
stream: getSecondsFromCurrentMinute(),
builder: (context, AsyncSnapshot<int> snapshot) {
double percentageOfSecond = (snapshot.data ?? 0) / 60;
return Container(
width: 40,
height: 40,
child: Stack(
children: [
// the circle showing progress
Positioned(
top: 0,
left: 0,
child: Container(
width: 40,
height: 40,
child: CircularProgressIndicator(
value: percentageOfSecond,
valueColor: AlwaysStoppedAnimation<Color>(
Colors.red,
),
backgroundColor: Colors.red.withOpacity(0.15),
),
),
),
// the play arrow, inside the circle
Positioned(
top: 0,
left: 0,
child: Container(
width: 35,
height: 35,
child: IconButton(
icon: Icon(
Icons.play_arrow,
color: Colors.red,
),
onPressed: () {},
),
),
),
],
),
);
}),
SizedBox(width: 8),
Container(
width: 40,
height: 40,
child: GestureDetector(
onTap: () {},
child: Icon(
Icons.skip_next,
color: Colors.red,
),
),
),
//
SizedBox(width: 8),
Container(
width: 40,
height: 40,
child: GestureDetector(
onTap: () {},
child: Icon(
Icons.menu,
color: Colors.red,
size: 35,
),
),
),
// Extra padding at the end of the row
SizedBox(width: 30),
],
),
);
}
}
You can use Slider widget to make progress bar.
#override
Widget build(BuildContext context) {
return Slider(
value: position.inSeconds.toDouble(),
min: 0.0,
max: duration.inSeconds.toDouble() ,
onChanged: (value) async {
final position = Duration(seconds: value.toInt());
await player.seek(position);
},
),
And put the duration and position value in the initState()
Duration duration = Duration.zero;
Duration position = Duration.zero;
#override
void initState() {
player.currentPosition.listen((positionValue){
setState(() {
position = positionValue;
});
});
player.current.listen((event) {
setState(() {
duration = event.audio.duration;
});
});

Flutter How to send and show captured image/ video to next page?

I've created a screen where I can use a button to open the camera and take video. And above that button, I made a container to display the video. But I want to show this container containing video to display on the next page. As I am new to flutter, I believe my code is messy. Can you help me with how to do this?
And how to show multiple videos on a screen after taking them through this camera in a loop like this image here?
Here is my code -
class video_record02 extends StatefulWidget {
final Function? onSelectVideo;
const video_record02({Key? key, this.onSelectVideo});
#override
_video_record02State createState() => _video_record02State();
}
class _video_record02State extends State<video_record02> {
String dropdownValue = 'Bedroom';
File? storedVideo;
Future<void> _takeVideo() async {
final picker = ImagePicker();
final videoFile = await picker.pickVideo(
source: ImageSource.camera,
preferredCameraDevice: CameraDevice.rear,
maxDuration: Duration(
seconds: 25,
),
);
if (videoFile == null) {
return;
}
final rlyvideoFile = File(videoFile.path);
setState(() {
storedVideo = rlyvideoFile;
});
final appDir = await syspaths.getApplicationDocumentsDirectory();
final fileName = path.basename(rlyvideoFile.path);
final savedVideo = await rlyvideoFile.copy('${appDir.path}/$fileName');
widget.onSelectVideo?.call(savedVideo);
}
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.white,
body: Center(
child: ListView(
shrinkWrap: true,
children: [
Column(
children: [
Container(
width: 150,
height: 100,
decoration: BoxDecoration(
border: Border.all(
width: 0.5,
color: Colors.grey,
),
),
child: storedVideo != null
? VideoWidget(storedVideo!)
: Text(
'No Video Taken',
textAlign: TextAlign.center,
),
alignment: Alignment.center),
Align(
alignment: Alignment.center,
child: Column(
children: [
IconButton(
icon: Icon(Icons.play_circle_fill),
color: Colors.red,
iconSize: 100.0,
onPressed: _takeVideo,
),
],
),
),
Text(
'Click to start',
style: TextStyle(
fontSize: 25.0,
color: Colors.red,
fontWeight: FontWeight.w300,
),
),
Container(
margin: EdgeInsets.fromLTRB(125, 0, 125, 0),
height: 50,
padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
child: TextButton(
child: Text(
'< Back',
style: TextStyle(fontSize: 17, color: Colors.black),
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => video_record01()),
);
},
),
),
],
),
],
),
),
),
);
}
}

Why is pdf not displaying?

This is my code to show pdf when clicked the button but for some reason, pdf is not displaying. I don't know what to do.
import 'package:flutter/material.dart';
import 'package:pdf_flutter/pdf_flutter.dart';
void main() {
runApp(MaterialApp(
home: MyApp(),
));
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Network PDF Viewer"),
),
body: Center(
child: TextButton(
onPressed: () {
PDF.network(
'https://google-developer-training.github.io/android-developer-fundamentals-course-concepts/en/android-developer-fundamentals-course-concepts-en.pdf',
height: 300,
width: 200,
placeHolder: Image.asset("assets/images/pdf.png",
height: 200, width: 100),
);
},
child: Container(
height: 30,
width: 100,
child: Center(
child: Text(
'Open PDF',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
),
),
),
));
}
}
I want my users to access the pdf by clicking on the button but the pdf is not displaying no matter how many times I click the button.
You cannot use PDF.network as on Pressed method, instead, do it like this
bool openedPDF = false;
Center(
child: TextButton(
onPressed: () {
setState((){openedPDF = true;});
},
child: Container(
height: 30,
width: 100,
child: Center(
child: Text(
'Open PDF',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
),
),
),
));
Visibility(
visible : openedPDF,
child:PDF.network(
'https://google-developer-training.github.io/android-developer-fundamentals-course-concepts/en/android-developer-fundamentals-course-concepts-en.pdf',
height: 300,
width: 200,
placeHolder: Image.asset("assets/images/pdf.png",
height: 200, width: 100),
);
Try this package
flutter_cached_pdfview
PDF().cachedFromUrl(widget.url,
placeholder: (progress) => Center(
child: Text("Loading - $progress %"),
),
errorWidget: (error) => Center(
child: Text("An error occured while opening bill PDF"),
)),
upvote if you find useful

The named parameter 'column' isn't defined. Try correcting the name to an existing named parameter's name

`
Widget build(BuildContext context) {
double height=MediaQuery.of(context).size.height;
double width=MediaQuery.of(context).size.width;
return Scaffold(
appBar: AppBar(
title: Text("Device Details"),
backgroundColor: Colors.black,
),
body : SingleChildScrollView(
child: Container(
**Column**: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
getImageWidget(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
MaterialButton(
color: Colors.green,
child: Text(
"Camera",
style: TextStyle(color: Colors.white),
),
onPressed: () {
getImage(ImageSource.camera);
}),
`The named parameter 'column' isn't defined. Try correcting the name to an existing named parameter's name, or defining a named parameter with the name 'column'. Open documentation.
If I replace column with "body" at column:SingleChildScrollView(
then it is saying as The argument for the named parameter 'body' was already specified.
Please fix my issue by giving your valuable suggestions.
class _MyFormPageState extends State<MyFormPage> {
File _selectedFile;
bool _inProcess = false;
Widget getImageWidget() {
if (_selectedFile != null) {
return Image.file(
_selectedFile,
width: 250,
height: 250,
fit: BoxFit.cover,
);
} else {
return Image.asset(
"assets/placeholder.jpg",
width: 250,
height: 250,
fit: BoxFit.cover,
);
}
}
getImage(ImageSource source) async {
this.setState((){
_inProcess = true;
});
File image = await ImagePicker.pickImage(source: source);
if(image != null){
File cropped = await ImageCropper.cropImage(
sourcePath: image.path,
aspectRatio: CropAspectRatio(
ratioX: 1, ratioY: 1),
compressQuality: 100,
maxWidth: 700,
maxHeight: 700,
compressFormat: ImageCompressFormat.jpg,
androidUiSettings: AndroidUiSettings(
toolbarColor: Colors.deepOrange,
toolbarTitle: "RPS Cropper",
statusBarColor: Colors.deepOrange.shade900,
backgroundColor: Colors.white,
)
);
this.setState((){
_selectedFile = cropped;
_inProcess = false;
});
} else {
this.setState((){
_inProcess = false;
});
}
}
final dbHelper = DatabaseHelper.instance;
String companyname,modelname,series,mfgyear;
#override
Widget build(BuildContext context) {
double height=MediaQuery.of(context).size.height;
double width=MediaQuery.of(context).size.width;
return Scaffold(
body: Stack(
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
getImageWidget(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
MaterialButton(
color: Colors.green,
child: Text(
"Camera",
style: TextStyle(color: Colors.white),
),
onPressed: () {
getImage(ImageSource.camera);
}),
MaterialButton(
color: Colors.deepOrange,
child: Text(
"Device",
style: TextStyle(color: Colors.white),
),
onPressed: () {
getImage(ImageSource.gallery);
})
],
)
],
),
(_inProcess)?Container(
color: Colors.white,
height: MediaQuery.of(context).size.height * 0.95,
child: Center(
child: CircularProgressIndicator(),
),
):Center()
],
),
appBar: AppBar(
title: Text(" Details"),
backgroundColor: Colors.black,
),
**column** : SingleChildScrollView(
child: Container(
decoration: new BoxDecoration(
color: Colors.black,
image: new DecorationImage(
fit: BoxFit.cover,
colorFilter: new ColorFilter.mode(Colors.grey.withOpacity(.5),BlendMode.dstATop),
image: new AssetImage(
"asset/bg00.jpg"
),
),
),
height: height,
width: width,
child: Padding(
padding: const EdgeInsets.all(5),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"Enter the Device Details",
style: TextStyle(
color: Colors.white,
fontSize: 30,
fontWeight: FontWeight.bold,
),
),
TextField(
onChanged: (val){
companyname=val;
},
cursorColor: Colors.black,
style: TextStyle(
height: 1
),
decoration: InputDecoration(
filled: true,
fillColor: Colors.grey[500],
prefixIcon: Icon(Icons.edit,color: Colors.blue[900],),
hintStyle: TextStyle(
color:Colors.black,
),
hintText: "Enter the Company Name",
),
),
SizedBox(
height: 5,
),
Looking at the doc for Scaffold. There is no properties named column indeed.
I think you have your SingleChildScrollView in the wrong place.
It should be un the body which contains a Stack with a Column at the moment. Not sure about what u want to achieve visually but yous might need to check in that direction. (Maybe putting the SingleChildScrollView at the end of said Column)
Check out if there is conflicting in the imported packages, this error has happened with me when I used "Variable" from moor.dart library. I resolved the error by converting the import statement to import 'moor.dart' as moor.
I know I'm too late, but for other people who gets crazy from this error.