Skip to content

Instantly share code, notes, and snippets.

@Rohit-554
Created January 11, 2026 14:40
Show Gist options
  • Select an option

  • Save Rohit-554/1ce0ab643c787bdba0b0950e37e3bc7b to your computer and use it in GitHub Desktop.

Select an option

Save Rohit-554/1ce0ab643c787bdba0b0950e37e3bc7b to your computer and use it in GitHub Desktop.
3dgloble.dart
import 'package:flutter/material.dart';
import 'package:flutter_earth_globe/flutter_earth_globe.dart';
import 'package:flutter_earth_globe/flutter_earth_globe_controller.dart';
import 'package:flutter_earth_globe/globe_coordinates.dart';
import 'package:flutter_earth_globe/point.dart';
import 'package:flutter_earth_globe/point_connection.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Earth Globe Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData.dark(),
home: const GlobeView(),
);
}
}
class GlobeView extends StatefulWidget {
const GlobeView({super.key});
@override
State<GlobeView> createState() => _GlobeViewState();
}
class _GlobeViewState extends State<GlobeView> {
late FlutterEarthGlobeController _controller;
bool _isNightModeSimulated = false;
@override
void initState() {
super.initState();
// 1. Initialize Controller with basic configuration
_controller = FlutterEarthGlobeController(
rotationSpeed: 0.05,
isBackgroundFollowingSphereRotation: true,
isDayNightCycleEnabled: true,
zoom: 0.5,
maxZoom: 3.0,
minZoom: 0.1,
);
// Load textures after initialization
WidgetsBinding.instance.addPostFrameCallback((_) {
_loadGlobeResources();
});
}
// 2. Load Textures (Surface, Night, Background)
void _loadGlobeResources() {
// Using Network Images for immediate run capability.
// In production, use Image.asset('assets/...')
_controller.loadSurface(
Image.network('https://upload.wikimedia.org/wikipedia/commons/thumb/c/c3/Aurora_as_seen_by_IMAGE.PNG/640px-Aurora_as_seen_by_IMAGE.PNG').image,
);
_controller.loadNightSurface(
Image.network('https://upload.wikimedia.org/wikipedia/commons/b/ba/The_earth_at_night.jpg').image,
);
_controller.loadBackground(
Image.network('https://upload.wikimedia.org/wikipedia/commons/8/80/Hyades.jpg').image,
);
_addInteractiveObjects();
}
void _addInteractiveObjects() {
// 3. Add Point (e.g., London)
_controller.addPoint(
Point(
id: 'london',
coordinates: const GlobeCoordinates(51.5072, 0.1276),
label: 'London',
isLabelVisible: true,
style: const PointStyle(color: Colors.redAccent, size: 6),
onTap: () {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Tapped London!')),
);
},
),
);
// Add another point for connection
_controller.addPoint(
Point(
id: 'nyc',
coordinates: const GlobeCoordinates(40.7128, -74.0060),
label: 'New York',
style: const PointStyle(color: Colors.blueAccent, size: 6),
),
);
// 4. Add Connection (London -> NYC)
_controller.addPointConnection(
PointConnection(
id: 'london-nyc',
start: const GlobeCoordinates(51.5072, 0.1276),
end: const GlobeCoordinates(40.7128, -74.0060),
label: 'Transatlantic Route',
isLabelVisible: true,
style: const PointConnectionStyle(
type: PointConnectionType.dashed,
color: Colors.greenAccent,
dashAnimateTime: 2000,
),
),
);
// 5. Add Satellite (Orbiting)
_controller.addSatellite(
Satellite(
id: 'iss',
coordinates: const GlobeCoordinates(0, 0),
altitude: 0.1, // Normalized altitude
label: 'ISS',
orbit: SatelliteOrbit(
inclination: 51.6,
period: const Duration(seconds: 20),
),
style: const SatelliteStyle(
size: 8,
showOrbitPath: true,
color: Colors.white,
),
),
);
// 6. Set Sphere Style (Shadows)
_controller.setSphereStyle(
const SphereStyle(
shadowColor: Colors.black54,
shadowBlurSigma: 20,
),
);
// 7. Start Day/Night Cycle Animation
_controller.startDayNightCycle(cycleDuration: const Duration(seconds: 60));
}
// 8. Dynamic Atmosphere Adjustment
void _changeAtmosphere() {
_controller.setAtmosphereColor(Colors.purpleAccent.withOpacity(0.5));
}
// 9. Switch Day/Night Mode (Texture vs Simulated)
void _toggleNightMode() {
setState(() {
_isNightModeSimulated = !_isNightModeSimulated;
if (_isNightModeSimulated) {
_controller.setDayNightMode(DayNightMode.simulated);
_controller.setSimulatedNightColor(Colors.deepPurple.shade900);
} else {
_controller.setDayNightMode(DayNightMode.textureSwap);
}
});
}
// 10. Zoom / Reset View
void _resetView() {
// There isn't a direct "reset" method in the doc snippet,
// but we can re-initialize or manipulate points.
// Here we use clearPoints to demonstrate the 'clear' function group.
// To be safer and keep the demo running, we'll just toggle the sun position mode
_controller.setUseRealTimeSunPosition(true);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Synced to Real-Time Sun Position')),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
// Main Globe Widget
FlutterEarthGlobe(
controller: _controller,
radius: 120, // Base radius
),
// Control Panel
Positioned(
bottom: 20,
left: 20,
right: 20,
child: Card(
color: Colors.black54,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
IconButton(
icon: const Icon(Icons.wb_sunny),
onPressed: _changeAtmosphere,
tooltip: 'Change Atmosphere',
),
IconButton(
icon: Icon(_isNightModeSimulated ? Icons.bedtime : Icons.brightness_high),
onPressed: _toggleNightMode,
tooltip: 'Toggle Night Mode Type',
),
IconButton(
icon: const Icon(Icons.sync),
onPressed: _resetView,
tooltip: 'Real-time Sun',
),
],
),
),
),
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment