-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
get.snackbar's selfsize #3075
Comments
@tospery If this helps you can close the issue To display an icon and messageText in a import 'package:flutter/material.dart';
import 'package:get/get.dart';
void showCustomSnackbar() {
Get.snackbar(
'Title',
'',
messageText: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.info, color: Colors.white),
SizedBox(width: 8),
Expanded(
child: Text(
'Your message here',
style: TextStyle(color: Colors.white),
),
),
],
),
backgroundColor: Colors.black,
snackPosition: SnackPosition.BOTTOM,
borderRadius: 8,
margin: EdgeInsets.all(10),
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
boxShadows: [
BoxShadow(
color: Colors.black.withOpacity(0.5),
spreadRadius: 1,
blurRadius: 10,
),
],
duration: Duration(seconds: 3),
);
} Explanation:
Usage:You can call import 'package:flutter/material.dart';
import 'package:get/get.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GetMaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Snackbar Example')),
body: Center(
child: ElevatedButton(
onPressed: showCustomSnackbar,
child: Text('Show Snackbar'),
),
),
),
);
}
} This will display a |
If you want to call it from the controller alsoSure, let's simplify the implementation by removing the Controller ImplementationFile: import 'package:get/get.dart';
import 'package:flutter/material.dart';
class SnackbarController extends GetxController {
void showCustomSnackbar() {
Get.snackbar(
'Title',
'',
messageText: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.info, color: Colors.white),
SizedBox(width: 8),
Expanded(
child: Text(
'Your message here',
style: TextStyle(color: Colors.white),
),
),
],
),
backgroundColor: Colors.black,
snackPosition: SnackPosition.BOTTOM,
borderRadius: 8,
margin: EdgeInsets.all(10),
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
boxShadows: [
BoxShadow(
color: Colors.black.withOpacity(0.5),
spreadRadius: 1,
blurRadius: 10,
),
],
duration: Duration(seconds: 3),
);
}
} View ImplementationExplanation:
Final Code for
|
thanks |
How do I use get.snackbar to display icon and messageText in itself size, instead of maxWidth?
The text was updated successfully, but these errors were encountered: