GithubHelp home page GithubHelp logo

izzy0 / flutterfun Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 5.61 MB

Kotlin 0.06% Swift 2.21% Objective-C 10.33% Dart 3.74% CMake 9.42% C++ 11.17% C 0.93% HTML 0.90% Makefile 60.38% Shell 0.53% Java 0.05% Ruby 0.27%

flutterfun's Introduction

Flutter FUN!

Getting Started

A few resources to get you started:

TIPS

Launch Andriod Emulator Without Opening Andriod Studios type flutter emulators find the device you want to open in the list then type flutter emulators --launch <emulator id>

Project Notes

Navigation

View in 1_basics folder

Setting Up Routes

routes: {
    '/firstpage': (context) => FirstPage(),
    '/secondpage': (context) => SecondPage(),
},

Navigating A Page

Navigation with onTap():

Push desired page using Navigator

onPress: () {
    Navigator.pushNamed(context, '/secondpage');
}

Navigating to page and basically "reseting" the view you need to pop the intial context so that the view is reset. Example: using a drawer menu and not popping when clicking a menu item it will keep the drawer open when clicking the back button, when including pop() in the navigatior this will show the drawer closed showing a "reset" view.

onPress: () {
    Navigator.pop(context);
    Navigator.pushNamed(context, '/secondpage');
}

Navigation with a bottomNavigationBar

create a list of pages you need, then follow the index of each item in the bottomBar *make sure to conver stateless widget to stateful

  int _selectedIndex = 0;

  // this method updates the new selected state
  void _navigateBottomBar(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  final List _pages = [
    HomePage(),
    ProfilePage(),
    SettingsPage(),
  ];

Here you will see that the body in indexed in _pages

body: _pages[_selectedIndex], <--- body changes based on index
bottomNavigationBar: BottomNavigationBar(
    currentIndex: _selectedIndex,
    onTap: _navigateBottomBar,
    items: [
        BottomNavigationBarItem(
        icon: Icon(Icons.home),
        label: 'HOME',
        ),
    ...],
    ),

Stateful

High Leve View of what is needed for state

  1. Variable
  2. Method
  3. UI (User Interface)

use setState(); to rebuild the widget, if not used the widget will remain unchanges while the variable will change.

Inputs

To get values from a text feild use a TextEditingController

TextEditingController myController = TextEditingController();

//use example
String userName = myController.text;

//connecting the controller
 ...
 TextField(
    controller: myController,
 )...

Theme Setting

Flutter 3.16.9

Setting the App Theme :

theme: ThemeData(
          colorScheme: ColorScheme.fromSwatch( <-- use colorScheme to set primary colors 
            primarySwatch: Colors.yellow,
          ),
          primaryColor: Colors.yellow,
          appBarTheme: AppBarTheme(
            backgroundColor: Colors.yellow,
          )),

*notice appBarTheme is included, this had to be set because the primary color does not follow the app bar colors using Flutter 3.16 +

calling theme variables within the code

color: Theme.of(context).primaryColor,

Local Database with Hive

first add hive to the pubspec.yaml file dependencies (both defualt and dev)

  hive: ^2.2.3
  hive_flutter: ^1.1.0

then initialize hive in the main.dart file and make the main funtion async

void main() async {
  // init the hive
  await Hive.initFlutter();

  // open a box
  var box = await Hive.openBox('myBox');

  runApp(const MyApp());
}

When using hive use the reference of the database

  // reference hive box
  final _myBox = Hive.box('myBox'); <-- reference myBox in hive
  ToDoDataBase db = ToDoDataBase(); <-- check database.dart creating methods for using the db

flutterfun's People

Contributors

izzy0 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.