Skip to content

Instantly share code, notes, and snippets.

@mohancm
Last active July 6, 2019 06:11
Show Gist options
  • Save mohancm/11fa57befb949ad18c0c82214e2b4fec to your computer and use it in GitHub Desktop.
Save mohancm/11fa57befb949ad18c0c82214e2b4fec to your computer and use it in GitHub Desktop.
Flutter Events
// To parse this JSON data, do
//
// final event = eventFromJson(jsonString);
import 'dart:convert';
List<Event> eventFromJson(String str) => new List<Event>.from(json.decode(str).map((x) => Event.fromJson(x)));
String eventToJson(List<Event> data) => json.encode(new List<dynamic>.from(data.map((x) => x.toJson())));
class Event {
String eventName;
String eventUrl;
DateTime eventDate;
String address;
String city;
double latitude;
double longitude;
String textMessage;
String htmlMessage;
String description;
Event({
this.eventName,
this.eventUrl,
this.eventDate,
this.address,
this.city,
this.latitude,
this.longitude,
this.textMessage,
this.htmlMessage,
this.description,
});
factory Event.fromJson(Map<String, dynamic> json) => new Event(
eventName: json["event_name"],
eventUrl: json["event_url"],
eventDate: DateTime.parse(json["event_date"]),
address: json["address"],
city: json["city"],
latitude: json["latitude"].toDouble(),
longitude: json["longitude"].toDouble(),
textMessage: json["text_message"],
htmlMessage: json["html_message"],
description: json["description"],
);
Map<String, dynamic> toJson() => {
"event_name": eventName,
"event_url": eventUrl,
"event_date": "${eventDate.year.toString().padLeft(4, '0')}-${eventDate.month.toString().padLeft(2, '0')}-${eventDate.day.toString().padLeft(2, '0')}",
"address": address,
"city": city,
"latitude": latitude,
"longitude": longitude,
"text_message": textMessage,
"html_message": htmlMessage,
"description": description,
};
}
import 'package:flutter/material.dart';
class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
bottom: TabBar(
tabs: <Widget>[
Tab(text: 'Global',),
Tab(text: 'Local',)
],
),
),
),
);
}
}
import 'package:flutter/material.dart';
import 'package:flutter_events/splash_screen.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// this widget is the root of your Application
@override
Widget build(BuildContext context){
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.deepPurple,
),
home: SplashScreen(),
);
}
}
import 'dart:async';
import 'package:flutter/material.dart';
import 'home_screen.dart';
class SplashScreen extends StatefulWidget {
@override
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
@override
void initState(){
// TODO: Implement initState
loadTimer();
super.initState();
}
Future<Timer> loadTimer() async {
return Timer(Duration(seconds: 3), navigate);
}
navigate(){
Navigator.of(context).pushReplacement(MaterialPageRoute(
builder:(_) => HomeScreen(),
));
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.deepPurple,
body: Container(
padding: EdgeInsets.all(20),
alignment: Alignment.center,
child: Image.network('https://itsallwidgets.com/images/logo.png'),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment