Flutter build not running with geocoding and location package - flutter

I tried to run a simple project but i gives me errors:
Launching lib\main.dart on ASUS Z01QD in debug mode...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugResources'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Failed to transform play-services-base-16.0.1.aar (com.google.android.gms:play-services-base:16.0.1) to match attributes {artifactType=android-compiled-dependencies-resources, org.gradle.status=release}.
> Execution failed for AarResourcesCompilerTransform: C:\Users\win\.gradle\caches\transforms-2\files-2.1\f260781842f212c36494d469961b4620\jetified-play-services-base-16.0.1.
> AAPT2 aapt2-4.1.0-6503028-windows Daemon #0: Unexpected error during compile 'C:\Users\win\.gradle\caches\transforms-2\files-2.1\f260781842f212c36494d469961b4620\jetified-play-services-base-16.0.1\res\drawable-xhdpi-v4\common_google_signin_btn_text_dark_normal_background.9.png', attempting to stop daemon.
This should not happen under normal circumstances, please file an issue if it does.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1m 58s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
main.dart ->
import 'package:flutter/material.dart';
import 'package:locationflutter/splashscreen.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: SplashScreen(),
);
}
}
splashscreen.dart
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:location/location.dart';
import 'package:locationflutter/location_service.dart';
import 'package:locationflutter/mainscreen.dart';
class SplashScreen extends StatefulWidget {
const SplashScreen({Key? key}) : super(key: key);
#override
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
#override
void initState() {
super.initState();
locationService();
}
Future<void> locationService() async {
Location location = new Location();
bool _serviceEnabled;
PermissionStatus _permissionLocation;
LocationData _locData;
_serviceEnabled = await location.serviceEnabled();
if(!_serviceEnabled) {
_serviceEnabled = await location.requestService();
if (!_serviceEnabled) {
return;
}
}
_permissionLocation = await location.hasPermission();
if(_permissionLocation == PermissionStatus.denied) {
_permissionLocation = await location.requestPermission();
if(_permissionLocation != PermissionStatus.granted) {
return;
}
}
_locData = await location.getLocation();
setState(() {
UserLocation.lat = _locData.latitude!;
UserLocation.long = _locData.longitude!;
});
Timer(Duration(milliseconds: 500), () {
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context) => MainScreen()));
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text("WELCOME"),
),
);
}
}
mainscreen.dart
import 'package:flutter/material.dart';
import 'package:geocoding/geocoding.dart';
import 'package:locationflutter/location_service.dart';
class MainScreen extends StatefulWidget {
const MainScreen({Key? key}) : super(key: key);
#override
_MainScreenState createState() => _MainScreenState();
}
class _MainScreenState extends State<MainScreen> {
String country = '';
String name = '';
String street = '';
String postalCode = '';
#override
void initState() {
super.initState();
getLocation();
}
Future<void> getLocation() async {
List<Placemark> placemark = await placemarkFromCoordinates(UserLocation.lat, UserLocation.long);
print(placemark[0].country);
print(placemark[0].name);
print(placemark[0].street);
print(placemark[0].postalCode);
setState(() {
country = placemark[0].country!;
name = placemark[0].name!;
street = placemark[0].street!;
postalCode = placemark[0].postalCode!;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Lat : " + "${UserLocation.lat}"),
Text("Long : " + "${UserLocation.long}"),
Text("Country : " + "$country"),
Text("Name : " + "$name"),
Text("Street : " + "$street"),
Text("PostalCode : " + "$postalCode"),
],
),
),
);
}
}
location_service.dart
class UserLocation {
static double lat = 0;
static double long = 0;
}
pubspec.yaml
name: locationflutter
description: A new Flutter project.
# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
location: ^4.3.0
geocoding: ^2.0.1
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.8.1, on Microsoft Windows [Version 10.0.19043.1415], locale
en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.0.4)
[√] Android Studio (version 2020.3)
[√] VS Code (version 1.63.2)
[√] Connected device (4 available)
! Device 127.0.0.1:5555 is offline.
• No issues found!
I don't know what am I doing wrong.

I Fixed this issue by:
In gradle-wrapper.properties I defined Gradle version 6.1.1
by adding at the last of the file
distributionUrl=https://services.gradle.org/distributions/gradle-6.1.1-all.zip
And in the project-level build.gradle I set version 4.0.2
by adding
classpath 'com.android.tools.build:gradle:4.0.2'
reference: solution

Related

FirebaseException ([cloud_firestore/unavailable] The service is currently unavailable , and how to solve it

i created a simple app using flutter and firebase it all work well but when i click on profile icon from the navigationbar the app froze
Profile page code:
import 'package:cached_network_image/cached_network_image.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:yumor/models/progress.dart';
import 'package:yumor/models/user_model.dart';
class profile extends StatefulWidget {
const profile({Key? key,required this.userProfile}) : super(key: key);
final String? userProfile;
#override
State<profile> createState() => _profileState();
}
class _profileState extends State<profile> {
final userRef = FirebaseFirestore.instance.collection('users');
buildprofileheader(){
return FutureBuilder(future:userRef.doc(widget.userProfile).get(),
builder: ((context, snapshot) {
if(!snapshot.hasData){
return CircularProgress();
}
UserModel user=UserModel.fromMap(Map);
return Padding(padding:EdgeInsets.all(16.0),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.account_circle, size: 90,)
],
),
Container(
alignment: Alignment.center,
padding: EdgeInsets.all(12.0),
child: Text(
user.Username as String,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize:16.0,
),
),
),
],
),
);
}),
);
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text(
"Profile",
),
),
body: ListView(children: <Widget>[
// buildprofileHeader(),
]));
}
}
navigation Bar source code
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:yumor/models/user_model.dart';
import 'package:yumor/pages/Home_page.dart';
import 'package:yumor/pages/profile.dart';
import 'package:yumor/pages/search.dart';
import 'package:yumor/pages/upload.dart';
class BottomBar extends StatefulWidget {
const BottomBar({Key? key}) : super(key: key);
#override
State<BottomBar> createState() => _BottomBarState();
}
class _BottomBarState extends State<BottomBar> {
List pages = [
home_page(),
search(),
upload(),
profile(userProfile:FirebaseAuth.instance.currentUser!.uid),
];
// this current index means that this index depends on which one you click form 0 to 4
int currentIndex = 0;
void onTap(int index) {
// currentindex equale to index to take value
setState(() {
currentIndex = index;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: pages[currentIndex],
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
selectedFontSize: 0,
unselectedFontSize: 0,
onTap: onTap,
currentIndex: currentIndex,
backgroundColor: Colors.white,
selectedItemColor: Colors.black87,
unselectedItemColor: Colors.grey.shade600.withOpacity(0.6),
elevation: 0,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home_outlined), label: 'home'),
BottomNavigationBarItem(icon: Icon(Icons.search), label: 'search'),
BottomNavigationBarItem(
icon: Icon(Icons.add_box_outlined), label: 'add'),
BottomNavigationBarItem(
icon: Icon(Icons.person_outline_rounded), label: 'profile'),
]),
);
}
}
firebase user creation code
import 'package:flutter/foundation.dart';
class UserModel {
String? uid;
String? Username;
String? email;
String? photoUrl;
UserModel(
{this.uid, this.email, this.Username, this.photoUrl});
// receving data from the server
factory UserModel.fromMap(Map) {
return UserModel(
uid: Map['userId'],
Username: Map['Username'],
email: Map['email'],
photoUrl: Map['photoUrl'],
);
}
// /// sending data to firestore
Map<String, dynamic> toMap() {
return {
'userId': uid,
'Username': Username,
'email': email,
'photoUrl': photoUrl,
};
}
}
error_patch.dart
#patch
#pragma("vm:external-name", "Error_throwWithStackTrace")
external static Never _throw(Object error, StackTrace stackTrace);
}
NOTE
flutter doctor -v
[
[√] Flutter (Channel stable, 3.3.5, on Microsoft Windows [Version 10.0.19044.2130], locale en-US)
• Flutter version 3.3.5 on channel stable at C:\Dart\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision d9111f6402 (8 days ago), 2022-10-19 12:27:13 -0700
• Engine revision 3ad69d7be3
• Dart version 2.18.2
• DevTools version 2.15.0
Checking Android licenses is taking an unexpectedly long time...[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at C:\Users\Abdou\AppData\Local\Android\Sdk
• Platform android-33, build-tools 33.0.0
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
• All Android licenses accepted.
[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[X] Visual Studio - develop for Windows
X Visual Studio not installed; this is necessary for Windows development.
Download at https://visualstudio.microsoft.com/downloads/.
Please install the "Desktop development with C++" workload, including all of its default components
[√] Android Studio (version 2021.2)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
[√] VS Code, 64-bit edition (version 1.72.2)
• VS Code at C:\Program Files\Microsoft VS Code
• Flutter extension version 3.50.0
[√] Connected device (3 available)
• Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 7.0 (API 24) (emulator)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19044.2130]
• Edge (web) • edge • web-javascript • Microsoft Edge 106.0.1370.52
[√] HTTP Host Availability
• All required HTTP hosts are available ]
my pubspec.yaml
name: yumor
description: A new Flutter project.
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.16.1 <3.0.0"
# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
cached_network_image: ^3.2.0
cloud_firestore: ^3.1.10
cupertino_icons: ^1.0.2
email_validator: ^2.0.1
firebase_auth: ^3.3.9
firebase_core: ^1.13.1
firebase_storage: ^10.2.15
flutter:
sdk: flutter
flutter_native_splash: ^2.2.9
flutter_svg: ^1.0.3
fluttertoast: ^8.0.9
get: ^4.6.5
image_picker: ^0.8.5
dev_dependencies:
flutter_lints: ^2.0.1
flutter_test:
sdk: flutter
flutter_native_splash:
background_image: assets/splashcreen.png
image: assets/start_logo.png
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- assets/yumor-logo.png
- assets/search_page.svg
- assets/upload_page.svg
- assets/user.png
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
import 'package:cached_network_image/cached_network_image.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:yumor/models/progress.dart';
import 'package:yumor/models/user_model.dart';
class profile extends StatefulWidget {
const profile({Key? key,required this.userProfile}) : super(key: key);
final String? userProfile;
#override
State<profile> createState() => _profileState();
}
class _profileState extends State<profile> {
final userRef = FirebaseFirestore.instance.collection('users');
final doc = await docRef.doc(docId).get();
if (doc.exists) {
data = doc.data();
}
buildprofileheader(){
return FutureBuilder( return FutureBuilder(future:doc,
builder: ((context, snapshot) {
if(!snapshot.hasData){
return CircularProgress();
}
UserModel user=UserModel.fromMap(Map);
return Padding(padding:EdgeInsets.all(16.0),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.account_circle, size: 90,)
],
),
Container(
alignment: Alignment.center,
padding: EdgeInsets.all(12.0),
child: Text(
user.Username as String,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize:16.0,
),
),
),
],
),
);
}),
);
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text(
"Profile",
),
),
body: ListView(children: <Widget>[
// buildprofileHeader(),
]));
}
}

Error running sample Flutter Provider program

I am trying to run sample Riverpod program from Getting started Riverpod page
Pubspec is specified as given on the page.
Debug Console dumps the following message:
Launching lib/main.dart on Chrome in debug mode...
lib/main.dart:1
: Error: Method not found: 'Error.throwWithStackTrace'.
../…/framework/provider_base.dart:985
Error.throwWithStackTrace(error, chain);
^^^^^^^^^^^^^^^^^^^
: Error: A non-null value must be returned since the return type 'Never' doesn't
allow null.
../…/framework/provider_base.dart:979
Never _rethrowProviderError(Object error, StackTrace stackTrace) {
^
Failed to compile application.
Exited (sigterm)
Just to be sure, following is main.dart:
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
// We create a "provider", which will store a value (here "Hello world").
// By using a provider, this allows us to mock/override the value exposed.
final helloWorldProvider = Provider((_) => 'Hello world');
void main() {
runApp(
// For widgets to be able to read providers, we need to wrap the entire
// application in a "ProviderScope" widget.
// This is where the state of our providers will be stored.
const ProviderScope(
child: MyApp(),
),
);
}
// Extend ConsumerWidget instead of StatelessWidget, which is exposed by Riverpod
class MyApp extends ConsumerWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context, WidgetRef ref) {
final String value = ref.watch(helloWorldProvider);
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Example')),
body: Center(
child: Text(value),
),
),
);
}
}
And pubspec is as follows:
name: simple_app
description: A new Flutter project.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: ">=2.12.0 <3.0.0"
flutter: ">=2.0.0"
dependencies:
flutter:
sdk: flutter
flutter_riverpod: ^2.0.0-dev.4
cupertino_icons: ^1.0.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^1.0.0
flutter:
uses-material-design: true
Environment:
Flutter (Channel stable, 2.5.3, on macOS 12.2.1 21D62 darwin-x64, locale en-US)

How to get user mobile number in flutter android and iOS

How to get user mobile number in flutter android and iOS.
final String mobileNumber = await MobileNumber.mobileNumber;
simple complete example
flutter main.dart file
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:mobile_number/mobile_number.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _mobileNumber = '';
List<SimCard> _simCard = <SimCard>[];
#override
void initState() {
super.initState();
MobileNumber.listenPhonePermission((isPermissionGranted) {
if (isPermissionGranted) {
initMobileNumberState();
} else {}
});
initMobileNumberState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initMobileNumberState() async {
if (!await MobileNumber.hasPhonePermission) {
await MobileNumber.requestPhonePermission;
return;
}
String mobileNumber = '';
// Platform messages may fail, so we use a try/catch PlatformException.
try {
mobileNumber = (await MobileNumber.mobileNumber)!;
_simCard = (await MobileNumber.getSimCards)!;
} on PlatformException catch (e) {
debugPrint("Failed to get mobile number because of '${e.message}'");
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_mobileNumber = mobileNumber;
});
}
Widget fillCards() {
List<Widget> widgets = _simCard
.map((SimCard sim) => Text(
'Sim Card Number: (${sim.countryPhonePrefix}) - ${sim.number}\nCarrier Name: ${sim.carrierName}\nCountry Iso: ${sim.countryIso}\nDisplay Name: ${sim.displayName}\nSim Slot Index: ${sim.slotIndex}\n\n'))
.toList();
return Column(children: widgets);
}
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
children: <Widget>[
Text('Running on: $_mobileNumber\n'),
fillCards()
],
),
),
),
);
}
}
pubspec.yaml file
name: flutter_mobilenumber
description: A new Flutter application.
# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
mobile_number: ^1.0.4
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
android app build.gradle file
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.flutter_mobilenumber"
minSdkVersion 17
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
here result :
[![enter image description here][1]][1]
details in link

I have a generated a QR code but the source code does not scan the generated QR code

I have a generated a QR code but the source code does not scan the generated QR code.
I have a QR code scanner template but it does not scan the generated QR code.
It can only Generate a QR code but it does not scan the Code.
The onPressed method is supposed to be scanning the generated code.
I get this error when I click the floating Button
Unhandled Exception: MissingPluginException(No implementation found for method scanBarcode on channel flutter_barcode_scanner)
import 'package:flutter/material.dart';
//import 'package:qr_flutter/qr_flutter.dart';
//import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart';
//import 'package:qr_code';;
import 'package:qrscan/qrscan.dart' as scanner;
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
title: "flutter Demo",
theme: ThemeData(
primaryColor: Colors.blue,
),
home: MyHomePage(title: "Flutter QR"),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String barcode = "";
Future scanBarcode() async {
String barcodeResult = await scanner.scan();
setState(() {
barcode = barcodeResult;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
children: <Widget>[
/*QrImage(
data: "Savanna, R25",
backgroundColor: Colors.white,
size: 200,
)*/
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () => scanBarcode(),
tooltip: "increment",
child: Icon(Icons.add),
),
);
}
}
My Pubspec.yaml file with plugins
name: fluttersqflite
description: A new Flutter application.
# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.0
qr_flutter: ^3.0.1
flutter_barcode_scanner: ^0.1.7
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
Give a try to this plugin- qrscan
and in your dart file write this:-
import 'package:qrscan/qrscan.dart' as scanner;
Function for scan:-
Future _scan() async {
String barcode = await scanner.scan();
setState(() {
barcode = barcodeResult;
});
}
And in your floating action button:-
floatingActionButton: FloatingActionButton(
onPressed: ()=>_scan(),
tooltip: "increment",
child: Icon(Icons.add),
),
And ya remember to add permission for this dependency

TypeAdapterGenerator:- Missing concrete implementation of 'getter TypeAdapter.typeId Try implementing the missing method

I'm learning Hive db in Flutter. When I use Flutter packages pub run build_runner build command its generate the data.g.dart file in it its has an error.
The full error:
{
"resource": "/E:/Mywork/AndroidApps/hive_todo/lib/data.g.dart",
"owner": "dart",
"code": "non_abstract_class_inherits_abstract_member",
"severity": 8,
"message": "Missing concrete implementation of 'getter TypeAdapter.typeId'.\nTry implementing the missing method, or make the class abstract.",
"source": "dart",
"startLineNumber": 9,
"startColumn": 7,
"endLineNumber": 9,
"endColumn": 18,
"tags": []
}
the data.g.dart code:
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'data.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class dataAdapter extends TypeAdapter<data> {
#override
data read(BinaryReader reader) {
var numOfFields = reader.readByte();
var fields = <int, dynamic>{
for (var i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return data(
todo: fields[0] as String,
val: fields[1] as int,
);
}
#override
void write(BinaryWriter writer, data obj) {
writer
..writeByte(2)
..writeByte(0)
..write(obj.todo)
..writeByte(1)
..write(obj.val);
}
}
The data.dart code:
import 'package:hive/hive.dart';
part 'data.g.dart';
#HiveType()
class data {
#HiveField(0)
final String todo;
#HiveField(1)
final int val;
data({this.todo,this.val});
}
The main method code:
import 'package:flutter/material.dart';
import 'package:hive/hive.dart';
import 'package:path_provider/path_provider.dart' as path_provider;
import 'data.dart';
import 'todo_page.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final appDocumentDir = await path_provider.getApplicationDocumentsDirectory();
Hive.init(appDocumentDir.path);
Hive.registerAdapter(dataAdapter());
runApp(MyApp());
}
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Hive Todo',
home: FutureBuilder(
future: Hive.openBox('data'),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasError)
return Text(snapshot.error.toString());
else
return Todo_Page();
}
// Although opening a Box takes a very short time,
// we still need to return something before the Future completes.
else
return Scaffold(backgroundColor: Colors.red);
},
),
);
}
#override
void dispose() {
Hive.close();
super.dispose();
}
}
If I do quick fix, then the error is gone, but when I register the adapter in the main method
Hive.registerAdapter(dataAdapter(), 0);
it only gives error because of typeId. When I remove it,
Hive.registerAdapter(dataAdapter());
then it doesn't gives error. But I want the typeId in it.
My pubspec.yaml:
name: hive_todo
description: A new Flutter project.
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.5.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
hive: ^1.2.0
hive_flutter: ^0.2.1
# For OS-specific directory paths
path_provider: ^1.3.1
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_test:
sdk: flutter
hive_generator: ^0.5.1
build_runner:
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
I had a similar issue and found this solution on the hivedb/hive GitHub page:
In pubspec.yaml, use hive: 1.2.0 without the carat symbol in your dependencies.