Skip to content

Commit

Permalink
chor: image capture, path manupilate
Browse files Browse the repository at this point in the history
  • Loading branch information
sachin96Boy committed Nov 23, 2023
1 parent d7cff53 commit 1618fda
Show file tree
Hide file tree
Showing 13 changed files with 493 additions and 80 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ android {
applicationId "com.example.good_places_app"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion flutter.minSdkVersion
minSdkVersion 21
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
26 changes: 7 additions & 19 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:label="good_places_app"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<application android:label="good_places_app" android:name="${applicationName}" android:icon="@mipmap/ic_launcher">
<activity android:name=".MainActivity" android:exported="true" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<meta-data android:name="io.flutter.embedding.android.NormalTheme" android:resource="@style/NormalTheme" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
<meta-data android:name="flutterEmbedding" android:value="2" />
</application>
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</manifest>
13 changes: 13 additions & 0 deletions lib/providers/places.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:good_places_app/models/place.dart';

Expand All @@ -9,4 +11,15 @@ class Places with ChangeNotifier {
List<Place> get places {
return [..._places];
}

void addPlace(String title, File image) {
final newPlace = Place(
id: DateTime.now().toString(),
title: title,
location: LatLang(latitude: 2.0, longitude: 3.0),
image: image);

_places.add(newPlace);
notifyListeners();
}
}
104 changes: 64 additions & 40 deletions lib/screens/add_place_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:good_places_app/providers/places.dart';
import 'package:good_places_app/widgets/image_input.dart';
import 'package:provider/provider.dart';

class AddPlaceScreen extends StatefulWidget {
static const routeName = '/add-place';
Expand All @@ -11,53 +16,72 @@ class AddPlaceScreen extends StatefulWidget {

class _AddPlaceScreenState extends State<AddPlaceScreen> {
final titleController = TextEditingController();
File _pickedImage = File('');

void _selectImage(File imageFile) {
_pickedImage = imageFile;
}

void _savePlace() {
if (titleController.text.isEmpty || _pickedImage.path == '') {
return;
}

Provider.of<Places>(context, listen: false)
.addPlace(titleController.text, _pickedImage);
GoRouter.of(context).pop();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Add New Place'),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
children: [
TextField(
decoration: const InputDecoration(labelText: 'Title'),
controller: titleController,
),
const SizedBox(
height: 10,
),
const ImageInput()
],
return SafeArea(
child: Scaffold(
appBar: AppBar(
title: const Text('Add New Place'),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
children: [
TextField(
decoration: const InputDecoration(labelText: 'Title'),
controller: titleController,
),
const SizedBox(
height: 10,
),
ImageInput(
onSelectImage: _selectImage,
)
],
),
),
),
)),
ElevatedButton.icon(
onPressed: () {},
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
elevation: 0,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
icon: const Icon(
Icons.add,
color: Colors.white,
),
label: const Text(
'Add Place',
style: TextStyle(
)),
ElevatedButton.icon(
onPressed: _savePlace,
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
elevation: 0,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
icon: const Icon(
Icons.add,
color: Colors.white,
),
label: const Text(
'Add Place',
style: TextStyle(
color: Colors.white,
),
),
),
),
],
],
),
),
);
}
Expand Down
49 changes: 34 additions & 15 deletions lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,47 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:good_places_app/providers/places.dart';
import 'package:good_places_app/screens/add_place_screen.dart';

import 'package:provider/provider.dart';

class HomeScreen extends StatelessWidget {
static const routeName = '/';
const HomeScreen({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Great Places'),
actions: [
IconButton(
onPressed: () {
GoRouter.of(context).pushNamed(AddPlaceScreen.routeName);
},
icon: const Icon(Icons.add),
),
],
),
body: const Center(
child: Text('This is boy'),
return SafeArea(
child: Scaffold(
appBar: AppBar(
title: const Text('Great Places'),
actions: [
IconButton(
onPressed: () {
GoRouter.of(context).pushNamed(AddPlaceScreen.routeName);
},
icon: const Icon(Icons.add),
),
],
),
body: Consumer<Places>(
child: const Center(child: Text('No Places Available')),
builder: (context, value, child) => value.places.isEmpty
? Center(child: child)
: ListView.builder(
itemCount: value.places.length,
itemBuilder: (context, index) {
return ListTile(
leading: CircleAvatar(
backgroundImage: FileImage(value.places[index].image),
),
title: Text(value.places[index].title),
onTap: () {
// go to detail page
},
);
},
),
),
),
);
}
Expand Down
32 changes: 28 additions & 4 deletions lib/widgets/image_input.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';

import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';

class ImageInput extends StatefulWidget {
const ImageInput({super.key});
final Function onSelectImage;

const ImageInput({super.key, required this.onSelectImage});

@override
State<ImageInput> createState() => _ImageInputState();
}

class _ImageInputState extends State<ImageInput> {
final File _storedImage = File('path');
File _storedImage = File('');
final ImagePicker picker = ImagePicker();

Future<void> _takePicture() async {
final imageFile = await picker.pickImage(
source: ImageSource.camera,
maxWidth: 600,
);

setState(() {
_storedImage = File(imageFile!.path);
});

final Directory appDocumentsDir = await getApplicationDocumentsDirectory();
final fileName = p.basename(imageFile!.path);
final savedImage =
await _storedImage.copy('${appDocumentsDir.path}/$fileName');
widget.onSelectImage(savedImage);
}

@override
Widget build(BuildContext context) {
Expand All @@ -22,7 +46,7 @@ class _ImageInputState extends State<ImageInput> {
decoration:
BoxDecoration(border: Border.all(width: 1, color: Colors.grey)),
alignment: Alignment.center,
child: _storedImage != null
child: _storedImage.path != ''
? Image.file(
_storedImage,
fit: BoxFit.cover,
Expand All @@ -37,7 +61,7 @@ class _ImageInputState extends State<ImageInput> {
width: 10,
),
TextButton.icon(
onPressed: () {},
onPressed: _takePicture,
icon: const Icon(Icons.camera),
label: const Text('Take pecture'),
)
Expand Down
4 changes: 4 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

#include "generated_plugin_registrant.h"

#include <file_selector_linux/file_selector_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);
}
1 change: 1 addition & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
file_selector_linux
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
4 changes: 4 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import FlutterMacOS
import Foundation

import file_selector_macos
import path_provider_foundation

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
}
Loading

0 comments on commit 1618fda

Please sign in to comment.