in my project I can press the save button to copy a file inside flutter in debug mode and every thing works fine (the file copied), but after build and open the release application I can't copy the file with no error message, just the button pressed and nothing happened.
I tried to run the release application as administrator, but it's the same problem.
Widget buildButton() {
final isFormValid = name.isNotEmpty && path.isNotEmpty;
return Padding(
padding: EdgeInsets.symmetric(vertical: 8, horizontal: 12),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
onPrimary: Colors.white,
primary: isFormValid ? null : Colors.grey.shade700,
),
onPressed: () async {
addOrUpdatePlan();
File PDF= File('assets/PDF/file.pdf');
File newPDF = await PDF.copy('$path/$name.pdf'); //////The Bug
},
child: Text(
'SAVE',
style: TextStyle(fontSize: 30),
),
),
);
}
You are using a relative path in your File constructor; that means that it will only work if the current working directory when the application is run happens to be the directory that the path is relative to. The working directory of an application is not controlled by where the application is, but how it was launched, so is not within your control as an application developer.
You should always use absolute paths, not relative paths, when writing applications. How you construct an absolute path for your use case depends on what the intended base directory is.
Related
I am developing a flutter app where appbar icon broke suddenly without any reason. Try to fix but nothing has been found yet.
enter image description here
AppBar(
actions: [
GestureDetector(
onTap: () {},
child: SvgPicture.asset(
iconSearch,
color: VisuColors.white,
),
),
]
)
According to the image and code that you provide, things that come to my mind are:
1- Try to give width and height to SvgPicture.asset like this:
SvgPicture.asset(
iconSearch,
color: VisuColors.white,
width: 15,
height: 15,
),
2- Check the color that you gave to SvgPicture.asset, maybe it has something related to the color.
3- If these 2 solutions didn't solve your problem, check your SVG file and try to use another SVG file to see if the problem is with the file that you use. Because sometimes, the SVG files may be broken (size, color, formatting etc.).
Before switching to flutter 3.3 everything worked fine
The essence of the problem: When testing on the emulator, I see in the console how the prints are displayed. But, if I plug in a real device, I don't see any output. Why?
Here are my two buttons:
Container(
margin: EdgeInsets.all(50),
child: ElevatedButton(onPressed: () {
_getCurrentLocation();
print('Тык точно был!');
}, child: Text('Test'))
),
ElevatedButton(onPressed: () {print('Text tipo tyt');}, child: Text('Test2'))
and of course I don't see any console output
try log inserted of print
log('Тык точно был!');
I would like to know whether or not it is possible to utilise the print(); command in flutter to create a String in order to link said data to a Firestore database.
I am creating a customer satisfaction application in which the customer would press a button on the screen and said button would then omit a message to the database corresponding the reaction the customer selected.
Only issue is: I have not found a way to link onPressed:in way that it can omit such data to a server or locally.
Here is a brief bit of code to somewhat witness what I am trying to achieve:
Align(alignment: Alignment.center,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
onPrimary: Colors.cyanAccent,
primary: Colors.deepPurple,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(55.0),
),
),
onPressed: () async {
print('Good Chosen');
print(DateTime.now());
HapticFeedback.mediumImpact();
// Close the screen and return "Good Chosen" as the result.
Navigator.pop(context, 'Good Chosen');
},
child: Image.asset('assets/good pixel.png'),
),
),
Have you considered writing the Good Chosen string directly to firestore?
Instead of / additionally to your print statements, you could write
FirebaseFirestore.instance.collection("feedback").doc()
.set({'type': 'good_chosen', 'timestamp': DateTime.now(),}, SetOptions(merge: true));
I need to write a flutter widget test to test a widget with GoogleFonts plugin in use. However, it gives network failer which is correct as the test suit doesn't have access to the internet. The problem is GoogleFonts.majorMonoDisplayTextTheme is a static method which makes it impossible to mock the GoogleFont class when using in the widget test.
Error: google_fonts was unable to load font MajorMonoDisplay-Regular because the following exception occurred:
Exception: Failed to load font with URL: https://fonts.gstatic.com/s/a/9901077f5681d4ec7e01e0ebe4bd61ba47669c64a7aedea472cd94fe1175751b.ttf
Widget usage:
Container(
padding: EdgeInsets.only(top: 10),
child: Text(
_now,
style: GoogleFonts.majorMonoDisplayTextTheme(Theme.of(context).textTheme).headline3,
),
),
Widget test method:
testWidgets(
'Shoudl display _now text',
(WidgetTester tester) async {
await tester.pumpWidget(_TestWidgetWithGoogleFont);
await tester.pumpAndSettle();
expect(find.byType(Text), findsOneWidget);
});
There is another way to silence the error. Especially handy if you don't want to (or can't) add additional files to a project.
Simply add this line of code to a desired test:
setUp(() => GoogleFonts.config.allowRuntimeFetching = false);
This code disallows runtime fetching which is a process that raises the erorr in the first place.
First you have to provide the font in pubspec.yaml file
Just follow those step
Download the fort extract it.
Go to your project file and create a folder name it "assets" and inside assets folder create another folder called "fonts". In this fonts folder paste the font .tiff copy the file name in this case it is"MajorMonoDisplay-Regular.ttf"
Next you have to provide the font information in pubspec.yaml file
just copy paste those code.
fonts:
- family: MajorMonoDisplay
fonts:
- asset: assets/fonts/MajorMonoDisplay-Regular.ttf
Next in open terminal run "flutter pub get"
and now just provide the fort family in your TextStyle.
Example:
child: Column(
children: [
Text(
'Should display _now text',
style: TextStyle(
fontSize: 20,
fontFamily: 'MajorMonoDisplay',
),
)
],
),
If the front is not showing then close the app and rerun it.
Sometimes after turning on my app, user see not rendered screen.
Buttons are available, but no labels and icons are printed.
I didn't notice it with debug version, only release.
In some cases restarting app helps, and sometimes user has to install the app again.
What may be causing this issue?
Broken screen:
And this is how it should look like
Code seems to be rather standard, e.g. logo, 'Slift' string is created this way:
#override
Widget build(BuildContext context) {
return BorderedText(
strokeWidth: strokeWidth,
strokeColor: ThemeColors.getColor3(),
child: Text(
'SLift',
style: GoogleFonts.baloo(
textStyle:
TextStyle(decoration: TextDecoration.none, fontSize: fontSize),
),
));
}
are you using MediaQuery in your code? Because sometimes it works differently on release and debug mode.