Wrong colors in Toggle button widget icons - flutter

I have a toggle button widget added to the appbar in the actions section. This is how it looks:
As you see icon colors are not correct. The selected one color is the same color as the appbar and the other icons show black. Oddly, the other icon added to the appbar outside the Toggle button widget is white:
import 'package:flutter/material.dart';
void main() async {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Project',
home: Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text("Game Manager"),
actions: [
Row(children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: ToggleButtons(
borderRadius: const BorderRadius.all(Radius.circular(8)),
/*borderColor: Colors.blue,
selectedBorderColor: Colors.blue[200],
selectedColor: Colors.white,
fillColor: Colors.blue[300],
color: Colors.blue[300],*/
onPressed: (int i) => print("pressed!"),
isSelected: const [true,false,false],
children: [
Tooltip(message: "sort_by_name", child: const Icon(Icons.receipt)),
Tooltip(message: "sort_by_status", child: const Icon(Icons.stars)),
Tooltip(message: "sort_by_size", child: const Icon(Icons.storage))
]),
),
IconButton(
onPressed: () {
print("Yeah");
},
icon: const Icon(Icons.unfold_less),
tooltip: "fold_all",
),
IconButton(
onPressed: null,
icon: Icon(Icons.refresh),
tooltip: "refresh",
),
]
)
]),
body: Container()
),
);
}
}
PubSpec.yaml:
name: project
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 is used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.0+1
environment:
sdk: '>=2.18.4 <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:
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.2
dev_dependencies:
flutter_test:
sdk: flutter
# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^2.0.0
# 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 packages.
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/images/logo.png
- assets/translations/

Related

Flutter app on android nougat (7.0.0) restarting the device

I had reports of users telling my app restarts the device on android 7.0.0 I tried it on the emulator and that is true. I started trying a lot of things I thought it could be a package or something.
what I finished doing is trying in a whole new project the default app that flutter creates. I tried it in the same version android 7.0.0 and there wasn't any problem.
I grabbed and pasted the main.dart from the default in my project and it keeps closing. I'll show the code just in case:
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// 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: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
#override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
#override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
It's just the default code. This is what throws in the debug console before it restarts the device:
✓ Built build/app/outputs/flutter-apk/app-debug.apk.
D/FlutterGeolocator( 8847): Attaching Geolocator to activity
D/FlutterGeolocator( 8847): Creating service.
D/FlutterGeolocator( 8847): Binding to location service.
D/FlutterLocationService( 8847): Creating service.
D/FlutterLocationService( 8847): Binding to location service.
D/FlutterGeolocator( 8847): Geolocator foreground service connected
D/FlutterGeolocator( 8847): Initializing Geolocator services
D/FlutterGeolocator( 8847): Flutter engine connected. Connected engine count 1
Connecting to VM Service at ws://127.0.0.1:61877/QRHypptu-ro=/ws
Lost connection to device.
Exited
Here's my pubspec.yaml
# 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: 2.1.2+21
environment:
sdk: ">=2.17.0 <3.7.3"
dependencies:
age_calculator: ^1.0.0
animate_do: ^3.0.2
appinio_swiper: ^1.0.3
badges: ^2.0.3
cached_network_image: ^3.2.1
carousel_images: ^1.1.2
carousel_slider: ^4.1.1
chat_bubbles: ^1.2.0
cloud_firestore: ^4.1.0
cupertino_icons: ^1.0.2
date_time_picker: ^2.1.0
dio: ^4.0.6
email_validator: ^2.0.1
equatable: ^2.0.3
extended_image: ^6.2.1
faker: ^2.0.0
firebase_auth: ^4.1.4
firebase_core: ^2.3.0
firebase_database: ^10.0.6
firebase_storage: ^11.0.6
flutter:
sdk: flutter
flutter_bloc: ^8.1.2
flutter_cache_manager: ^3.3.0
flutter_dotenv: ^5.0.2
flutter_feather_icons: ^2.0.0+1
flutter_form_builder: ^7.2.1
flutter_google_places: ^0.3.0
flutter_localizations:
sdk: flutter
flutter_markdown: ^0.6.13
flutter_native_splash: ^2.2.12
flutter_secure_storage: ^6.0.0
flutter_svg: ^1.1.3
geocoder2: ^1.4.0
geolocator: ^9.0.2
google_fonts: ^3.0.1
google_maps_flutter: ^2.2.1
google_sign_in: ^5.3.1
gradient_borders: ^0.2.0
http: ^0.13.5
image_picker: ^0.8.5+3
insta_image_viewer: ^1.0.2
intl: ^0.17.0
jiffy: ^5.0.0
jwt_decode: ^0.3.1
loading_animation_widget: ^1.2.0+2
location: ^4.4.0
lottie: ^1.4.2
marquee: ^2.2.3
permission_handler: ^10.1.0
photo_view: ^0.14.0
pinch_zoom: ^1.0.0
preload_page_view: ^0.1.6
provider: ^6.0.4
share_plus: ^4.5.2
shared_preferences: ^2.0.15
shimmer: ^2.0.0
simple_gradient_text: ^1.2.3
text_scroll: ^0.1.2
theme_provider: ^0.5.0
url_launcher: ^6.1.8
video_player: ^2.4.7
zoom_pinch_overlay: ^1.2.0
dev_dependencies:
flutter_launcher_icons: ^0.11.0
flutter_lints: ^2.0.1
flutter_test:
sdk: flutter
flutter_native_splash:
background_image: assets/img/brand/gradient.png
background_image_dark: assets/img/brand/gradientBlack.png
image: assets/img/others/splash.png
image_dark: assets/img/brand/wikenLogoBlack.png
branding: assets/img/brand/WikenBrand.png
branding_dark: assets/img/brand/WikenBrandBlack.png
android_12:
image: assets/img/brand/12logo.png
image_dark: assets/img/brand/13logo.png
color: "#EE7E58"
color_dark: "#1F1F1F"
flutter_icons:
android: true
ios: true
image_path: "assets/app_logo.png"
adaptative_icon_background: "#ffffff"
adaptative_icon_foreground: "assets/img/brand/logo_foreground.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:
- .env
- assets/
- assets/img/
- assets/img/alertas/
- assets/img/brand/
- assets/img/login/
- assets/img/maps/
- assets/img/others/
- assets/img/placeholder/
- assets/img/muestra/
- assets/img/uploadScreen/
- assets/img/tutorial/
- assets/svg/
- assets/ca/
fonts:
- family: Montserrat
fonts:
- asset: assets/fonts/Montserrat-Regular.ttf
- asset: assets/fonts/Montserrat-Italic-VariableFont_wght.ttf
weight: 100
- asset: assets/fonts/Montserrat-Light.ttf
weight: 300
- asset: assets/fonts/Montserrat-Medium.ttf
weight: 500
- asset: assets/fonts/Montserrat-SemiBold.ttf
weight: 600
- asset: assets/fonts/Montserrat-Bold.ttf
weight: 700
- family: Montserrat Alternates
fonts:
- asset: assets/fonts/MontserratAlternates-Regular.ttf
- asset: assets/fonts/MontserratAlternates-Bold.ttf
weight: 700
I have already run flutter clean, flutter pub get, flutter upgrade. I'm on flutter 3.7.3
I hope you can help me! Thanks in advance.

Flutter & Sqflite: MissingPluginException(No implementation found for method getDatabasesPath on channel com.tekartik.sqflite)

I'm currently trying to create a DB in my flutter app.
In a database.dart file I have:
void CreateBD() async{
WidgetsFlutterBinding.ensureInitialized();
final database = openDatabase(
//on choisi le path de la bd
join(await getDatabasesPath(), 'hyrule_database.db'),
//initialisation des tables
onCreate: (db, version) {
// Run the CREATE TABLE statement on the database.
return db.execute(
'CREATE TABLE foods(id INTEGER PRIMARY KEY, name TEXT,image TEXT, description TEXT, cookingEffect TEXT, category TEXT, commonLocations list<TEXT>, heartsRecovered INTEGER);'
'CREATE TABLE nonfoods(id INTEGER PRIMARY KEY, name TEXT,image TEXT, description TEXT,category TEXT, commonLocations list<TEXT>, drops list<TEXT>);'
'CREATE TABLE equipments(id INTEGER PRIMARY KEY, name TEXT,image TEXT, description TEXT, attack INTEGER, category TEXT, commonLocations list<TEXT>, defense INTEGER);'
'CREATE TABLE materials(id INTEGER PRIMARY KEY, name TEXT,image TEXT, description TEXT, cookingEffect TEXT, category TEXT, commonLocations list<TEXT>, heartsRecovered INTEGER);'
'CREATE TABLE monsters(id INTEGER PRIMARY KEY, name TEXT,image TEXT, description TEXT, category TEXT, commonLocations list<TEXT>, drops list<TEXT>);'
'CREATE TABLE treasure(id INTEGER PRIMARY KEY, name TEXT,image TEXT, description TEXT, category TEXT, commonLocations list<TEXT>, drops list<TEXT>)',
);
},
//version afin de laisser la posibilité de upgrade et downgrade
version: 1,
);
}
Future<Database> connectBD()async{
final database = openDatabase(
join(await getDatabasesPath(), 'hyrule_database.db'),
);
return database;
}
And for every table i've create CRUD functions , here an exemple with food table:
// Insertion
Future<void> insertFood(Food food) async {
final db = await connectBD();
await db.insert(
'foods',
food.toMap(),
conflictAlgorithm: ConflictAlgorithm.replace,
);
}
//récupération
Future<List<Food>> foods() async {
final db = await connectBD();
final List<Map<String, dynamic>> maps = await db.query('foods');
return List.generate(maps.length, (i) {
return Food(
id: maps[i]['id'],
name: maps[i]['name'],
image: maps[i]['image'],
heartsRecovered: maps[i]['hearts_recovered'],
description: maps[i]['description'],
cookingEffect: maps[i]['cooking_effect'],
commonLocations: maps[i]['common_locations'],
category: maps[i]['category'],
);
});
}
//update
Future<void> updateFood(Food food) async {
final db = await connectBD();
await db.update(
'foods',
food.toMap(),
where: 'id = ?',
whereArgs: [food.id],
);
}
//delete
Future<void> deleteFood(int id) async {
final db = await connectBD();
await db.delete(
'foods',
where: 'id = ?',
whereArgs: [id],
);
}
Then I try to execute the creation, and I only end up with the error :
Error: MissingPluginException(No implementation found for method getDatabasesPath on channel com.tekartik.sqflite)
the file I use to execute look like :
import 'package:flutter/material.dart';
import 'package:projet_flutter/Utils/hyrule_bd.dart';
import 'package:projet_flutter/Utils/fill_bd.dart';
import 'package:projet_flutter/models/food_model.dart';
import 'dart:async';
import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';
class TestApp extends StatefulWidget {
#override
State<StatefulWidget> createState() => _TestState();
}
class _TestState extends State<TestApp> {
#override
void initState() {
super.initState();
}
#override
Widget build(BuildContext context) {
CreateBD();
//remplirBD();
return MaterialApp(
title: 'Fetch Data Example',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
title: const Text('Fetch Data Example'),
),
body: Center(
child:FutureBuilder<List<Food>>(
future: foods(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Text('${snapshot.data}');
} else if (snapshot.hasError) {
print("erreur test: ${snapshot.error}");
return Text('${snapshot.error}');
}
// By default, show a loading spinner.
return const CircularProgressIndicator();
},
),
),
));
}
}
My pubspec.yaml :
name: projet_flutter
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.14.0 <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:
flutter:
sdk: flutter
http: 0.13.4
sqflite: any
path: any
# 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
# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^1.0.0
# 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'm currently learning Flutter dev, so i was wondering what went wrong?
Sqflite doesn't support web (https://github.com/tekartik/sqflite), which was what I was trying to build.
Sometimes this happens after adding new dependencies into pubspec file.
Try running the following command from the project terminal:
flutter clean
And then re-run the project.

Getting "Unhandled Exception: NoSuchMethodError: The method 'map' was called on null"

Main.dart file
import 'package:flutter/material.dart';
import 'package:weather_app/listModel.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:weather_app/model.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
var listModel;
bool circular = true;
#override
void initState() {
super.initState();
getData();
}
void getData() async {
var res = await http.get(Uri.parse('https://www.metaweather.com/api/location/2295420/'));
var r = json.decode(res.body);
setState(() {
listModel = ListModel.fromJson({"data": r});
print(listModel);
circular = false;
});
//
}
#override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('WEATHER REPORT'),
),
body: Center(
child: circular ? CircularProgressIndicator(): ListView.builder(itemCount: listModel.consolidatedWeather.length,itemBuilder: (BuildContext context, int index)=>
dataShow(listModel.consolidatedWeather[index],index)),
)
),
);
}
Widget dataShow(Model obj, index) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 10),
child: Container(
height: 100,
// width: MediaQuery.of(context).size.width,
child: Card(
color: Colors.teal,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"Name ${index + 1} : ${obj.weatherStateName}",
style: TextStyle(fontSize: 18, color: Colors.white),
),
SizedBox(
height: 10,
),
Text(
"PhoneNumber : ${obj.theTemp}",
style: TextStyle(fontSize: 18, color: Colors.white),
),
],
),
),
),
);
}
}
List Model.dart
import 'package:weather_app/model.dart';
class ListModel {
ListModel({
required this.consolidatedWeather,
});
List<Model> consolidatedWeather;
factory ListModel.fromJson(Map<String, dynamic> json) => ListModel(
consolidatedWeather: List<Model>.from(json["consolidated_weather"].map((x) => Model.fromJson(x))).toList(),
);
Map<String, dynamic> toJson() => {
"consolidated_weather": List<dynamic>.from(consolidatedWeather.map((x) => x.toJson())),
};
}
Model.dart
class Model {
Model({
required this.weatherStateName,
required this.weatherStateAbbr,
required this.applicableDate,
required this.theTemp,
});
String weatherStateName;
String weatherStateAbbr;
DateTime applicableDate;
double theTemp;
factory Model.fromJson(Map<String, dynamic> json) => Model(
weatherStateName: json["weather_state_name"],
weatherStateAbbr: json["weather_state_abbr"],
applicableDate: DateTime.parse(json["applicable_date"]),
theTemp: json["the_temp"].toDouble(),
);
Map<String, dynamic> toJson() => {
"weather_state_name": weatherStateName,
"weather_state_abbr": weatherStateAbbr,
"applicable_date": "${applicableDate.year.toString().padLeft(4, '0')}-${applicableDate.month.toString().padLeft(2, '0')}-${applicableDate.day.toString().padLeft(2, '0')}",
"the_temp": theTemp,
};
}
pupspec.yml
name: weather_app
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:
meta: ^1.0.2
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.2
http: ^0.13.3
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
ERROR
Performing hot restart...
Syncing files to device Redmi Note 9 Pro...
Restarted application in 1,965ms.
E/flutter (26913): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: NoSuchMethodError: The method 'map' was called on null.
E/flutter (26913): Receiver: null
E/flutter (26913): Tried calling: map(Closure: (dynamic) => Model)
E/flutter (26913): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
E/flutter (26913): #1 new ListModel.fromJson (package:weather_app/listModel.dart:11:72)
E/flutter (26913): #2 _MyAppState.getData.<anonymous closure> (package:weather_app/main.dart:30:29)
E/flutter (26913): #3 State.setState (package:flutter/src/widgets/framework.dart:1088:30)
E/flutter (26913): #4 _MyAppState.getData (package:weather_app/main.dart:29:5)
E/flutter (26913): <asynchronous suspension>
E/flutter (26913):
W/Choreographer(26913): Frame time is 0.009381 ms in the future! Check that graphics HAL is generating vsync timestamps using the correct timebase.
W/Choreographer(26913): Frame time is 0.021302 ms in the future! Check that graphics HAL is generating vsync timestamps using the correct timebase.
W/Choreographer(26913): Frame time is 0.006804 ms in the future! Check that graphics HAL is generating vsync timestamps using the correct timebase.
W/Choreographer(26913): Frame time is 0.064763 ms in the future! Check that graphics HAL is generating vsync timestamps using the correct timebase.
What can I try next to resolve this?
The getData() fn should go like this..
void getData() async {
var res = await http.get(Uri.parse('https://www.metaweather.com/api/location/2295420/'));
var r = json.decode(res.body);
setState(() {
listModel = ListModel.fromJson(r); // Change this line
print(listModel);
circular = false;
});
}

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

image asset not loading in flutter firebase project

I am following one tutorial on flutter and I am trying to load an image, unfortunately, the image was unable to load. I always have an error in console that the image was unable to load.my code is as followed:
import 'dart:ffi';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart';
final GoogleSignIn googleSignIn = new GoogleSignIn();
class Home extends StatefulWidget {
#override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
bool isAuth = false;
#override
Void initState() {
super.initState();
//detect when user sign in
googleSignIn.onCurrentUserChanged.listen((account) {
handleSignIn(account);
}, onError:(err){
print('error signing in:$err');
}
);
//re-authenticated when user sign in the app
googleSignIn.signInSilently(suppressErrors: false).then((account){
handleSignIn(account);
}).catchError((err){
print('error signing in:$err');
});
}
handleSignIn(GoogleSignInAccount account){
if (account != null) {
print(account);
setState(() {
isAuth = true;
});
} else {
setState(() {
isAuth = false;
});
}
}
login() {
googleSignIn.signIn();
}
logOut(){
googleSignIn.signOut();
}
Widget buildAuthScreen() {
return RaisedButton(
child:Text("LogOut"),
onPressed: (){
logOut();
},
);
}
Scaffold unAuthBuildScreen() {
return Scaffold(
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
colors: [
Theme.of(context).primaryColor,
Theme.of(context).accentColor,
],
),
),
alignment: Alignment.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
"FlutterShare",
style: TextStyle(
//fontFamily: "Signatra",
fontSize: 50.0,
color: Colors.white,
),
),
GestureDetector(
onTap: () => print("tapped"),
child: Container(
width: 260.0,
height: 60.0,
decoration: BoxDecoration(
image: DecorationImage(
// image:AssetImage(bund"assets/images/google_sigin_button.png"),
image: AssetImage("assets/images/google_sigin_button.png"),
fit: BoxFit.fill),
),
),
),
],
),
),
);
}
#override
Widget build(BuildContext context) {
return isAuth ? buildAuthScreen() : unAuthBuildScreen();
}
}
pubspec.yaml is as follows.Please help me
name: fluttershare
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.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
firebase_auth: ^0.15.5+3
firebase_database: ^3.1.3
cloud_firestore: ^0.13.4+1
image_picker: ^0.6.4
firebase_storage: ^3.1.5
google_sign_in: ^4.4.1
geolocator: ^5.3.1
uuid: ^2.0.4
timeago: ^2.0.26
path_provider: ^1.6.4
flutter_svg:
cached_network_image: ^2.0.0
firebase_messaging: ^6.0.13
image: ^2.1.4
animator: ^1.0.0+5
# 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
# 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:
uses-material-design: true
assets:
- assets/images/google_signin_button.png
- assets/images/upload.svg
- assets/images/search.svg
- assets/images/activity_feed.svg
- assets/images/no_content.svg
# 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
please help I have been on this for the past 3 days
Here is the Android’s density to Flutter pixel ratio
Android density qualifier Flutter pixel ratio
ldpi 0.75x
mdpi 1.0x
hdpi 1.5x
xhdpi 2.0x
xxhdpi 3.0x
xxxhdpi 4.0x
Best way to add images is to create an asset directory structure like that.
Put your images base on the density mapping to appropriate folder, flutter will pick image based on the device density.
You don't need to add every image path in pubspec.yaml only root folder is enough. Make sure assets and pubspec.yaml are in same directory level.
flutter:
assets:
- assets/images/
Hope it will solve your problem.
I think if you're using firebase for the authentication, you should use firebase storage to store your images.
You need these imports.
import 'package:firebase_storage/firebase_storage.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:cached_network_image/cached_network_image.dart';
And in the main function you need this code.
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
UserCredential userCredential = await FirebaseAuth.instance
.signInAnonymously(); // you need to indentify your user
print(userCredential);
runApp(MyApp());
}
You can load your images with this code.
FutureBuilder<dynamic>(
future: FirebaseStorage().ref('google_sigin_button.png').getDownloadURL(),
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.connectionState != ConnectionState.waiting) {
return Image(
image: CachedNetworkImageProvider(snapshot.data.toString()),
fit: BoxFit.cover,
);
} else {
return Text('Loading image....');
}
},
),
If you need more information how this actually work, you should see my github repository where you can find an example for this.
https://github.com/orosiferenc3/Flutter_Firebase_Storage_connection