I'm trying to archive my flutter app in distributing it to testers first. I have made and added schemas in Xcode for different flavours of the app.
I also use amplify_core plugin.
First when I try to clean build it gave me an error saying
"Compiling for iOS 11.0, but module 'amplify_core' has a minimum deployment target of iOS 16.0:"
After a little bit of researching I've made the apmlify_core min deployment target to 11 under runner in Xcode pods.
Then the build was successful.
but when I try to do an archive it gives me this error
"package:/main.dart: Error: No 'main' method found. Try adding a method named 'main' to your program."
I will paste my main.dart and one flavour dart file for reference.
anyone can help me with his. ?
main.dart file
class MyApp extends StatelessWidget {
MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
final appRouter = AppRouter().router;
#override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
StreamProvider<EInternetStatus>(
create: (context) =>
ConnectionCheck().internetStatusController.stream,
initialData: EInternetStatus.iLoading,
),
],
child: MaterialApp.router(
debugShowCheckedModeBanner: AppEnvironment.flavour == EFlavour.fDev ||
AppEnvironment.flavour == EFlavour.fQa
? true
: false,
theme: FPTheme.lightTheme,
routerConfig: appRouter,
),
);
}
}
main_dev.dart file
Future<void> main() async {
AppEnvironment.setupEnv(EFlavour.fDev);
WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
await AmplifyServices().configureAmplify();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
SystemChrome.setEnabledSystemUIMode(SystemUiMode.leanBack);
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
setUp();
runApp(MyApp());
}
im not sure what I do here wrong? if anyone can help me out with this it would be amazing
How are you running your app?
i think you haven't configured build using flavours correctly in your editor
try using
flutter run -t lib/main_dev.dart
To configure your vs code to run with flavours try changing launch.json file.
"configurations": [
{
"name": "Flutter",
"request": "launch",
"type": "dart",
"program": "${workspaceFolder}/lib/main_dev.dart"
}].
You can also refer This stackoverflow answer
Related
I was trying to debug an issue I was having and I've seen in this answer an advice to set debugPrintScheduleBuildForStacks to true.
I've managed to find the docs for it however, nowhere on the internet I was able to find a guide on how to actually use them.
I've tried setting it as a global variable, a variable inside my widgets as well as changing it directly in the source file (debug.dart) however, I did not manage to see the debug logging as in the answer mentioned above.
Can someone explain, or point me to some docs on how to use it?
Inside build() in main.dart
I have used debugPrintScheduleFrameStacks.
You can replace it with debugPrintScheduleBuildForStacks.
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
debugPrintScheduleFrameStacks = true;
doc: https://pub.dev/documentation/flutter_for_web/latest/widgets/debugPrintScheduleBuildForStacks.html
I'm wrapping a SharedPreferences service class in a provider class that implements PreferencesProvider.of(context). It sets the theme as follows:
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return StreamBuilder(
stream: PreferencesProvider.of(context).service.isDark,
initialData: PreferencesProvider.of(context).service.isDark.value, //its an rxDart ValueObservable
builder: (context, snapshot) => MaterialApp(
theme: ThemeData(
brightness: snapshot.data ? Brightness.dark : Brightness.light,
primarySwatch: Colors.blue,
///etc etc etc
Widgets can change the theme simply with PreferencesProvider.of(context).service.toggleIsDark(). It works well, but it takes about 3 seconds of being frozen to change theme on my device. On the emulator, it happens instantly.
Any possible leads on debugging this would be great. I've tried using the Dart Observatory Timeline but I couldn't see anything helpful (I couldn't make much sense of it).
This was happening because I was creating my BLoCs in the outermost build function. I moved creation to main() and passed in the created BLoCs which solved the problem. Don't create anything except widgets in build functions!
I had a Dart trouble, the vscode analyzer stopped without reason.
I reinstall vscode/dart/flutter, then get packages again and nothing happens.
I found this strange non-logic problem
class MyApp extends StatelessWidget {
String get isWhatever:ist => "";
// This widget is the root of your application.
#override
...
}
I discovered I accidentally commited a : instead L, the function name was isWhatever:ist instead isWhateverList. Somebody know why?
I'm having a terrible time getting this program to run. I keep getting compiler troubles when I run the code. See specifics below. Anybody understand what's going on here?
My code extract from file TapScreenToo.dart:
import 'profiles.dart';
import 'package:flutter/material.dart';
import 'cards.dart';
class PageTapScreen extends StatefulWidget {
final List<Profile> profileList;
Key key;
PageTapScreen({
this.key,
this.profileList,
}) : super(key: key); // constructor
#override
_PageTapScreenState createState() => new _PageTapScreenState();
}
The profile class in file profiles.dart (no import statement there):
class Profile {
final String ttaKey;
final String imageUrl;
final String displayName;
Profile({
this.ttaKey,
this.imageUrl,
this.displayName,
});
}
my profile list from file demoProfiles.dart:
import 'profiles.dart';
final List<Profile> demoProfiles = [
new Profile(
ttaKey: "0",
imageUrl: 'http://localhost:8080/photo_0.jpg',
displayName: 'abc',
),
new Profile(
ttaKey: "1",
imageUrl: 'http:// ... etc
),
]
And all of this gets called in main.dart
import 'package:flutter/material.dart';
import 'tapScreenToo.dart';
import 'demoProfiles.dart';
class _MyHomePageState extends State<MyHomePage> {
final Key keyOne = PageStorageKey('pageOne');
...
#override
void initState() {
tapScreen = PageTapScreen(
key: keyOne,
profileList: demoProfiles, <--- error points here
);
I'm getting a compiler message at the time of initiation:
compiler message: lib/main.dart:68:20: Error: A value of type 'dart.core::List<#lib1::Profile>' can't be assigned to a variable of type 'dart.core::List<#lib2::Profile>'.
compiler message: Try changing the type of the left hand side, or casting the right hand side to 'dart.core::List<#lib2::Profile>'.
compiler message: profileList: demoProfiles,`
I've tried to cast (List <Profile>) but that seems to be a fail, or I'm just doing it wrong.
Note: when I remark out the error line, and debug step to the failure location, I can see that the values for both keyOne and demoProfiles are exactly as expected. Note, these code snippets are located in different files, linked via import commands.
As I look at the rest of the code, I can see where import 'profiles.dart' gets called multiple times.
I don't understand the error message. I've also studied this posting with a similar error, but I'm just not seeing what's going on with this code, nor how to fix it.
You need to change the imports in the main.dart:
import 'tapScreenToo.dart';
import 'demoProfiles.dart';
Since the main.dart can only have packages: imports which are called absolute imports.
Therefore change the imports to:
import package:mypackage/path/tapScreenToo.dart
import package:mypackage/path/demoProfiles.dart
Check this:
Error: A value of type 'List<#lib1::Data>' can't be assigned to a variable of type 'List<#lib2::Data>
https://github.com/dart-lang/sdk/issues/33076
https://www.dartlang.org/tools/pub/get-started#importing-libraries-from-packages
I'm trying to obtain the top-level state of my app using a .of()-method, similar to the Scaffold.of() function. This is the (stripped down) code:
class IApp extends StatefulWidget {
#override
IAppState createState() => new IAppState();
static IAppState of(BuildContext context) =>
context.ancestorStateOfType(const TypeMatcher<IAppState>());
}
The app is started using runApp(new IApp)
This Widget creates a HomePage:
#override
Widget build(BuildContext context) {
return new MaterialApp(
// ommitted: some localization and theming details
home: new HomePage(),
);
}
Then, I try to access the State from the HomePage (a StatefulWidget itself):
#override
Widget build(BuildContext context) {
return new Scaffold(
// ommited: some Scaffold properties such as AppBar
// runtimeType not actual goal, but just for demonstration purposes
body: new Text(IApp.of(context).runtimeType.toString()),
);
}
The strange this is, the code works when I place the code for HomePage in the same file as the IApp, but just as an extra class. However, when I place HomePage in a separate file (main.dart and homepage.dart importing each other), the return value of IApp.of(context) is null.
What causes this? And how can I fix it?
TDLR: imports file only using
import 'package:myApp/path/myFile.dart';
Never with
import './myFile.dart';
This is due to how dart resolves imports.
You may have a single source file, but during builds, there is some kind of duplicates.
Let's say you're working on 'myApp'. To import a file, you could do both :
import 'relativePath/myFile.dart'
import 'package:myApp/path2/myFile.dart'
You'd think that they point to the same file right?
But no. One of them will point to the original source. While the other one will point to a temporary file used for the build.
The problem comes when you start to mix both solutions. Because for the compiler, these two files are different. Which means that IApp imported from package:myApp/IApp is not equal to the same IApp imported from relativePath/myApp/IApp
In your case, you inserted in your widget tree an IApp from pakage:path but your IApp.of(context) use IAppState resolved locally.
They both have a different runtimeType. Therefore const TypeMatcher<IAppState>() won't match. And your function will return null.
There's an extremely easy way to test this behavior.
Create a test.dart file containing only
class Test {
}
then in your main.dart add the following imports :
import 'package:myApp/test.dart' as Absolute;
import './test.dart' as Relative;
You can finally test this by doing :
new Relative.Test().runtimeType == new Absolute.Test().runtimeType
Spoiler: the result is false
Now you can use the relative path.
You can verify this, as Remy suggested two years ago:
Relative.Test().runtimeType == Absolute.Test().runtimeType
Spoiler: the result is true