Attempting to set the box constraints of a Row widget in Flutter - ios

Okay, so I'm using Flutter, and trying to set constraints of an entire Row widget to the
width of the screen, NOT set the constraints of each individual part of the row. I've searched
everywhere, and a Row widget does not HAVE a width or max width parameter to set (It sets it to
infinity for some reason) and ONE of the two things inside the row HAS to be a textfield (I'm
developing on iOS so I'm using a CupertinoTextField, but that shouldn't make a difference.
An example of the body of a scaffold widget would be:
body: Container(
constraints: BoxConstraints.tight(new Size(MediaQuery.of(context).size.width, double.infinity)),
child: Row(
children: [
FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
CupertinoTextField(
textInputAction: TextInputAction.done,
keyboardType: TextInputType.text,
onSubmitted: (value) {
notes = value;
},
controller: textInput,
),
],
)
)
As you can imagine, I'm getting unbounded render box errors, as the row is NOT getting bounded
properly, and I have no idea why Flutter won't let me set the counting box for the entire row.
(Or if it does, it's not doing it in the way I'm doing!)
Results of Flutter Doctor -v
[✓] Flutter (Channel master, v1.14.2-pre.20, on Mac OS X 10.15.2 19C57, locale
en-CA)
• Flutter version 1.14.2-pre.20 at /Users/iosdev/Developer/flutter
• Framework revision 91f8d3da32 (2 hours ago), 2020-01-16 18:21:16 +0000
• Engine revision e0fe834288
• Dart version 2.8.0 (build 2.8.0-dev.2.0 009537bbf0)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/iosdev/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling
support)
• Platform android-29, build-tools 29.0.2
• Java binary at: /Applications/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build
1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.3.1, Build version 11C504
• CocoaPods version 1.8.4
[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 42.1.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build
1.8.0_202-release-1483-b49-5587405)
[✓] Connected device (1 available)
• Phillip’s iPhone • 52a4fba45a6767b88e4dddd881201205138cac0e • ios • iOS
13.3
• No issues found!

You just need to wrap your CupertinoTextField with an Expanded widget:
Container(
child: Row(
children: [
FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
Expanded(
child: CupertinoTextField(
textInputAction: TextInputAction.done,
keyboardType: TextInputType.text,
onSubmitted: (value) {
notes = value;
},
controller: textInput,
),
),
],
)
)

Related

flutter video_player is not working on IOS devices. Even though it works on android devices

I'm trying to use video_player in flutter to show network videos in mp4 format (https://www.heygold.com/media/reel/ThisorThat.mp4). On IOS devices it never sets _controller.value.isInitialized to true.
I'm using:
video_player: 2.4.7
Output of flutter doctor -v:
[✓] Flutter (Channel stable, 3.3.9, on macOS 12.6 21G115 darwin-arm, locale en-DE)
• Flutter version 3.3.9 on channel stable at /Users/casparbaumeister/development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision b8f7f1f986 (2 weeks ago), 2022-11-23 06:43:51 +0900
• Engine revision 8f2221fbef
• Dart version 2.18.5
• DevTools version 2.15.0
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
• Android SDK at /Users/casparbaumeister/Library/Android/sdk
• Platform android-33, build-tools 32.1.0-rc1
• Java binary at: /Users/casparbaumeister/development/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14B47b
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.1)
• Android Studio at /Users/casparbaumeister/development/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
[✓] VS Code (version 1.73.1)
• VS Code at /Users/casparbaumeister/development/Visual Studio Code.app/Contents
• Flutter extension version 3.54.0
[✓] Connected device (3 available)
• sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 12 (API 32) (emulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 12.6 21G115 darwin-arm
• Chrome (web) • chrome • web-javascript • Google Chrome 108.0.5359.94
[✓] HTTP Host Availability
• All required HTTP hosts are available
Video player page:
class ReelsPage extends StatefulWidget {
const ReelsPage({Key? key, required this.videoUrl}) : super(key: key);
final String videoUrl;
#override
_ReelsPageState createState() => _ReelsPageState();
}
class _ReelsPageState extends State<ReelsPage> {
late VideoPlayerController _controller;
#override
void initState() {
super.initState();
_controller = VideoPlayerController.network(widget.videoUrl)
..addListener(() => setState(() {}))
..setLooping(true)
..initialize().then((_) => _controller.play());
}
#override
void dispose() {
_controller.dispose();
super.dispose();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: IconButton(
icon: Icon(Icons.arrow_back_ios_new_rounded, color: GOLDISH),
onPressed: () {
Navigator.of(context).pop();
},
),
automaticallyImplyLeading: true,
backgroundColor: Colors.black,
elevation: 0,
),
body:
_controller.value.isInitialized
? show video
: Loading <- never leaves this state
)
);
}
}
My info.plist includes the following lines:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
</dict>
It works totally fine on android emulator and device. I know that it doest work on IOS emulators, but it also does not work on IOS devices. Every help is welcomed, also recommendations for other video player packages! Thanks in regard.

Flutter (web) Provider not working in released mode, but working in debug

I'm experiencing some odd behavior where a Provider behaves differently in debug vs. release mode.
This question is posted in off this question.
Here is a short description of the functionality: I have a list of ExpansionTiles (containing TextFormFields in their body) and a FloatingActionButton that adds to the list of ExpansionTiles. Below those two widgets I have one Back button and one Next button. The Next button needs be "unavailable" (ie. throw an error message to the user and have the color grey) as long as any TextFormField in the list of ExpansionTiles is incomplete. Once all TextFormFields are ready the Next button should change color and direct the user to a new page. Changing the color and functionality works fine in debug, but not in release mode (ie. after running: flutter build web).
Firstly: TravelProceedModel monitors the status of whether the user can click the Next button or not. Ie. this is just a simple bool. Whenever updateCanProceed() is called I update canProceed and also notifyListeners().
import 'package:flutter/material.dart';
class TravelProceedModel extends ChangeNotifier {
bool canProceed;
void updateCanProceed(bool value) {
canProceed = value;
notifyListeners();
}
}
Secondly, the TravelProceedModel is implemented using the ChangeNotifierProvider and then using Consumer. I'm expecting (and this works in debug) that when canProceed is changed this line: "nextEnabled: proceedModel.canProceed" should cause the button the change color. However, this only works in debug mode.
class TravelDeductionTrips extends StatefulWidget {
#override
_TravelDeductionTripsState createState() => _TravelDeductionTripsState();
}
class _TravelDeductionTripsState extends State<TravelDeductionTrips> {
#override
Widget build(BuildContext context) {
String year = Provider.of<UserSelectionsModel>.(context).selected_report["year"];
String report = Provider.of<UserSelectionsModel>(context).selected_report["report"];
return MultiProvider(
providers: [
ChangeNotifierProvider(
create: (context) => TravelProceedModel()
),
ChangeNotifierProvider(
create: (context) => TravelModel(
year: year,
report: report,
),
),
],
child: Consumer<TravelModel>(
builder: (context, travelModel, child) {
return FutureBuilder(
future: travelModel.fetchTripsToLocalSession(),
builder: (context, data) {
if (data.connectionState == ConnectionState.done) {
return Column(
children: <Widget>[
TravelDeductionTripList(),
Consumer<TravelProceedModel>(
builder: (context, proceedModel, child) {
proceedModel.updateCanProceed(
travelModel.checkProceedCondition()
);
return BackNextButtons(
backEnabled: true,
nextEnabled: proceedModel.canProceed,
backText: "Tilbage",
nextText: travelModel.trips["next_action_title"],
errorMessage: travelModel.proceedErrorMessage,
nextFunction: () async {
await addQuestionIDtoStack(year, report, travelModel.trips["next_question_id"], true);
}, // No special function is needed, this is just a simple next
);
},
),
],
);
} else {
return Center(
child: CircularProgressIndicator(),
);
}
}
);
}
),
);
}
}
NB! proceedModel.canProceed is updated from within TravelDeductionTripList() which calls
Provider.of<TravelProceedModel>(context, listen: false).updateCanProceed(
Provider.of<TravelModel>(context, listen: false).checkProceedCondition()
);
The Next button only changes colors after reloading the widget. Ie. it appears that the TravelProceedModel is being updated but that the widget is not being redrawn in the UI - although it happens perfectly in debug mode.
Does anybody have any idea why debug works but release does not?
Below is my "flutter doctor -v". Notice, that this is a flutter web project.
[✓] Flutter (Channel beta, v1.15.17, on Mac OS X 10.15.2 19C57, locale en-US)
• Flutter version 1.15.17 at /Users/danni/Documents/flutter/flutter
• Framework revision 2294d75bfa (13 days ago), 2020-03-07 00:28:38 +0900
• Engine revision 5aff311948
• Dart version 2.8.0 (build 2.8.0-dev.12.0 9983424a3c)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/danni/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.
[✗] Xcode - develop for iOS and macOS
✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
Download at: https://developer.apple.com/xcode/download/
Or install Xcode via the App Store.
Once installed, run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch
✗ CocoaPods installed but not working.
You appear to have CocoaPods installed but it is not working.
This can happen if the version of Ruby that CocoaPods was installed with is different from the one being used
to invoke it.
This can usually be fixed by re-installing CocoaPods. For more info, see
https://github.com/flutter/flutter/issues/14293.
To re-install CocoaPods, run:
sudo gem install cocoapods
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 41.0.2
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] VS Code (version 1.43.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.8.1
[✓] Connected device (2 available)
• Chrome • chrome • web-javascript • Google Chrome 80.0.3987.149
• Web Server • web-server • web-javascript • Flutter Tools
! Doctor found issues in 1 category.
I had the same problem, and I've made a workaround for it.
Since listen is a parameter, you can pass any other bool variable to it (should not be a constant true or false).
There is a built-in bool variable in foundation.dart package called kReleaseMode.
So here is an example, how i handled this listener problem between debug and release mode:
await Provider.of<AuthService>(context, listen: kReleaseMode).loginUser(
user: _username, password: _password);
For me, it works perfectly.

Flutter with firebase_messaging - how to custom message on permission dialog?

I'm using fcm and firebase_messaging to send push notification to flutter app, and want to custom permission message when executing FirebaseMessaging().requestNotificationPermissions for ios remote notification.
Now I have permission dialog below
How to custom '"" Would Like to Send You Notifications', 'Notifications may include alerts, sounds, and icon...', and 'Don't Allow/Allow'? Does anyone any idea?
and my code
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
await _firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(
sound: true, badge: true, alert: true));
await _firebaseMessaging.onIosSettingsRegistered.listen((settings) {
debugPrint('Settings registered: $settings');
});
Here's my flutter doctor -v result
[✓] Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.15.1 19B88, locale ja-JP)
• Flutter version 1.12.13+hotfix.5 at /usr/local/bin/flutter
• Framework revision 27321ebbad (6 weeks ago), 2019-12-10 18:15:01 -0800
• Engine revision 2994f7e1e6
• Dart version 2.7.0
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/shunmanabe/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.3.1, Build version 11C504
• CocoaPods version 1.8.4
[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 42.1.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] VS Code (version 1.41.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.7.1
[✓] Connected device (1 available)
• iPhone 11 • 4B5E0CE0-8D25-49CC-BEBA-0BDE35991977 • ios •
com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator)
• No issues found!
Thanks in advance!
first update to the latest firebase messaging dependency in your pubspec.yaml file
firebase_messaging: ^9.1.0
then create an instance of firebase messaging
final FirebaseMessaging firebaseMessaging = FirebaseMessaging.instance;
then request for the permission
Future initialize(context) async {
if (Platform.isIOS) {
firebaseMessaging.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
}
}
In my case i updated the firebase dependency firebase_messaging: ^10.0.2 and replace
_fcm.requestNotificationPermissions(const IosNotificationSettings())
to
_fcm.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
but we will have to change
_fcm.configure()
as well, change it with below code.
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
RemoteNotification _notification = message.notification;
AndroidNotification _android = message.notification?.android;
});
and problem solved.

Why CustomClipper is not working suddenly?

I'm studying clipping image as curve, but CustomClipper is not working suddenly.
Only clipper property of IreneClipper not works. How can I fix it?
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Clock',
theme: ThemeData(
primarySwatch: Colors.blue
),
home: IreneClip(),
);
}
}
class IreneClip extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(backgroundColor: Colors.orange,),
body: ClipPath(
child: Image.asset('assets/irene.jpg'),
clipper: IreneClipper(),
),
);
}
}
class IreneClipper extends CustomClipper<Path> {
#override
Path getClip(Size size) {
Path path = Path();
path.moveTo(0.0, size.height);
return Path();
}
#override
bool shouldReclip(CustomClipper<Path> oldClipper) {
return false;
}
}
Error message
I/flutter (25014): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY
╞═════════════════════════════════════════════════════════ I/flutter
(25014): The following assertion was thrown during performLayout():
I/flutter (25014): The _ScaffoldLayout custom multichild layout
delegate forgot to lay out the following child: I/flutter (25014):
_ScaffoldSlot.body: RenderClipPath#ab20f NEEDS-LAYOUT NEEDS-PAINT I/flutter (25014): Each child must be laid out exactly once. I/flutter
(25014): I/flutter (25014): When the exception was thrown, this was
the stack: I/flutter (25014): #0
MultiChildLayoutDelegate._callPerformLayout.
(package:flutter/src/rendering/custom_layout.dart:222:13) I/flutter
(25014): #1 MultiChildLayoutDelegate._callPerformLayout
(package:flutter/src/rendering/custom_layout.dart:230:8)
Flutter doctor
[√] Flutter (Channel beta, v1.0.0, on Microsoft Windows [Version 10.0.17134.472], locale ko-KR)
• Flutter version 1.0.0 at C:\flutter
• Framework revision 5391447fae (5 weeks ago), 2018-11-29 19:41:26 -0800
• Engine revision 7375a0f414
• Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)
[√] Android toolchain - develop for Android devices (Android SDK 28.0.3)
• Android SDK at C:\AndroidSDK
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• ANDROID_HOME = C:\AndroidSDK
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
• All Android licenses accepted.
[√] Android Studio (version 3.2)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 31.3.1
• Dart plugin version 181.5656
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
[!] IntelliJ IDEA Community Edition (version 2018.2)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.2
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
• For information about installing plugins, see
https://flutter.io/intellij-setup/#installing-the-plugins
[!] VS Code, 64-bit edition (version 1.30.1)
• VS Code at C:\Program Files\Microsoft VS Code
• Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[√] Connected device (1 available)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)
I solved, shouldReclip method must return true if you want to hot reload clipping image.
class IreneClipper extends CustomClipper<Path> {
#override
Path getClip(Size size) {
Path path = Path();
path.lineTo(0.0, size.height-40);
path.lineTo(size.width, size.height-60);
path.lineTo(size.width, 0.0);
path.close();
return path;
}
#override
bool shouldReclip(CustomClipper<Path> oldClipper) {
return true;
}
}
You need to wrap it with like:
Column(
children: [
SafeArea(
child: SingleChildScrollView(
child: Column(
children: [
Stack(
clipBehavior: Clip.none,
children: <Widget>[
// stack overlaps widgets
ClipPath(
clipper: YOURCUSTOMCLIPPER(),
child: Container(
width: MediaQuery.of(context).size.width,
height: 140,
color: Colors.red,
),
),
],
),
],
),
),
),
],
),

NetworkImage does not work to render url

I tried to render a image with the _renderImage method using a NetworkImage but all what shows up is a big red square. When I render with the _renderImage2 method using Image.network it works fine. unfortunatly I need the decorations from and the boder radius of renderImage. Why does it not work?
Container _renderImage(GroupMessageController message) => new Container(
width: 300.0,
margin: const EdgeInsets.all(5.0),
decoration: new BoxDecoration(
borderRadius: const BorderRadius.all(const Radius.circular(25.0)),
image: new DecorationImage(
fit: BoxFit.contain,
image: new NetworkImage(message.mediaUrl.toString()))));
Container _renderImage2(GroupMessageController message) => new Container(
width: 300.0,
child: new Image.network(
message.mediaUrl.toString(),
fit: BoxFit.contain,
),
);
[√] Flutter (on Microsoft Windows [Version 10.0.16299.64], locale en-US, channel alpha)
• Flutter at c:\sdks\flutter
• Framework revision e8aa40eddd (5 weeks ago), 2017-10-17 15:42:40 -0700
• Engine revision 7c4142808c
• Tools Dart version 1.25.0-dev.11.0
[√] Android toolchain - develop for Android devices (Android SDK 27.0.1)
• Android SDK at C:\Users\ride4\AppData\Local\Android\sdk
• Platform android-27, build-tools 27.0.1
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b01)
[√] Android Studio (version 3.0)
• Android Studio at C:\Program Files\Android\Android Studio
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b01)
[√] IntelliJ IDEA Community Edition (version 2017.2)
• Flutter plugin version 19.1
• Dart plugin version 172.4343.25
[√] Connected devices
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 7.1.1 (API 25) (emulator)
There's a difference between using decoration property and Image widget.
Using decoration of DecoratedBox is like defining a background image of your box. But since your DecoratedBox has no child at all, then it has a default size of 0x0.
On the other hand, Image has a different purpose and will have a size.
edit
return new DecoratedBox(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new NetworkImage("https://displate.com/displates/2017-09-04/7b4f0a94798f5d8c1ea094984c766911_0dc0c70583e9e27897d5c0125acac0c1.jpg?h=357&w=500&v=3"),
),
),
child: new SizedBox(
width: 300.0,
height: 300.0,
),
);

Resources