Color gradients take a starting color and position and ending color and position. Then it performs a transition between the colors. With consideration for color theory, they can make an application more visually interesting than a plain design. |
import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, visualDensity: VisualDensity.adaptivePlatformDensity, ), home: MyHomePage(), ); } } class MyHomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Flutter Gradient Example'), ), body: Center( child: Container( decoration: BoxDecoration( gradient: LinearGradient( begin: Alignment.topRight, end: Alignment.bottomLeft, colors: [ Colors.blue, Colors.red, Colors.green, Colors.yellow ], ) ), child: Center( child: Text( 'Hello Gradient!', style: TextStyle( fontSize: 48.0, fontWeight: FontWeight.bold, color: Colors.white, ), ), ), ), ), ); } } |
Compile your code and have it run in an emulator: This creates a linear gradient that starts at 0.0 of the way down the screen with blue then red then green and last yellow. |
Wednesday, September 28, 2022
How To Use Gradients in Flutter with BoxDecoration and GradientAppBar
Create Script To Copy Files From One Folder To Another On Windows 10 - Batch file to copy files from one folder to another folder
The batch script, also known as batch file, actually refers to a list of several commands; whenever you double-click the file, the commands will be executed. If you want to copy files or folders from one folder to another automatically, creating a batch script is a nice choice. As for how to get the work done. |
Yet, do you want to automatically move files from one folder to another? The copying and pasting process can be finished quickly by using the Windows command line. |
You can create a batch file to copy data in a file from one place to another place on your computer automatically. The following steps are finished on Windows 10. 1. Open Windows search. 2. Type notepad. 3. Open the Notepad app. 4. Copy & paste the script into the new Notepad file. 5. Select File -> Save As. 6. Give it a name like copy_file.bat 7. Select All Files. 8. Click Save to finish creating the batch file. |
Step four: type the following script in or copy & paste it into Notepad. This will copy source_file.txt to destination folder @echo off set "source=C:\Users\developer\Desktop\source_file.txt" set "destination=C:\Users\developer\Desktop\" xcopy /s %source% %destination% /Y /b |
Wednesday, September 21, 2022
Web Views Open Website URL in Flutter Example & Output
For web view in flutter, we use webview_flutter, a Flutter package that provides a WebView widget on Android and iOS.
To get started, first add webview_flutter as a dependency in your pubspec.yaml file, like this: webview_flutter: ^0.3.19+9 Incase you get this error Cannot run with sound null safety, because the following dependencies do IDE run arguments/configuration To set this up in your IDE of choice, you can use: In IntelliJ/Android Studio: "Edit Configurations" (in your run configurations) → "Additional run args". In Visual Studio Code: search for "Flutter run additional args" in your user settings. In both cases, add --no-sound-null-safety. |
After adding webview_flutter package, you can use WebView() widget. This widget has three basic arguments, thye're key, javascriptMode & initialUrl. See the implementation below: |
Code Snippet: Web View Open Website URL in Flutter |
import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:webview_flutter/webview_flutter.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Web View URL Example', home: Scaffold( appBar: AppBar( title: Text('Web View URL Example'), centerTitle: true, ), body: WebViewExample('https://www.google.com/'), ), ); } } class WebViewExample extends StatefulWidget { final String url; WebViewExample(this.url); @override _WebViewExampleState createState() => _WebViewExampleState(); } class _WebViewExampleState extends State<WebViewExample> { final _key = UniqueKey(); @override Widget build(BuildContext context) { return Container( child: Column( children: <Widget>[ Expanded( child: WebView( key: _key, javascriptMode: JavascriptMode.unrestricted, initialUrl: widget.url, ), ), ], ), ); } } |
Output: Web View Open Website URL in Flutter |
For more details please see WebView for Flutter which has documentation for this package. |
Flutter Multiple Styles in Single Line: Use RichText & TextSpan
In Flutter, if you need to design single line with multiple styles then it can be done by using RichText widget with TextSpan.
RichText widget displays text with different styles. Different text to display is represented using a tree of TextSpan widgts. Each of these TextSpan widgets are associated with different style. In this flutter example, we are going to implement simple application that displays multiple styles on same line. |
Code Snippet: Text with Multiple Styles |
import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'RichText + TextSpan Example', home: Scaffold( appBar: AppBar( title: Text('RichText+ TextSpan Example'), centerTitle: true, ), body: Center( child: RichText( text: TextSpan( text: 'Style 1 ', style: TextStyle( color: Colors.blue, fontWeight: FontWeight.bold, fontSize: 24, ), children: remainingItems() ), ), ), ), ); } List<InlineSpan> remainingItems() { return [ TextSpan( text: 'Style 2 ', style: TextStyle( color: Colors.white, backgroundColor: Colors.teal, fontSize: 20, ), ), TextSpan( text: 'Style 3 ', style: TextStyle( color: Colors.orange, fontFamily: 'courier', fontSize: 24, ), ), TextSpan( text: 'Style 4 ', style: TextStyle( fontStyle: FontStyle.italic, color: Colors.pink, fontSize: 18, ), ), ]; } } |
Output: Multiple Styles for Text |
Based on layout constraints the text might break across multiple lines or might all be displayed on the same line. For more details please see RichText for Flutter which has documentation for this widget. |
Sunday, October 31, 2021
MySQL Drop All Tables At a Glance - For Speed Up Development
There may come a time when you need to drop all of your tables in a MySQL database but don't want to delete database. Consider you have 100+ tables in your database. So it will be big problem for all of us to delete all tables in short time.
If you have foreign keys in your database, then you may encounter errors if you drop a table that is related to another table using foreign keys. The quicker way to do this is to disable the foreign key checks when these statements are run, so you can drop the tables and avoid the error. Add this line above all of your Drop Table statements to disable the foreign key checks: SET FOREIGN_KEY_CHECKS = 0; Then, add this line at the end of your script to enable them: SET FOREIGN_KEY_CHECKS = 1; |
So what we will do is Drop All Tables In One Script to speed up our whole process. |
SET FOREIGN_KEY_CHECKS = 0; SET GROUP_CONCAT_MAX_LEN=32768; SET @tables = NULL; SELECT GROUP_CONCAT('`', table_name, '`') INTO @tables FROM information_schema.tables WHERE table_schema = (SELECT DATABASE()); SELECT IFNULL(@tables,'dummy') INTO @tables; SET @tables = CONCAT('DROP TABLE IF EXISTS ', @tables); PREPARE stmt FROM @tables; EXECUTE stmt; DEALLOCATE PREPARE stmt; SET FOREIGN_KEY_CHECKS = 1; |
Thursday, October 21, 2021
Grails 4: How to add Java JAR files to Grails project | How to add an external library or JAR file that is not a grails plugin to the Grails project
Putting the jar in the lib folder should do the trick.
The default lib folder is gone as of Grails 3.0. grails.github.io/grails-doc/3.0.x/guide/single.html#upgrading --> "Dependency resolution should be used to resolve JAR files" |
If Grails by default don't take the local .jar libraries located in <GRAILS-APP-DIR>/lib (seems that with Grails >= 3.X the /lib folder default configuration is removed) the easy way to enforce it is modifying build.gradle to add a local directory dependency for it. |
For almost all cases is of course better to use the maven repos, but in some cases it's possible to have some other libraries which aren't in a public repo. To do so we have to add these libraries in some lib folder then modify the <GRAILS-APP-DIR>/build.gradle and add something like: |
dependencies { ... // lib folder or any other name one can use compile fileTree(dir: './lib', include: ['*.jar']) ... } |
If you want you can use another directory (not /lib) since you're specifying it. Of course use the correct scope (for example for jars which probably already are in your application container class path the scope will be runtime instead of compile) |
You can download and drop the jar file into the grails-app/lib directory directly. This should be carefully maintained by someone time to time. Other developers working on the same project might not be aware of its presence. Plus you cannot easily upgrade versions in a transparent manner. |
Get Android API level of phone currently running my application
How do I get the Api level of the phone curently running my application |
Check android.os.Build.VERSION, which is a static class that holds various pieces of information about the Android OS a system is running.
If you care about all versions possible (back to original Android version), as in minSdkVersion is set to anything less than 4, then you will have to use android.os.Build.VERSION.SDK, which is a String that can be converted to the integer of the release. If you are on at least API version 4 (Android 1.6 Donut), the current suggested way of getting the API level would be to check the value of android.os.Build.VERSION.SDK_INT, which is an integer. |
In either case, the integer you get maps to an enum value from all those defined in android.os.Build.VERSION_CODES: |
SDK_INT value Build.VERSION_CODES Human Version Name 1 BASE Android 1.0 (no codename) 2 BASE_1_1 Android 1.1 Petit Four 3 CUPCAKE Android 1.5 Cupcake 4 DONUT Android 1.6 Donut 5 ECLAIR Android 2.0 Eclair 6 ECLAIR_0_1 Android 2.0.1 Eclair 7 ECLAIR_MR1 Android 2.1 Eclair 8 FROYO Android 2.2 Froyo 9 GINGERBREAD Android 2.3 Gingerbread 10 GINGERBREAD_MR1 Android 2.3.3 Gingerbread 11 HONEYCOMB Android 3.0 Honeycomb 12 HONEYCOMB_MR1 Android 3.1 Honeycomb 13 HONEYCOMB_MR2 Android 3.2 Honeycomb 14 ICE_CREAM_SANDWICH Android 4.0 Ice Cream Sandwich 15 ICE_CREAM_SANDWICH_MR1 Android 4.0.3 Ice Cream Sandwich 16 JELLY_BEAN Android 4.1 Jellybean 17 JELLY_BEAN_MR1 Android 4.2 Jellybean 18 JELLY_BEAN_MR2 Android 4.3 Jellybean 19 KITKAT Android 4.4 KitKat 20 KITKAT_WATCH Android 4.4 KitKat Watch 21 LOLLIPOP Android 5.0 Lollipop 22 LOLLIPOP_MR1 Android 5.1 Lollipop 23 M Android 6.0 Marshmallow in October 2015 24 N Android 7.0 Nougat in August 2016 25 N_MR1 Android 7.1.1 Nougat in October 2016 26 O Android 8.0 Oreo in August 2017 27 O_MR1 Android 8.1 Oreo MR1 in December 2017 28 P Android 9 Pie in August 2018 29 Q Android 10 in September 2019 30 R Android 11 in September 2020 10000 CUR_DEVELOPMENT Current Development Version |
All informatio collected from https://developer.android.com/reference/android/os/Build.VERSION_CODES |
Subscribe to:
Posts (Atom)