Giter VIP home page Giter VIP logo

firebaseextended / codelab-friendlyeats-flutter Goto Github PK

View Code? Open in Web Editor NEW
79.0 7.0 35.0 355 KB

FlutterFire Firestore codelab. Develop a cross platform restaurant recommendation app with Flutter.

License: Apache License 2.0

Kotlin 1.76% Ruby 6.00% Swift 1.73% Objective-C 1.11% Dart 84.76% HTML 4.65%
flutter flutter-example firebase firebase-firestore firebase-auth codelab multiplatform android ios web

codelab-friendlyeats-flutter's People

Contributors

ditman avatar mzdm avatar nickfehlinger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

codelab-friendlyeats-flutter's Issues

Firebase Hosting Deploy error

Had to modify firebase.json hosting-predeploy prop to avoid error.

From:
"predeploy": "flutter clean; flutter build web",
To:
"predeploy": ["flutter clean", "flutter build web"],

This works, but I'm not sure if this is the preferred syntax.

Error:
D:\apps\flutter\codelab-friendlyeats>firebase deploy --only hosting

=== Deploying to 'edgfowler-1'...

i deploying hosting
Running command: flutter clean; flutter build web
Could not find a command named "clean;".

Broken/wrong link

In the introduction. the link to "firebase for flutter" is broken and can't be found.

Images not loading in codelab app. CORS error is thrown.

Browser: Chrome
Browser version: 88.0.4324.146
Operating system: Windows 10 Pro
Operating system version: 19042.789

What steps will reproduce the problem:

  1. Follow the codelab verbatim to step 9 and run the app.

What is the expected result? App should run and display cards with pictures for each restaurant.

What happens instead of that? App loads and cards are displayed, but pictures do not load. Console reports CORS errors.

Please provide any other information below, and attach a screenshot if possible.

Example Error Message:
Access to XMLHttpRequest at 'https://storage.googleapis.com/firestorequickstarts.appspot.com/food_11.png' from origin 'http://localhost:60020' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

image

15. Deploy your web app to Firebase Hosting

Hi, it looks like in the CodeLab: Multi-platform Firestore Flutter, step 15 is missing this command firebase init hosting.

https://codelabs.developers.google.com/codelabs/friendlyeats-flutter?hl=en&continue=https%3A%2F%2Fcodelabs.developers.google.com%2F%3Fcat%3Dflutter#14

Commands:

  1. flutter build web
  2. firebase init hosting
    3. firebase deploy --only hosting

If we don't run the command firebase init hosting we get the below error:

Target dart2js failed: Exception: Error: FileSystemException: Cannot open file, path =
--
/Users/asandoval/dev/flutter/friendlyeats-flutter/.dart_tool/flutter_build/ed4fd20d65140e369640cdfbaae21d2e/app.dill
(OS Error: No such file or directory, errno = 2)

Thanks,
Andres

home_page.dart error at step 12. Sorting and Filtering Data

home_page.dart:90 code:
data.loadFilteredRestaurants(filter).listen(_updateRestaurants);

(full home_page.dart code at bottom.)

Expected behavior:
The query requires an index. You can create it here: https://console.firebase.google.com/project/.../database/firestore/indexes?create_index=...

Instead Got:
Uncaught (in promise) TypeError: Cannot read property 'listen' of undefined
at home_page.dart:90
at home_page._HomePageState.new.setState (framework.dart:1244)
at home_page._HomePageState.new._onFilterBarPressed (home_page.dart:82)
at _onFilterBarPressed.next ()
at async_patch.dart:45
at _RootZone.runUnary (zone.dart:1450)
at _FutureListener.thenAwait.handleValue (future_impl.dart:143)
at handleValueCallback (future_impl.dart:696)
at Function._propagateToListeners (future_impl.dart:725)
at async._AsyncCallbackEntry.new.callback (future_impl.dart:393)
at Object._microtaskLoop (schedule_microtask.dart:41)
at _startMicrotaskLoop (schedule_microtask.dart:50)
at async_patch.dart:166

xpat@penguin:~/FlutterProjects/codelabs/friendly_flutter$ flutter doctor -v
[✓] Flutter (Channel dev, 1.22.0-9.0.pre, on Linux, locale en_US.UTF-8)
• Flutter version 1.22.0-9.0.pre at /home/xpat/development/flutter
• Framework revision 7a43175198 (3 weeks ago), 2020-08-28 23:18:04 -0400
• Engine revision 07e2520d5d
• Dart version 2.10.0 (build 2.10.0-73.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at /home/xpat/Android/Sdk
• Platform android-29, build-tools 29.0.3
• Java binary at: /opt/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.

[✓] Chrome - develop for the web
• Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
• clang version 7.0.1-8 (tags/RELEASE_701/final)
• cmake version 3.13.4
• ninja version 1.8.2
• pkg-config version 0.29

[✓] Android Studio (version 4.0)
• Android Studio at /opt/android-studio
• Flutter plugin version 47.1.2
• Dart plugin version 193.7361
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] VS Code (version 1.46.1)
• VS Code at /usr/share/code
• Flutter extension version 3.12.2

[✓] Connected device (3 available)
• Linux (desktop) • linux • linux-x64 • Linux
• Web Server (web) • web-server • web-javascript • Flutter Tools
• Chrome (web) • chrome • web-javascript • Google Chrome 83.0.4103.116

• No issues found!
xpat@penguin:~/FlutterProjects/codelabs/friendly_flutter$

Even after deploying the indexes from firestore.indexes.json

xpat@penguin:~/FlutterProjects/codelabs/friendly_flutter$ firebase deploy --only firestore:indexes

=== Deploying to ''...

i deploying firestore
i firestore: reading indexes from firestore.indexes.json...
✔ firestore: deployed indexes in firestore.indexes.json successfully

✔ Deploy complete!

xpat@penguin:~/FlutterProjects/codelabs/friendly_flutter$ flutter doctor -v
[✓] Flutter (Channel dev, 1.22.0-9.0.pre, on Linux, locale en_US.UTF-8)
• Flutter version 1.22.0-9.0.pre at /home/xpatdevelopment/flutter
• Framework revision 7a43175198 (3 weeks ago), 2020-08-28 23:18:04 -0400
• Engine revision 07e2520d5d

home_page.dart full code:

// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import 'dart:async';
import 'dart:math';

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';

import 'restaurant_page.dart';
import 'model/data.dart' as data;
import 'model/filter.dart';
import 'model/restaurant.dart';
import 'widgets/empty_list.dart';
import 'widgets/filter_bar.dart';
import 'widgets/grid.dart';
import 'widgets/dialogs/filter_select.dart';

class HomePage extends StatefulWidget {
  static const route = '/';

  HomePage({Key key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  _HomePageState() {
    FirebaseAuth.instance
        .signInAnonymously()
        .then((UserCredential userCredential) {
      _currentSubscription =
          data.loadAllRestaurants().listen(_updateRestaurants);
    });
  }

  @override
  void dispose() {
    _currentSubscription?.cancel();
    super.dispose();
  }

  StreamSubscription<QuerySnapshot> _currentSubscription;
  bool _isLoading = true;
  List<Restaurant> _restaurants = <Restaurant>[];
  Filter _filter;

  void _updateRestaurants(QuerySnapshot snapshot) {
    setState(() {
      _isLoading = false;
      _restaurants = data.getRestaurantsFromQuery(snapshot);
    });
  }

  Future<void> _onAddRandomRestaurantsPressed() async {
    final numReviews = Random().nextInt(10) + 20;

    final restaurants = List.generate(numReviews, (_) => Restaurant.random());
    data.addRestaurantsBatch(restaurants);
  }

  Future<void> _onFilterBarPressed() async {
    final filter = await showDialog<Filter>(
      context: context,
      builder: (_) => FilterSelectDialog(filter: _filter),
    );
    if (filter != null) {
      await _currentSubscription?.cancel();
      setState(() {
        _isLoading = true;
        _filter = filter;
        if (filter.isDefault) {
          _currentSubscription =
              data.loadAllRestaurants().listen(_updateRestaurants);
        } else {
          _currentSubscription =
              data.loadFilteredRestaurants(filter).listen(_updateRestaurants);
        }
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: Icon(Icons.restaurant),
        title: Text('FriendlyEats'),
        bottom: PreferredSize(
          preferredSize: Size(320, 48),
          child: Padding(
            padding: EdgeInsets.fromLTRB(6, 0, 6, 4),
            child: FilterBar(
              filter: _filter,
              onPressed: _onFilterBarPressed,
            ),
          ),
        ),
      ),
      body: Center(
        child: Container(
          constraints: BoxConstraints(maxWidth: 1280),
          child: _isLoading
              ? CircularProgressIndicator()
              : _restaurants.isNotEmpty
                  ? RestaurantGrid(
                      restaurants: _restaurants,
                      onRestaurantPressed: (id) {
                        // TODO: Add deep links on web
                        Navigator.pushNamed(context, RestaurantPage.route,
                            arguments: RestaurantPageArguments(id: id));
                      })
                  : EmptyListView(
                      child: Text('FriendlyEats has no restaurants yet!'),
                      onPressed: _onAddRandomRestaurantsPressed,
                    ),
        ),
      ),
    );
  }
}

Add Firebase to your Android App - skips `build.gradle` modifications

In Step 6 here:
https://codelabs.developers.google.com/codelabs/friendlyeats-flutter/#5

The "Add Firebase to your Android App" suggests you can skip modifications to the build.gradle

"10. Back in the Firebase console, skip the remaining steps, and go back to the main page of the Firebase console."

This will cause errors such as:

FirebaseException ([core/not-initialized] Firebase has not been correctly initialized.

Usually this means you've attempted to use a Firebase service before calling `Firebase.initializeApp`.

View the documentation for more information: https://firebase.flutter.dev/docs/overview#initialization
    )

Please add steps to implement the build.gradle modifications

In android/build.gradle

  • Add classpath 'com.google.gms:google-services:4.3.10' to dependencies

In android/app/build.gradle

  • Add apply plugin: 'com.google.gms.google-services'

Code in this project is not null safe

This project should be updated to eliminate the null safety warning that occurs at startup:

C:...Git\friendlyeats-flutter2>flutter run -d chrome --web-renderer html
Launching lib\main.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome... 31.1s
Debug service listening on ws://127.0.0.1:57882/LNbNgnoYfAQ=/ws

Running with unsound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety

To hot restart changes while running, press "r" or "R".
For a more detailed help message, press "h". To quit, press "q".

COMMIT ID of code: 6f7603c

No "web server" listed as instructions say to expect

In step 4 (Prepare the Firebase and Flutter CLI) it says: "In your IDE under the devices pulldown, or at the command line using flutter devices, you should now see Chrome and Web server listed." I see Chrome and "Edge" but no "Web server".

PS C:...\friendlyeats-flutter> flutter devices
Downloading Material fonts... 796ms
Downloading Gradle Wrapper... 47ms
Downloading package sky_engine... 363ms
Downloading flutter_patched_sdk tools... 1,176ms
Downloading flutter_patched_sdk_product tools... 797ms
Downloading windows-x64 tools... 1,600ms
Downloading windows-x64/font-subset tools... 387ms
2 connected devices:

Chrome (web) • chrome • web-javascript • Google Chrome 89.0.4389.114
Edge (web) • edge • web-javascript • Microsoft Edge 89.0.774.68

replace jcenter() with mavenCentral()

Looks like the android module on this codelab is still using jcenter() which has been recently sunset:

jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.3'
}
}
allprojects {
repositories {
google()
jcenter()

The approach we've been taking on Android repos is to replace it with mavenCentral(): firebase/snippets-android@5b9f209
I think it would be nice to do it here too.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.