-
Notifications
You must be signed in to change notification settings - Fork 2
Fix app initialization: localization wiring, DB init, package name, and widget test #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" | ||
| #include "Generated.xcconfig" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" | ||
| #include "Generated.xcconfig" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # Uncomment this line to define a global platform for your project | ||
| # platform :ios, '13.0' | ||
|
|
||
| # CocoaPods analytics sends network stats synchronously affecting flutter build latency. | ||
| ENV['COCOAPODS_DISABLE_STATS'] = 'true' | ||
|
|
||
| project 'Runner', { | ||
| 'Debug' => :debug, | ||
| 'Profile' => :release, | ||
| 'Release' => :release, | ||
| } | ||
|
|
||
| def flutter_root | ||
| generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) | ||
| unless File.exist?(generated_xcode_build_settings_path) | ||
| raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" | ||
| end | ||
|
|
||
| File.foreach(generated_xcode_build_settings_path) do |line| | ||
| matches = line.match(/FLUTTER_ROOT\=(.*)/) | ||
| return matches[1].strip if matches | ||
| end | ||
| raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" | ||
| end | ||
|
|
||
| require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) | ||
|
|
||
| flutter_ios_podfile_setup | ||
|
|
||
| target 'Runner' do | ||
| use_frameworks! | ||
|
|
||
| flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) | ||
| target 'RunnerTests' do | ||
| inherit! :search_paths | ||
| end | ||
| end | ||
|
|
||
| post_install do |installer| | ||
| installer.pods_project.targets.each do |target| | ||
| flutter_additional_ios_build_settings(target) | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,18 +1,24 @@ | ||||||||||||||
| import 'package:flutter/material.dart'; | ||||||||||||||
|
|
||||||||||||||
| void main() { | ||||||||||||||
| import 'generated/app_localizations.dart'; | ||||||||||||||
| import 'database/database_helper.dart'; | ||||||||||||||
|
|
||||||||||||||
| void main() async { | ||||||||||||||
| WidgetsFlutterBinding.ensureInitialized(); | ||||||||||||||
| await DatabaseHelper().initDB(); | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use Line 8 currently calls Proposed fix void main() async {
WidgetsFlutterBinding.ensureInitialized();
- await DatabaseHelper().initDB();
+ await DatabaseHelper().getDB();
runApp(const MyApp());
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| runApp(const MyApp()); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| class MyApp extends StatelessWidget { | ||||||||||||||
| const MyApp({super.key}); | ||||||||||||||
|
|
||||||||||||||
| // This widget is the root of your application. | ||||||||||||||
| @override | ||||||||||||||
| Widget build(BuildContext context) { | ||||||||||||||
| return MaterialApp( | ||||||||||||||
| title: 'Carbon Tracker', | ||||||||||||||
| debugShowCheckedModeBanner: false, | ||||||||||||||
| localizationsDelegates: AppLocalizations.localizationsDelegates, | ||||||||||||||
| supportedLocales: AppLocalizations.supportedLocales, | ||||||||||||||
| theme: ThemeData( | ||||||||||||||
| colorScheme: ColorScheme.fromSeed(seedColor: Colors.lightGreen), | ||||||||||||||
| ), | ||||||||||||||
|
|
@@ -27,7 +33,7 @@ class MyHomePage extends StatelessWidget { | |||||||||||||
| @override | ||||||||||||||
| Widget build(BuildContext context) { | ||||||||||||||
| return Scaffold( | ||||||||||||||
| appBar: AppBar(title: const Text('Carbon Tracker')), | ||||||||||||||
| appBar: AppBar(title: Text(AppLocalizations.of(context)?.hello ?? 'Carbon Tracker')), | ||||||||||||||
| body: const Center(child: Text('Welcome to Carbon Tracker!')), | ||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,13 @@ | ||
| // 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:template_flutter/main.dart'; | ||
| import 'package:carbon_tracker/main.dart'; | ||
|
|
||
| void main() { | ||
| testWidgets('Counter increments smoke test', (WidgetTester tester) async { | ||
| // Build our app and trigger a frame. | ||
| testWidgets('App renders welcome screen with localized hello', | ||
| (WidgetTester tester) async { | ||
| 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); | ||
| expect(find.text('Hello'), findsOneWidget); | ||
| expect(find.text('Welcome to Carbon Tracker!'), findsOneWidget); | ||
| }); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: AOSSIE-Org/CarbonTracker
Length of output: 593
🏁 Script executed:
Repository: AOSSIE-Org/CarbonTracker
Length of output: 2906
🏁 Script executed:
Repository: AOSSIE-Org/CarbonTracker
Length of output: 2906
Cast decoded transport arrays to
List<String>inUser.fromMap.User.fromMapassigns rawjsonDecode(...)(for JSON arrays this is typicallyList<dynamic>) into fields typed asList<String>, which can fail with a runtime type error when constructingUser.Proposed fix
factory User.fromMap(Map<String, dynamic> map) { return User( id: map['id'], - preferredTransports: jsonDecode(map['preferred_transports']), - frequentTransports: jsonDecode(map['frequent_transports']), + preferredTransports: + List<String>.from(jsonDecode(map['preferred_transports']) as List), + frequentTransports: + List<String>.from(jsonDecode(map['frequent_transports']) as List), trackingMode: map['tracking_mode'], weight: (map['weight'] as num).toDouble(), sustainabilityThoughts: map['sustainability_thoughts'], lastResetMonth: map['last_reset_month'], lastResetYear: map['last_reset_year'], ); }🤖 Prompt for AI Agents