Skip to main content

Flutter Development (Day-09):

  • In this post we are going to talk about some interesting topics in Flutter like 
  • How to use Custom fonts  and Custom Icons in Flutter .
  • How to use Themes and change the Theme across different screens and finally
  • How to change the view of  the Screen based on Orientation like (portrait,LandScape).
  • All source code : Click Here.

lib/main.dart:

import 'package:allaboutflutterblog/tuts/customFonts.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      home: CustomFonts(),
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        fontFamily: "Montserrat",
        brightness: Brightness.dark,
      ),
    ),
  );
}

import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:random_color/random_color.dart';

class CustomFonts extends StatefulWidget {
  @override
  _CustomFontsState createState() => _CustomFontsState();
}

class _CustomFontsState extends State<CustomFonts> {
  final List _items = List.generate(100, (i) => i + 1);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        // FontAwesomeIcon
        leading: Icon(FontAwesomeIcons.alignLeft),
        title: Text(
          "Custom Fonts and Themes",
          style: TextStyle(fontSize: 15.0),
        ),
        centerTitle: true,
        backgroundColor: Colors.deepPurple,
        actions: <Widget>[
          // FontAwesomeIcon
          Icon(FontAwesomeIcons.search),
        ],
      ),
      body: OrientationBuilder(
        builder: (BuildContext context, orientation) {
          return GridView.builder(
            itemCount: _items.length,
            itemBuilder: (BuildContext context, orientation) {
              return Container(
                alignment: Alignment.center,
                color: RandomColor().randomColor(),
                child: Text(
                  "Grid ${orientation + 1}",
                  style: TextStyle(color: Colors.white, fontSize: 22.0),
                ),
              );
            },
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: orientation == Orientation.portrait ? 2 : 4,
            ),
          );
        },
      ),
    );
  }
}

pubspec.yaml:

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^0.1.2
  http: ^0.12.0+2
  random_color: ^1.0.3
  font_awesome_flutter: ^8.4.0

dev_dependencies:
  flutter_test:
    sdk: flutter

  fonts:
    - family: Montserrat
      fonts:
        - asset: fonts/montserrat/Montserrat-Regular.ttf       
          style: italic

Explanation:

  • Add font_awesome_flutter 8.4.0 in your pubspec.yaml file Also add custom font.
  • Wrap the widget with OrientationBuilder in order to change the view of the screen when the orientation is changed.
  • Wrap the root widget with Theme or we can use Themes in the MaterialApp widget.
  • If you are following this tutorial / blog please leave your opinion πŸ‘€ / say Hii βœ‹/ Your e-mail in the comment section that I can improve myself and it will gives boost for me to do more tutorials.
  • If you have any doubts feel free to ask me in the comment section or email me ramubugudi4@gmail.com I can definetly give reply.

Follow me on:
 Twitter  Github   LinkedIn

Comments

Popular posts from this blog

Flutter Development (Day-00): This is the First Post from this Blog.This blog will tell you about Flutter.If you don't know about it then the upcoming posts will explain you everything.This is 30 day tutorial which explains about Flutter for absolute beginners. prerequsites:  If you are enthusiastic and Curious. All source code :  Click Here . If you are following this tutorial / blog please leave your opinion πŸ‘€ / say Hii βœ‹/ Your e-mail in the comment section that I can improve myself and it will gives boost for me to do more tutorials. If you have any doubts feel free to ask me in the comment section or email me ramubugudi4@gmail.com I can definetly give reply. Follow me on:   Twitter   Github     LinkedIn
Flutter Development (Day-11): In the last post we have discussed about how to implement brand new Todo application. All source code :  Click Here . Building its User Interface. How to display the data. How to remove the items from the List by tapping the Delete Icon or by Swiping it. Showing which item is deleted in the form of SnackBar. And finally modify some UI stuff. If you want to copy the exact same code  click here . List _todos = []; First of all create a empty list which will be holding all of our Todo's. When we tap on the ADD button we have to perfom some operation see below.   _validateForm() {if (_key.currentState.validate()) {setState(() {_todos.add(_controller.text);});_controller.clear();Navigator.of(context).pop();}} Here we have used setState () in order to refresh every single time of changing the data in the TextField and then we add the text to _todos list. Then we clear the data in the TextField and go back to ho...
Flutter Development (Day - 05) In this post we are going to talk about Tabs and Forms. Here is the Sample code with Explanation in the form of comments (//).     All source code :  Click Here .       lib/main.dart: import 'package:allaboutflutterblog/tuts/tabs_forms.dart'; import 'package:flutter/material.dart'; void main() {   runApp(     MaterialApp(       home: TabsForms(),       debugShowCheckedModeBanner: false,              theme: ThemeData(         primaryColor: Colors.red,         primarySwatch: Colors.blue,       ),     ),   ); } import 'package:flutter/material.dart'; class TabsForms extends StatefulWidget {   @override   _TabsFormsState createState() => _TabsFormsState(); } class _TabsFormsState extends State...