Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrated to latest flutter version and android studio #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 27
compileSdkVersion 28

lintOptions {
disable 'InvalidPackage'
Expand All @@ -35,7 +35,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.groceryshopflutter"
minSdkVersion 16
targetSdkVersion 27
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand Down
21 changes: 10 additions & 11 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,33 @@
flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />

<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="grocery_shop_flutter"
android:icon="@mipmap/ic_launcher">
android:icon="@mipmap/ic_launcher"
android:label="grocery_shop_flutter">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:name="io.flutter.embedding.android.FlutterActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
android:name="flutterEmbedding"
android:value="2" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
package io.flutter.plugins;

import io.flutter.plugin.common.PluginRegistry;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;

import io.flutter.embedding.engine.FlutterEngine;

/**
* Generated file. Do not edit.
* This file is generated by the Flutter tool based on the
* plugins that support the Android platform.
*/
@Keep
public final class GeneratedPluginRegistrant {
public static void registerWith(PluginRegistry registry) {
if (alreadyRegisteredWith(registry)) {
return;
}
}

private static boolean alreadyRegisteredWith(PluginRegistry registry) {
final String key = GeneratedPluginRegistrant.class.getCanonicalName();
if (registry.hasPlugin(key)) {
return true;
}
registry.registrarFor(key);
return false;
public static void registerWith(@NonNull FlutterEngine flutterEngine) {
}
}
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.5.0'
}
}

Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
4 changes: 2 additions & 2 deletions android/local.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sdk.dir=C:\\Users\\willn\\AppData\\Local\\Android\\sdk
flutter.sdk=C:\\src\\flutter
sdk.dir=D:\\sdk
flutter.sdk=D:\\flutter-sdk
flutter.versionName=1.0.0
flutter.versionCode=1
flutter.buildMode=debug
22 changes: 10 additions & 12 deletions lib/bloc/CartBloc.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import 'package:rxdart/rxdart.dart';
import 'package:grocery_shop_flutter/models/Product.dart';
import 'package:grocery_shop_flutter/models/Order.dart';
import 'package:grocery_shop_flutter/models/Cart.dart';
import 'package:grocery_shop_flutter/models/Order.dart';
import 'package:grocery_shop_flutter/models/Product.dart';
import 'package:rxdart/rxdart.dart';

class CartBloc{

class CartBloc {
static int _orderId = 0;
static CartBloc _cartBloc;
Cart _currentCart;
Expand All @@ -13,16 +12,15 @@ class CartBloc{
PublishSubject<Order> _publishSubjectOrder;

factory CartBloc(){
if(_cartBloc == null)
_cartBloc = new CartBloc._();
if (_cartBloc == null) _cartBloc = CartBloc._();

return _cartBloc;
}

CartBloc._(){
_currentCart = new Cart();
_publishSubjectCart = new PublishSubject<Cart>();
_publishSubjectOrder = new PublishSubject<Order>();
CartBloc._() {
_currentCart = Cart();
_publishSubjectCart = PublishSubject<Cart>();
_publishSubjectOrder = PublishSubject<Order>();
}

Observable<Cart> get observableCart => _publishSubjectCart.stream;
Expand All @@ -37,7 +35,7 @@ class CartBloc{
}

void addOrderToCart(Product product, int quantity){
_lastOrder = new Order(product, quantity, _orderId++);
_lastOrder = Order(product, quantity, _orderId++);
_currentCart.addOrder(_lastOrder);
_updateLastOrder();
_updateCart();
Expand Down
137 changes: 89 additions & 48 deletions lib/components/CartManager.dart
Original file line number Diff line number Diff line change
@@ -1,65 +1,106 @@
import 'package:flutter/material.dart';
import 'package:grocery_shop_flutter/models/Cart.dart';
import 'package:grocery_shop_flutter/bloc/CartBloc.dart';
import 'package:grocery_shop_flutter/components/OrderWidget.dart';
import 'package:grocery_shop_flutter/models/Cart.dart';

class CartManager extends StatefulWidget {
@override
_CartManager createState() => new _CartManager();
_CartManager createState() => _CartManager();
}

class _CartManager extends State<CartManager> {

CartBloc _cartBloc = new CartBloc();
CartBloc _cartBloc = CartBloc();

@override
Widget build(BuildContext context) {
double _gridSize = MediaQuery.of(context).size.height * 0.88;

double _gridSize = MediaQuery.of(context).size.height*0.88;

return new Container(height: MediaQuery.of(context).size.height, child:
new Stack(children: <Widget>[
new Column(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[
new StreamBuilder(initialData: _cartBloc.currentCart, stream: _cartBloc.observableCart, builder: (context, AsyncSnapshot<Cart> snapshot){
return
new Container(margin: EdgeInsets.symmetric(horizontal: 20), height: _gridSize, width: double.infinity, child:
new Column(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[
new Padding(padding: EdgeInsets.symmetric(vertical: 40), child:
new Text("Cart", style: TextStyle(color: Colors.white, fontSize: 40, fontWeight: FontWeight.bold))
),
new Container(margin: EdgeInsets.only(bottom: 10), height: _gridSize*0.60, child:
new ListView.builder(itemCount: snapshot.data.orders.length, itemBuilder: (context, index ){
return Dismissible(
background: Container(color: Colors.transparent),
key: Key(snapshot.data.orders[index].id.toString()),
onDismissed: (_) {
_cartBloc.removerOrderOfCart(snapshot.data.orders[index]);
},
child: new Padding(padding: EdgeInsets.symmetric(vertical: 10), child: new OrderWidget(snapshot.data.orders[index], _gridSize)),
);
})
),
new Container(height: _gridSize*0.15, child:
new Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: <Widget>[
new Text("Total", style: TextStyle(color: Colors.white, fontSize: 20)),
new Text("\$${snapshot.data.totalPrice().toStringAsFixed(2)}", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 40)),
])
)
])
);
})
]),
new Align(alignment: Alignment.bottomLeft, child:
new Container(padding: EdgeInsets.only(left: 10, bottom: _gridSize*0.02), width: MediaQuery.of(context).size.width - 80, child:
new RaisedButton(color: Colors.amber, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(60)), padding: EdgeInsets.all(20),
onPressed: (){
if(_cartBloc.currentCart.isEmpty)
Scaffold.of(context).showSnackBar(SnackBar(content: Text("Cart is empty")));
},
child: new Text("Next", style: TextStyle(fontWeight: FontWeight.bold))
)
)
)
return Container(
height: MediaQuery.of(context).size.height,
child: Stack(children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
StreamBuilder(
initialData: _cartBloc.currentCart,
stream: _cartBloc.observableCart,
builder: (context, AsyncSnapshot<Cart> snapshot) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 20),
height: _gridSize,
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: EdgeInsets.symmetric(vertical: 40),
child: Text("Cart",
style: TextStyle(
color: Colors.white,
fontSize: 40,
fontWeight: FontWeight.bold))),
Container(
margin: EdgeInsets.only(bottom: 10),
height: _gridSize * 0.60,
child: ListView.builder(
itemCount: snapshot.data.orders.length,
itemBuilder: (context, index) {
return Dismissible(
background: Container(
color: Colors.transparent),
key: Key(snapshot
.data.orders[index].id
.toString()),
onDismissed: (_) {
_cartBloc.removerOrderOfCart(
snapshot.data.orders[index]);
},
child: Padding(
padding: EdgeInsets.symmetric(
vertical: 10),
child: OrderWidget(
snapshot.data.orders[index],
_gridSize)),
);
})),
Container(
height: _gridSize * 0.15,
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
Text("Total",
style: TextStyle(
color: Colors.white,
fontSize: 20)),
Text(
"\$${snapshot.data.totalPrice().toStringAsFixed(2)}",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 40)),
]))
]));
})
]),
Align(
alignment: Alignment.bottomLeft,
child: Container(
padding: EdgeInsets.only(left: 10, bottom: _gridSize * 0.02),
width: MediaQuery.of(context).size.width - 80,
child: RaisedButton(
color: Colors.amber,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(60)),
padding: EdgeInsets.all(20),
onPressed: () {
if (_cartBloc.currentCart.isEmpty)
Scaffold.of(context).showSnackBar(
SnackBar(content: Text("Cart is empty")));
},
child: Text("Next",
style: TextStyle(fontWeight: FontWeight.bold)))))
])
);
}
Expand Down
35 changes: 20 additions & 15 deletions lib/components/CategoryDropMenu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,33 @@ import 'package:flutter/material.dart';

class CategoryDropMenu extends StatefulWidget {
@override
_CategoryDropMenu createState() => new _CategoryDropMenu();
_CategoryDropMenu createState() => _CategoryDropMenu();
}

class _CategoryDropMenu extends State<CategoryDropMenu> {

String dropdownValue = "Pasta & Noodles";

@override
Widget build(BuildContext context){
return new DropdownButtonHideUnderline(child:
new DropdownButton<String>(
value: dropdownValue,
onChanged: (String newValue) {
setState(() {
dropdownValue = newValue;
});
},
items: <String>['Pasta & Noodles'].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value, style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold, fontSize: 20)),
);
Widget build(BuildContext context) {
return DropdownButtonHideUnderline(
child: DropdownButton<String>(
value: dropdownValue,
onChanged: (String Value) {
setState(() {
dropdownValue = Value;
});
},
items: <String>['Pasta & Noodles']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 20)),
);
}).toList(),
));
}
Expand Down
Loading