WorldTime | Discord bot for keeping track of user time zones | Bot library
kandi X-RAY | WorldTime Summary
kandi X-RAY | WorldTime Summary
Discord bot for keeping track of user time zones.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of WorldTime
WorldTime Key Features
WorldTime Examples and Code Snippets
Community Discussions
Trending Discussions on WorldTime
QUESTION
I have list of items that are loading from database, the problem is each one of this items require to get 1 string loaded from server and I can't find out a way to make that string get updates.
Logic
- Show list of locations from database (done)
- Show each item current time (the issue)
Screenshot
Code Commented
ANSWER
Answered 2021-May-29 at 17:14Use FutureBuilder for calling instance.getTime() since it returns a Future. Replace Text('$time')
with following:
QUESTION
**main.dart**
import 'package:flutter/material.dart';
import 'package:world_time/pages/choose_location.dart';
import 'package:world_time/pages/home.dart';
import 'package:world_time/pages/loading.dart';
void main() => runApp(MaterialApp(
initialRoute: '/',
routes: {
'/': (context) => Loading(),
'/home': (context) => Home(),
'/location': (context) => ChooseLocation(),
},
));
**home.dart**
import 'package:flutter/material.dart';
class Home extends StatefulWidget {
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State {
Map data = {};
@override
Widget build(BuildContext context) {
data = data.isNotEmpty ? data : ModalRoute.of(context).settings.arguments;
print(data);
// set background
String bgImage = data['isDaytime'] ? 'day.png' : 'night.png';
Color bgColor = data['isDaytime'] ? Colors.blue : Colors.indigo[700];
return Scaffold(
backgroundColor: bgColor,
body: SafeArea(
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/$bgImage'),
fit: BoxFit.cover,
),
),
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 120.0, 0, 0),
child: Column(
children: [
FlatButton.icon(
onPressed: () async {
dynamic result =
await Navigator.pushNamed(context, '/location');
setState(() {
data = {
'time': result['time'],
'result': result['location'],
'isDaytime': result['isDaytime'],
'flag': result['flag'],
};
});
},
icon: Icon(
Icons.edit_location,
color: Colors.grey[300],
),
label: Text(
'Edit Location',
style: TextStyle(
color: Colors.grey[300],
),
),
),
SizedBox(height: 20.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
data['location'] ?? '',
style: TextStyle(
fontSize: 38.0,
letterSpacing: 2.0,
color: Colors.white,
),
),
],
),
SizedBox(height: 20.0),
Text(
data['time'] ?? '',
style: TextStyle(
fontSize: 66.0,
color: Colors.white,
),
),
],
),
),
),
),
);
}
}
**choose_location.dart**
import 'package:flutter/material.dart';
import 'package:world_time/services/world_time.dart';
class ChooseLocation extends StatefulWidget {
@override
_ChooseLocationState createState() => _ChooseLocationState();
}
class _ChooseLocationState extends State {
List locations = [
WorldTime(url: 'Europe/London', location: 'London', flag: 'uk.png'),
WorldTime(url: 'Europe/Berlin', location: 'Athens', flag: 'greece.png'),
WorldTime(url: 'Africa/Cairo', location: 'Cairo', flag: 'egypt.png'),
WorldTime(url: 'Africa/Nairobi', location: 'Nairobi', flag: 'kenya.png'),
WorldTime(url: 'America/Chicago', location: 'Chicago', flag: 'usa.png'),
WorldTime(url: 'America/New_York', location: 'New York', flag: 'usa.png'),
WorldTime(url: 'Asia/Seoul', location: 'Seoul', flag: 'south_korea.png'),
WorldTime(url: 'Asia/Jakarta', location: 'Jakarta', flag: 'indonesia.png'),
];
void updateTime(index) async {
WorldTime instance = locations[index];
await instance.getTime();
// navigate to home screen
Navigator.pop(context, {
'location': instance.location,
'flag': instance.flag,
'time': instance.time,
'isDaytime': instance.isDaytime,
});
}
@override
Widget build(BuildContext context) {
print('build function ran');
return Scaffold(
backgroundColor: Colors.grey[200],
appBar: AppBar(
backgroundColor: Colors.blue[900],
title: Text('Choose a Location'),
centerTitle: true,
elevation: 0,
),
body: ListView.builder(
itemCount: locations.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 1.0, horizontal: 4.0),
child: Card(
child: ListTile(
onTap: () {
updateTime(index);
},
title: Text(locations[index].location),
leading: CircleAvatar(
backgroundImage:
AssetImage('assets/${locations[index].flag}'),
),
),
),
);
},
),
);
}
}
**loading.dart**
import 'package:flutter/material.dart';
import 'package:world_time/services/world_time.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
class Loading extends StatefulWidget {
@override
_LoadingState createState() => _LoadingState();
}
class _LoadingState extends State {
void setupWorldTime() async {
WorldTime instance = WorldTime(
location: 'Berlin', flag: 'germany.png', url: 'Europe/Berlin');
await instance.getTime();
Navigator.pushReplacementNamed(context, '/home', arguments: {
'location': instance.location,
'flag': instance.flag,
'time': instance.time,
'isDaytime': instance.isDaytime,
});
}
@override
void initState() {
super.initState();
setupWorldTime();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blue[900],
body: Center(
child: SpinKitFadingCircle(
color: Colors.white,
size: 50.0,
),
),
);
}
}
**world_time.dart**
import 'package:http/http.dart';
import 'dart:convert';
import 'package:intl/intl.dart';
class WorldTime {
String location; // location name for the UI
String time; //the time in that location
String flag; //url to an asset flag icon
String url; //location url for api endpoint
bool isDaytime; //true or false if daytime or not
WorldTime({this.location, this.flag, this.url});
Future getTime() async {
//make the request
Response response =
await get(Uri.parse('https://worldtimeapi.org/api/timezone/$url'));
Map data = jsonDecode(response.body);
//print(data);
//get properties from data
String datetime = data['datetime'];
String offset = data['utc_offset'].substring(1, 3);
//print(datetime);
//print(offset);
//create DateTime object
DateTime now = DateTime.parse(datetime);
now = now.add(Duration(hours: int.parse(offset)));
//set the time property
isDaytime = now.hour > 6 && now.hour < 20 ? true : false;
time = DateFormat.jm().format(now);
}
}
WorldTime instance =
WorldTime(location: 'Berlin', flag: 'germany.png', url: 'Europe/Berlin');
...ANSWER
Answered 2021-May-26 at 12:19On your flatbutton onpressed you have set the location key to 'result' change it to 'location'.
QUESTION
I cannot find the mistake in the below code. Dart shows an error message saying "Error: Expected a declaration but got '}'. Could someone please assist?
...ANSWER
Answered 2021-May-09 at 05:50There is a closing }
after WorldTime
constructor declaration, so that the last }
in the code you given is extra. The solution is to remove the closing }
after the WorldTime({ });
constructor declaration, or remove the last }
.
QUESTION
It is a world time app that starts with a home screen showing a default location at the beginning then you can change the location and the API gets you the time on that new location. It works fine but when I hit the back button in the "location" bar it gets me an error !!
Here is my Home code:
...ANSWER
Answered 2020-Aug-04 at 13:29You are doing
QUESTION
main.dart
...ANSWER
Answered 2020-Jun-03 at 17:06The error says.boolean expression must not be null
that means you're try to check the value of null
variable. In order to solve this you should check if it true by using full statement.
QUESTION
Performing hot restart...
Syncing files to device Android SDK built for x86...
Restarted application in 2,632ms.
I/flutter (17581): ══╡ EXCEPTION CAUGHT BY FLUTTER FRAMEWORK ╞═════════════════════════════════════════════════════════
I/flutter (17581): The following message was thrown:
I/flutter (17581): Could not navigate to initial route.
I/flutter (17581): The requested route name was: "/home"
I/flutter (17581): There was no corresponding route in the app, and therefore the initial route specified will be
I/flutter (17581): ignored and "/" will be used instead.
I/flutter (17581): ════════════════════════════════════════════════════════════════════════════════════════════════════
...ANSWER
Answered 2020-May-07 at 14:33You mis-typed the route. You have written route as:
QUESTION
I have an app for showing world times. I have a page for changing different locations around the world. It's a ListView.
...ANSWER
Answered 2020-Apr-30 at 13:35You can wrap your screen with IgnorePointer, which ignores any click.
Create bool variable.
QUESTION
Dart version: 2.8.0
I'm getting this: Instance of 'Future'
even though I'm using await.
See the code: from loading.dart (this is first page when app launch)
...ANSWER
Answered 2020-Apr-05 at 20:50A constructor may only return an instance of the class it creates (WorldTime
). Constructors cannot be asynchronouse because they would have to return Future
which is not supported.
In your case you should just create and instance of WorldTime
:
QUESTION
I'm trying to subclass the datetime class so my main code looks cleaner. However, doing any arithmetic on my subclass changes the data type back to datetime.datetime.
I took my original code and cut it down to a minimal example.
...ANSWER
Answered 2019-Aug-28 at 20:57The important line is this one, within the to_local()
method:
QUESTION
I am currently trying to get the titles from all auction lots (page 1 till page 33) of the 'Hong Kong Watches 2.0' auction provided on the Bonhams website (https://www.bonhams.com/auctions/25281/?category=results#/!). I am new to using python and selenium, but I tried to get the results using the code below. This code gives me the results I want, but only for page 1. Then, the code keeps repeating the results of page 1 over and over again. It looks like the loop to click on the next pages is not working. Can anybody help me with fixing this loop?
Below you can find the code I used:
...ANSWER
Answered 2019-Jul-15 at 05:36Not required selenium
library to scrap data. you can also get all pages data using requests
and BeautifulSoup
library.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install WorldTime
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page