Home Blog Page 35

How to Host a WordPress Website on AWS In Just 5 Min

0
Host a Wordpress Website on AWS In Just 5 Min

Hi Guys, This tutorial is on how to host a website on aws wordpress instance hosting by using Bitnami and automattic instance version of wordpress on AWS.

If you don’t have aws account, create a free AWS account now, follow the video tutorial if you get stuck.

Video Tutorial


1. Create WordPress AWS EC2 Instance

Once you create a free AWS account, login into the account. Now In you amazon dashboard you will be Services Option at the top left of the page then in Compute -> click on EC2.

Then in EC2 dashboard, you can see a button “Launch Instance”, Here the word “Instance” means “virtual machine”.

Now, In EC2 instance search for “wordpress”, it will search lot’s of AWS marketplace AMI’s, select “WordPress Certified by bitnami and Automattic”.

2. Create key pair for ssh connection

Before launching instance(virtual compute engine) you need ppk or pem key pair for ssh connection to your aws server, Click on Create new key pair and create it. Next click on Launch Instance button.

Verify your server config and finally click on Launch Instance.

AWS wordpress instance is getting created, it will take 2-5 min to get created.

We have successfully created WordPress instance on aws.

But, In your order to customize your first wordpress website on aws you need login credentials right. Now let’s check how to get login credentials of aws wordpress hosting.

3. How to get login credential of aws wordpress hosting

In Service tap, goto Compute > click on EC2 then in Instance you will find your newly created wordpress instance.

Next, Click on Instance ID.

where is aws system log

Now, On the selected Instance ID page, Click on Action button -> In Drop Down Select Monitor And troubleshoot then Click on Get System log.

aws bitnami wordpress login credential

In get system log, use sidebar scroll, and look for Setting Bitnami application password.

4. Login to AWS WordPress wp-admin

After you know your wordpress login credentials, Open a browser and browse wordpress login page (wp-admin)

<instance public IP>/wp-admin

Get your Instance public IP here: Service -> EC2 -> Instance -> Instance ID ->

Login to WordPress

http://3.144.75.98/wp-admin

Next, In new browser tab, paste the public IP address of your instance followed by wp-admin (as show above), This will load wordpress login page, Enter user as username and paste the password tht you just copyed from system log(refer above).

That’s it


Congratulations! You’ve successfully hosted your first wordpress website on AWS server.

Dart map – get sum of all values in Map

0
Dart map - get sum of all values in Map

Hi Guys, Welcome to Proto Coders Point, In this short article let’s learn how to add all integer values of map and get the sum of them.

The below Snippet of calculating sum of all the values works only if the values in map are number(So will assume all the values in map are numbers).

Learn more about dart map <– Here .

Example 1: Get Sum of all values from Map using Dart Reduce() in-built function

void main() {
  
  const Map<String,int> dataMap = {
    'prodPrice1': 5,
    'prodPrice2': 1,
    'prodPrice3': 6,
    'prodPrice4': 10,
    'prodPrice5': 15,
    'prodPrice6': 4,
  };
  
  Iterable<int> priceValue = dataMap.values;
  
  final sumOfAllPrice = priceValue.reduce((sum,currentValue)=>sum+currentValue);
  
  print(sumOfAllPrice);
}

Output:

41


Example 2: Get Sum of all values from Map using Dart For Loop

void main() {
  
  const Map<String,double> dataMap = {
    'prodPrice1': 55.6,
    'prodPrice2': 2.1,
    'prodPrice3': 6.8,
    'prodPrice4': 10.8,
    'prodPrice5': 19.2,
    'prodPrice6': 44.5,
  };
  double sumOfAllPrice = 0;
  
  // create a list which contain only price value
  List<double> allPriceValueList = dataMap.values.toList();
  
  
  // loop through the list and calculate sum of them
  for(double value in allPriceValueList){
    sumOfAllPrice += value;
  }
  
  print(sumOfAllPrice);
}

Output:

139

PuTTY fatal error: “No supported authentication methods available”

0
PuTTY fatal erro No supported authentication methods available

Solution: To fix “PuTTY fatal error: “No supported authentication methods available”:

You need to Edit sshd_config file and set PasswordAuthentication to yes.

How to fix “Putty – no supported authentication”

Step 1: Open sshd_config

sudo vi /etc/ssh/sshd_config

Step 2: set PasswordAuthentication to yes

Step 3: Then restart server

sudo service ssh restart
sudo service sshd restart

How to add const keyword everywhere in flutter code

0
audo add const keyword in flutter code

Hi Guys: Welcome to Proto Coders Point, welcome. If you recently updated your flutter SDK to version 2.5.0 or higher, you might have noticed that every widget that uses static data now displays a warning to include the “const” modifier at the beginning of the widget.

This is due to the fact that the flutter lints rules are now automatically applied.

Video tutorial to automatically add const keyword everywhere in code

Using the const keyword on any data type or widget that uses static data is a recommended practise.


How to auto add const keyword in flutter code

However, you may update your analysis_options.yaml file and include the following if you’d like to auto add const in your code:

In you flutter project structure:

Step 1: open analysis_option.yaml file & under linter > rules disable prefer_const_constructor:

Step 2: Add prefer const constructors and make it false

linter:
  rules:
    prefer_const_constructors : false   //add this line

Step 3: Run dart fix apply in IDE terminal

After setting prefer_const_constructors to false, you must enter the following command into the IDE terminal.

dart fix --apply

This will auto add const keyword in your flutter code by analyzing your complete code

auto add const keywords in flutter code

The right way to add background image in flutter

0
how to set background image in flutter

Hi Guy’s Welcome to Proto Coder Point. In this flutter article let’s learn how to set background image in flutter.

Preventing moving background image in flutter

If you have a TextField that open a keyboard then the background image will auto resize and move a bit above keyboard which don’t look good, so to solve it we can wrap Scaffold widget with container & in then container widget by using decoration we can add background image (Refer: As done in below snippet code), & then In scaffold widget make sure to set background color to transparent(so that background image is visible).

Note: I have used NetworkImage, but in real time app, it better to make use of AssetImage if your background in flutter app is static.

Container(
      decoration: BoxDecoration(
        image: DecorationImage(
          image: NetworkImage(
            'https://images.pixexid.com/green-silhouette-mobile-wallpaper-hd-scpc9x4o.jpeg'
          ),
          fit: BoxFit.cover
        )
      ),
      child: Scaffold(
        backgroundColor: Colors.transparent,
          appBar: AppBar(
             title: Text('Add Background image flutter'),
          ),
        body: Container(
          alignment: Alignment.center,
          padding: EdgeInsets.all(30),
          child: Column(
            children: const [
              TextField(
                decoration: InputDecoration(
                  hintText: 'Enter Email',
                  filled: true,
                  fillColor: Colors.white
                ),
              ),
              SizedBox(height: 20,),
              TextField(
                decoration: InputDecoration(
                    hintText: 'Enter Password',
                    filled: true,
                    fillColor: Colors.white
                ),
              ),
              SizedBox(height: 20,),
              ElevatedButton(
                onPressed: null,
                child: Text("Submit"),
              )
            ],
          ),
        ),
      ),
    );

Complete Source Code

The Below Code (Complete Source Code) will set a background image in flutter & darken the background image and apply gradient effect on top of flutter background image.

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        image: DecorationImage(
          image: NetworkImage(
            'https://images.pixexid.com/green-silhouette-mobile-wallpaper-hd-scpc9x4o.jpeg'
          ),
          fit: BoxFit.cover
        )
      ),
      child: Container(
        decoration: BoxDecoration(
          gradient: LinearGradient(
            begin: Alignment.center,
            end: Alignment.bottomCenter,
            colors: [
              Colors.black12,
              Colors.red.shade100
            ]
          )
        ),
        child: Scaffold(
          backgroundColor: Colors.transparent,
            appBar: AppBar(
               title: Text('Add Background image flutter'),
            ),
          body: Container(
            alignment: Alignment.center,
            padding: EdgeInsets.all(30),
            child: Column(
              children: const [
                TextField(
                  decoration: InputDecoration(
                    hintText: 'Enter Email',
                    filled: true,
                    fillColor: Colors.white
                  ),
                ),
                SizedBox(height: 20,),
                TextField(
                  decoration: InputDecoration(
                      hintText: 'Enter Password',
                      filled: true,
                      fillColor: Colors.white
                  ),
                ),
                SizedBox(height: 20,),
                ElevatedButton(
                  onPressed: null,
                  child: Text("Submit"),
                )
              ],
            ),
          ),
        ),
      ),
    );
  }
}
flutter add background image

When to use FittedBox Widget in flutter

0
flutter fittedbox widget

Hi Guys, Welcome to Proto Coders Point. In this flutter article let’s learn how to fit a widget inside another widget & acquire the available space of it parent widget.

Video Tutorial

To do so we can make use of fittedbox widget of flutter.

Here is what happens when you simply wrap a widget inside another widget in flutter.

Container(
          width: 200,
          height: 200,
          color: Colors.blue,
          child: Center(
               child: Text("Subscribe To Proto Coders Point",style: TextStyle(fontSize: 60),)
            ),
   ),
flutter fitted widget example

As you can see in above image, The Text Widget with fontSize: 75 that is wrapped inside a Container is getting cropped and is not responsive & not fitting inside container. To fix this we can make use of FittedBox widget.


Flutter FittedBox Widget Example

Simply wrap the child widget of Container with FittedBox, What FittedBox will do is it will automatically Scales and positions its child within the available space of it parent.

Code Example

Container(
          width: 300,
          height: 200,
          color: Colors.blue,
          child: FittedBox(
              child: Center( 
                        child:  Text("Subscribe To Proto Coders Point",style: TextStyle(fontSize: 60),)
              )
          ),
),
flutter fitted widget example

In Above code FittedBox will simply ignore the size given to it’s child, In our case we have Text with fontSize as 60.

Drawback of this is: Suppose In Above Example I give smaller fontsize to Text, Even though it will acquire the complete available fit.

To fix this use fit Property of FittedBox widget Example below:

Container(
          width: 300,
          height: 200,
          color: Colors.blue,
          child: FittedBox(
            fit: BoxFit.scaleDown,
              child: Center(
                        child:  Text("Subscribe To Proto Coders Point",style: TextStyle(fontSize: 10),)
              )
          ),
        )
flutter fitted widget example