diff --git a/lib/presentation/screens/birth_info/birth_info_screen.dart b/lib/presentation/screens/birth_info/birth_info_screen.dart new file mode 100644 index 0000000..2014a0d --- /dev/null +++ b/lib/presentation/screens/birth_info/birth_info_screen.dart @@ -0,0 +1,91 @@ +import 'package:flutter/material.dart'; + +import '../../../core/services/astrology-service.dart'; +import '../../../domain/entities/birth_card_request.dart'; +import '../../widgets/birth/birth_chart.dart'; + +class BirthInfoScreen extends StatefulWidget { + const BirthInfoScreen({super.key}); + + @override + State createState() => _BirthInfoScreenState(); +} + +class _BirthInfoScreenState extends State { + final AstrologyService _astrologyService = AstrologyService(); + String? _svgData; + bool _isLoading = false; + String? _errorMessage; + + @override + void initState() { + super.initState(); + _fetchBirthCard(); + } + + Future _fetchBirthCard() async { + setState(() { + _isLoading = true; + _errorMessage = null; + }); + final subject = Subject( + year: 1980, + month: 12, + day: 12, + hour: 12, + minute: 12, + longitude: 0.0, + latitude: 51.4825766, + city: 'London', + nation: 'GB', + timezone: 'Europe/London', + name: 'John Doe', + zodiacType: 'Tropic', + siderealMode: null, + ); + final request = BirthCardRequest( + subject: subject, + theme: 'classic', + language: 'EN', + ); + try { + final response = await _astrologyService.getBirthCard(request.toJson()); + setState(() { + _svgData = response['chart']; + + RegExp regex = RegExp(r"([\s\S]*?)<\/svg>"); + Match? match = regex.firstMatch(_svgData!); + + if (match != null) { + _svgData = match.group(0) ?? ""; + } + + _isLoading = false; + + }); + } catch (e) { + setState(() { + _errorMessage = 'Failed to load birth card: $e'; + _isLoading = false; + }); + } + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text('Birth Info'), + ), + body: Center( + child: _isLoading + ? CircularProgressIndicator() + : _errorMessage != null + ? Text(_errorMessage!) + : _svgData != null + ? BirthChart(svgData: _svgData!) + : Text('No data available'), + ), + ); + } +} diff --git a/lib/presentation/screens/splash/slides/welcome_page.dart b/lib/presentation/screens/splash/slides/welcome_page.dart index 412a45f..cb23af9 100644 --- a/lib/presentation/screens/splash/slides/welcome_page.dart +++ b/lib/presentation/screens/splash/slides/welcome_page.dart @@ -1,6 +1,8 @@ import 'package:first_app/presentation/screens/counter_screen.dart'; import 'package:flutter/material.dart'; +import '../../birth_info/birth_info_screen.dart'; + class WelcomePage extends StatelessWidget { const WelcomePage({super.key}); @@ -22,7 +24,7 @@ class WelcomePage extends StatelessWidget { // Navigate to the next screen Navigator.pushReplacement( context, - MaterialPageRoute(builder: (context) => CounterScreen()), + MaterialPageRoute(builder: (context) => BirthInfoScreen()), ); }, child: Text('Get Started'), diff --git a/test/widget_test.dart b/test/widget_test.dart deleted file mode 100644 index 84eacd6..0000000 --- a/test/widget_test.dart +++ /dev/null @@ -1,30 +0,0 @@ -// This is a basic Flutter widget test. -// -// To perform an interaction with a widget in your test, use the WidgetTester -// utility in the flutter_test package. For example, you can send tap and scroll -// gestures. You can also use WidgetTester to find child widgets in the widget -// tree, read text, and verify that the values of widget properties are correct. - -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:first_app/main.dart'; - -void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. - await tester.pumpWidget(const MyApp()); - - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); - - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); - }); -}