Hide navigation bar Swiftui - uinavigationcontroller

I've a problem with the NavigationView in SwiftUI, I've add this code for hide the navigation and works fine but in when scroll the view appear the sticky header how to remove this? thanks!!
NavigationView {
...
}
.navigationBarTitle("")
.navigationBarHidden(true)
.navigationBarBackButtonHidden(true)

Moving the navigationBarTitle and navigationBarHidden within the NavigationView will remove the sticky header. Here's the code.
import SwiftUI
struct ContentView: View {
let months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December","January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
var body: some View {
NavigationView {
List(months, id: \.self) { month in
NavigationLink(destination: DetailView(month: month)) {
Text(month)
}
}
.navigationBarTitle("")
.navigationBarHidden(true)
}
//.navigationBarBackButtonHidden(true)
}
}
struct DetailView: View {
let month: String
var body: some View {
Text(month)
}
}

Related

Assistance required to get search query data render on screen. flutter/dart

I made this notes app which uses firestore to save data and it is working fine, no problem whatsoever.
Now I am trying to implement a search filter on notes and I can't find the right method to do it.
Here is my code that renders the notes on the screen
here is the reference image
List<Widget> _buildNotesView(
BuildContext context, NoteFilter filter, List<Note> notes) {
if (notes?.isNotEmpty != true) {
return [_buildBlankView(filter.noteState)];
}
final asGrid = filter.noteState == NoteState.deleted || notesView;
final factory = asGrid ? NotesGrid.create : NotesList.create;
final showPinned = filter.noteState == NoteState.unspecified;
if (!showPinned) {
return [
factory(notes: notes, onTap: _onNoteTap),
];
}
final partition = _partitionNotes(notes);
final hasPinned = partition.item1.isNotEmpty;
final hasUnpinned = partition.item2.isNotEmpty;
final _buildLabel = (String label, [double top = 26]) => SliverToBoxAdapter(
child: Container(
padding:
EdgeInsetsDirectional.only(start: 26, bottom: 25, top: top),
child: Text(
label,
style: TextStyle(
fontFamily: selectedFont,
color: kHintTextColorLight,
fontWeight: FontWeights.medium,
fontSize: 12,
),
),
),
);
//TODO
if (searchController.text.isNotEmpty) {
notes.forEach((note) {
if (note.title
.toLowerCase()
.contains(searchController.text.toLowerCase()) ||
note.content
.toLowerCase()
.contains(searchController.text.toLowerCase())) ;
//Do something here?
});
}
return [
if (hasPinned) _buildLabel('PINNED', 0),
if (hasPinned) factory(notes: partition.item1, onTap: _onNoteTap),
if (hasPinned && hasUnpinned) _buildLabel('OTHERS'),
factory(notes: partition.item2, onTap: _onNoteTap),
];
}
Any help would be great. I'm open to learning.

getx and weird problem: text won't change on UI

I am trying to create a search function from firebase
and i am using getx for the state management
I counter this weird problem, when I try to use the function directly it work, but when I use the firebase function it does not.
I will explain more on the code snipit.
this is my search textForm
TextFormField(
onChanged: (value) => database.searchForId(value),
decoration: InputDecoration(
focusColor: Colors.lightGreenAccent,
prefixIcon: Icon(
Icons.search,
color: Colors.lightGreenAccent,
),
labelText: 'Search...',
labelStyle: TextStyle(color: Colors.lightGreenAccent),
border: OutlineInputBorder(),
focusedBorder: OutlineInputBorder(
borderSide:
const BorderSide(color: Colors.lightGreenAccent),
),
)),
as you can see I am using on change value
database code for search
searchForId(searchText) {
FirebaseFirestore.instance
.collection('inventory')
.where('id', isGreaterThanOrEqualTo: searchText)
.get()
.then((snapshot) {
var data = snapshot.docs[0];
if (data['id'] != searchText) {
return;
} else {
searchController.changeId(data['id']);
searchController.changeName(data['name']);
searchController.changeQuantity(data['quantity']);
searchController.changeCost(data['cost']);
searchController.changeMyPrice(data['myPrice']);
}
});
}
and the controller
class SearchController extends GetxController {
var id = 'No info'.obs;
var name = 'No info'.obs;
var quantity = 'No info'.obs;
var cost = 'No info'.obs;
var myPrice = 'No info'.obs;
changeId(_id) {
id(_id);
print(id);
}
the print show me that the value is changed, but never update it on my UI
Obx(() => Text(searchController.id.value))
so i trid to call the controller dirctly (not using database file) and it work just fine, and UI updated
any idea why ?
the weird is the print show me the function get called and working fine ( i mean when i use database file as well ) but it never update the UI
I think u forgot to keep
SearchController searchcontroller = Get.put(SearchController());
if you initialized it before just find that controller using
SearchController searchcontroller = Get.find();
var id = 'No info'.obs;
searchController.changeId(data['id']);
changeId(_id) {
id(_id);
print(id);
}
In order to update your text in UI, you can either update your code
changeId(_id) {
id(_id);
print(id);
update(); // Calling update manually. update() is a function in GetxController to trigger the observable change.
}
or
changeId(String _id) {
id.value = _id;
}

Flutter: How to sort data in listview.builder after calculating distance from firebase firestore using latitude and longitude

I am making an app that calculates and shows the nearby businesses by fetching the latitude and longitude which I saved in Firebase Firestore and calculate them according to the user location and i have to put them in listview here and i wanted to sort them according to the nearest location when being calculated and fetched
import 'package:e_commerce/zRealDistance/AssistantMethods.dart';
import 'package:geolocator/geolocator.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
var passlat;
var passlong;
#override
Future<String> getCurrentLocation(String slatitude, String slongitude) async {
var slat = double.parse(slatitude);
var slon = double.parse(slongitude);
var position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.bestForNavigation);
passlat = position.latitude;
passlong = position.longitude;
LatLng a = LatLng(passlat, passlong);
LatLng b = LatLng(slat, slon);
var details = await AssistantMethods.obtainDirectionDetails(a, b);
return details.distanceText;
}
Here is the direction detail class
class DirectionDetails {
int distanceValue;
int durationValue;
String distanceText;
String durationText;
String encodedPoints;
DirectionDetails({
this.distanceText,
this.distanceValue,
this.durationText,
this.durationValue,
this.encodedPoints
});
}
and this below calculates and obtains the direction details
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'request_assistant.dart';
import 'directiondetails.dart';
class AssistantMethods {
static Future<DirectionDetails> obtainDirectionDetails(
LatLng initialPosition, LatLng finalPosition) async {
String directionUrl =
"https://maps.googleapis.com/maps/api/directions/json?origin=${initialPosition.latitude},${initialPosition.longitude}&destination=${finalPosition.latitude},${finalPosition.longitude}&key=apiKey";
var res = await RequestAssistant.getRequest(directionUrl);
if (res == "failed") {
print(res.toString());
}
if (res == null) {
print(res.toString());
}
try {
DirectionDetails directionDetails = DirectionDetails();
directionDetails.encodedPoints =
res["routes"][0]["overview_polyline"]["points"];
directionDetails.distanceText =
res["routes"][0]["legs"][0]["distance"]["text"];
directionDetails.distanceValue =
res["routes"][0]["legs"][0]["distance"]["value"];
directionDetails.durationText =
res["routes"][0]["legs"][0]["duration"]["text"];
directionDetails.durationValue =
res["routes"][0]["legs"][0]["duration"]["value"];
return directionDetails;
} catch (exp) {
print(exp.toString());
}
}
}
and at last this one puts them in a text format in a listtile
subtitle: FutureBuilder<String>(
future: getCurrentLocation(
'${doc[index].data()['latitude']}',
'${doc[index].data()['longitude']}'),
builder: (BuildContext context,
AsyncSnapshot<String> snapshot) {
List<Widget> children;
if (snapshot.hasData) {
children = <Widget>[
Text('Distance: ${snapshot.data}'),
];
} else {
children = <Widget>[
JumpingText(
'Calculating distance...',
),
];
}
return Column(
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: children,
);
},
),

Displaying video ads in a row with admob on flutter

Im interested if there is a way to display more than one RewardVideoAd in a row. Before opening one videoAd it must be loaded, so I tried to load another videoAd when other is opened, so that way when the videoAd is closed/rewarded/completed it shows the new one. But it isn't working here is the code I have tried.
(RewardedVideoAdEvent event, {String rewardType, int rewardAmount}) {
print("RewardedVideoAd event $event");
if (event == RewardedVideoAdEvent.opened) {
setState(() {
RewardedVideoAd.instance.load(
adUnitId: RewardedVideoAd.testAdUnitId,
targetingInfo: targetingInfo);
});
} else if (event == RewardedVideoAdEvent.closed ||
event == RewardedVideoAdEvent.completed ||
event == RewardedVideoAdEvent.rewarded ||
event == RewardedVideoAdEvent.failedToLoad) {
setState(() {
_coins += rewardAmount;
RewardedVideoAd.instance.show();
});
}
};
..and the buttons from where the first ad is started.
RaisedButton(
child: const Text('LOAD REWARDED VIDEO'),
onPressed: () {
RewardedVideoAd.instance.load(
adUnitId: RewardedVideoAd.testAdUnitId,
targetingInfo: targetingInfo);
},
),
RaisedButton(
child: const Text('SHOW REWARDED VIDEO'),
onPressed: () {
RewardedVideoAd.instance.show();
},
),
I wonder if there is a way to show 2 or 3 rewardVideoAds in a row, one after another. Thanks!

Using Form With PageView Overwrites Previous Form Data With Each Page Flutter

I am using a pageview to display a form and get data. But, with every page, the previous data is is overwritten. I'm not sure why. Here is what I'm doing:
I want to get these pieces of information from each page:
final Map<String, dynamic> ratingCapsule = {
"prodId": null,
"starRating": null,
"_foodRating": null,
"_drinkRating": null,
"recommend": null
};
Page View:
Expanded(
flex: 2,
child: Form(
key: _userRatingKey,
child: IndexedStack(
index: index,
children: <Widget>[
PageView.builder(
itemBuilder: (context, i) {
return _prodctReview2(context, i);
},
itemCount: currentReview.order.orderDetails.length,
controller: _pageController,
)
],
),
)),
Validator:
void _submit(srating, effectRating, usageRating, userRecommend) {
final FormState form = _userRatingKey.currentState;
if (form.validate()) {
ratingCapsule['starRating'] = srating;
ratingCapsule['_foodRating'] = effectRating;
ratingCapsule['_drinkRating'] = _drinkRating;
ratingCapsule['recommend'] = userRecommend;
form.save();
print(ratingCapsule['prodId']);
print(ratingCapsule['starRating']);
print(ratingCapsule['_foodrating']);
print(ratingCapsule['_drinkRating']);
print(ratingCapsule['recommend']);
print(ratingCapsule.values);
ratingsList.add(ratingCapsule);
print(ratingsList);
setState(() {
vaildForm = true;
print(ratingCapsule);
});
_clearInput();
ratingCapsule.clear();
nextPage();
} else {
print('Invalid Form');
print(ratingCapsule.values);
print(ratingCapsule);
}
}
On the first page I get:
[{prodId: 51, starRating: 4.0, _foodRating: 5, _drinkRating: 1, recommend: 1}]
But on the second page I get:
[{prodId: 55, starRating: 5.0, _foodRating: 5, _drinkRating: 1, recommend: 1}, {prodId: 55, starRating: 5.0, _foodRating: 5, _drinkRating: 1, recommend: 1}]
Overwriting the previous data with the new information. How do I stop this?
You can use TextEdittingController for each field.

Resources