Custom progress indicator with GIF image - flutter

I want to make a dialog for progress indicator. I want to use GIF file.
This is the gif image:

The best way is to display the gif within the dialog box. You can do something like this:
// Currently transparent, change this to your desired background color
var _backgroundColor = Colors.transparent;
showDialog(
context: context,
barrierColor: _backgroundColor,
builder: (BuildContext dialogContext) {
return AlertDialog(
backgroundColor: _backgroundColor,
content: Container(
child: Center(
child: Image.asset(
'assets/test.gif', // Put your gif into the assets folder
width: 100,
),
),
),
);
},
);
Just a quick note, the GIF you chose have a solid background color. If you want to only display the progress indicator, you have 3 options:
Remove the background from the gif
Choose a gif with transparent background
Set the _backgroundColor to the same color as the background from the gif
P/s: Another options is to design an animation yourself using Flare/ Rive but it's a bit advance. You can read more here

Related

Flutter IconButton does not play animation if used for navigation, showing popup etc

I am using IconButtons in my application for opening popups, deleting ListTiles from ListViews, navigating to other views etc.
To my surprise the onPressed callback always gets triggered before the animation starts to play resulting in that the animation will not play at all. This is confusing to the user because there is no feedback that he pushed the button.
The setup looks something like this.
This is the code for the add button in the top right corner:
IconButton(
onPressed: () {
showDialog(
context: context,
builder: (context) {
return AddDevicePopup(
...
).build(context);
});
},
icon: const Icon(
Icons.add_circle_outline_rounded,
size: 30.0,
)
)
When the user taps the button the popup immediately appears but the animation won't get played.
This is the same for the IconButtons on the tiles:
the edit button opens a popup immediately and the ripple or splash animation won't play.
the delete button removes the element from the list. In this case the ListTile element gets removed and so the IconButton disappears without the animation getting played.
In every case there is a Material widget that is an ancestor of the IconButton so wrapping it in a Material widget does not solve the problem. I have double checked it by removing the showDialog part from the callback, in these cases all of the IconButtons play the splash / ripple animation as expected.
How do I make the onPressed to wait for the animation to at least be started. I did not find any solution. Is is possible to trigger this animation via code? In that case I can add that to the beginning of the onPressed callback.
To add animations, you must use showGeneralDialog instead of showDialog.
The implementation looks like this:
showGeneralDialog(
barrierDismissible: true,
barrierColor: Colors.black.withOpacity(0.5),
transitionDuration: const Duration(milliseconds: 200),
context: context,
pageBuilder: (_, __, ___) {
return AddDevicePopup(
...
).build(context);
},
//Customize your animation here
transitionBuilder: (_, a1, __, child) {
return Transform.scale(
scale: a1.value,
child: Opacity(
opacity: a1.value,
child: child,
),
);
},
);

Customize DateRangePicker in flutter

I want to customize DateRangePicker in flutter, How can I change the following elements?
Change the Save button to image.
Remove the Switch to input button.
Change the header background color.
Change day name color.
Change background color.
Change selected item indicator color.
Change selected item text color.
Change selected range indicator color.
Change selected range text color.
showDateRangePicker(
context: context,
firstDate: DateTime.now(),
lastDate: DateTime.now().add(Duration(days: 100)),
builder: (BuildContext context, Widget child) {
return Theme(
data: ThemeData(
...
),
child: child,
);
},
);
Most of these things can only be changed by modifying the source, as others have said before.
You can change the header background color by applying an appBarTheme in the builder callback of showDateRangePicker.
The text colors and the selection color can also be set via applying a theme, you need to use a ColorScheme to set them.
This example sets the header background to blue, the close icon to white, the header texts + the selected date texts to white, and the selection color to red:
final themeData = Theme.of(context);
showDateRangePicker(
context: context,
initialDateRange: initialDateRange,
firstDate: firstDate,
lastDate: lastDate,
currentDate: currentDate,
initialEntryMode: initialEntryMode,
helpText: helpText,
cancelText: cancelText,
confirmText: confirmText,
saveText: saveText,
errorFormatText: errorFormatText,
errorInvalidText: errorInvalidText,
errorInvalidRangeText: errorInvalidRangeText,
fieldStartHintText: fieldStartHintText,
fieldEndHintText: fieldEndHintText,
fieldStartLabelText: fieldStartLabelText,
fieldEndLabelText: fieldEndLabelText,
locale: locale,
useRootNavigator: useRootNavigator,
routeSettings: routeSettings,
textDirection: textDirection,
builder: (context, Widget? child) => Theme(
data: themeData.copyWith(
appBarTheme: themeData.appBarTheme.copyWith(
backgroundColor: Colors.blue,
iconTheme: themeData.appBarTheme.iconTheme!.copyWith(color: Colors.white)),
colorScheme: ColorScheme.light(
onPrimary: Colors.white,
primary: Colors.red
)),
child: child!,
));
Screenshot
#Michael Feinstein is right - to elaborate a little bit on what you have to do:
You need to copy date_range_picker_dialog.dart into your lib folder (you get there by clicking 'go to implementation' on showDateRangePicker()
You need to copy calendar_date_range_picker.dart (~ line 577 of date_range_picker_dialog.dart is where the actual picker widget is returned as body of the dialog)
You need to make the adjustments you want to do in both files. Your numbers 1-3 are in the dialog, have a look at the class _CalendarRangePickerDialog and change what you need. For your 6-9 look at _buildDayItem in the range picker file and the other 2 are also easy to find :-)
Don't forget to change the import in your copy of date_range_picker_dialog.dart so that you import your copy of the date_range_picker.dart, instead of the original one.
Now you are all set and good to go.
I copy below how to change almost everything you asked in terms of color customization:
showDateRangePicker(
context: context,
firstDate: DateTime.now(),
lastDate: DateTime.now().add(Duration(days: 100)),
builder: (BuildContext context, Widget child) {
return Theme(
data: ThemeData.light().copyWith(
//Header background color
primaryColor: Colors.blue,
//Background color
scaffoldBackgroundColor: Colors.grey[50],
//Divider color
dividerColor: Colors.grey,
//Non selected days of the month color
textTheme: TextTheme(
bodyText2:
TextStyle(color: Colors.black),
),
colorScheme: ColorScheme.fromSwatch().copyWith(
//Selected dates background color
primary: Colors.blue,
//Month title and week days color
onSurface: Colors.black,
//Header elements and selected dates text color
//onPrimary: Colors.white,
),
),
child: child,
);
}
);
For that level of customization you will need to get the source code, copy it, and then make your own widget modifying that source code.
You have could do this in two ways:
Fork a library which has the code to create something similar to this and then edit the code directly and customize how you want
Look for a library which allows more customizing to the date picker, below are a few:
Date picker 1
Date picker 2
Many more are available here
I created a package calendar_date_picker2 supporting high-level customisations, just simply wrap it inside a Container and set the container color as the background colors.

How does flutter make this style of widget?

Click the action of appBar to expand a pop-up window below, and click action again to shrink the pop-up window.Or is there a plugin recommendation with such an effect?
If view of you is simple view, you can use simple popup, see this tutorial.
If view of you complex more, you have to custom it. You need create Widget container both menu and expand part, custom display like main page. Then show it as dialog.
showGeneralDialog(
context: context,
barrierColor: Colors.black12.withOpacity(0.6), // background color
barrierDismissible: false, // should dialog be dismissed when tapped outside
barrierLabel: "Dialog", // label for barrier
transitionDuration: Duration(milliseconds: 400), // how long it takes to popup dialog after button click
pageBuilder: (_, __, ___) { // your widget implementation
FocusScope.of(context).requestFocus(_focusNodeCity);
return SafeArea(
child: Material(
color: Colors.transparent,
child: SizedBox.expand( // makes widget fullscreen
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
],
),
),
),
);
},
);

Flutter - Custom Paint Animation disappears from screen

I have some thumbnails with a custom paint animation, and i want to show the selected animation at the main container when the user tap the thumbnail.
This part is "ok". The problem is that the custom paint disappears a few seconds after ends the animation. And i'm setting the same widget from the thumbnail to the main container, but differently of the thumbnail, the custom paint doesn't remains after the animation ends on the main container. Someone has any idea of what can be the problem?
Here is a gif with what is happening.
The problem was related to the same question of this answer, but I couldn't figured it out because even the thumbnails are inside the stack. And I was getting the problem even setting the width and height for the parent container of the custom paint. I solved only wrapping the entire stack with a LayoutBuilder like the code bellow:
_buildContent() {
var ctxSize = MediaQuery.of(context).size;
return Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return Stack(
children: <Widget>[
//Code with CustomPaint
],
);
},
),
);
}

pop-up effect similar to dropDownMenuButton

I hope I can make this kind of pop-up effect similar to dropDownMenuButton. Is there any plugin or example that can be used for reference or help?
If you want a floating window i would suggest using a dialog.
To use a dialog you use a function and provide it with a context
This example should show a rounded corned white dialog with "YAY!" in the middle of it.
You close the dialog calling Navigator.of(context).pop() , and You could also use the align widget combined with padding to make it appear to the bottom, top, left, and right.
Touching on the backdrop of the dialog will also dismiss it.
void _showDialog(context) {
showDialog(
context: context,
builder: (BuildContext context) {
// return my custom widgets
return Center(
child: SizedBox(
width: 250.0,
height: 250.0,
child: Material( //Use material to use FlatButton, IconButton, InkWell, etc.
borderRadius: BorderRadius.all(Radius.circular(12.0)),
color: Colors.white,
child: Text('YAY!')
)));
},
);
}
Feel free to experiment.