Skip to content

Instantly share code, notes, and snippets.

@mtayyab010
mtayyab010 / PageRouting.dart
Created April 19, 2020 04:33
Page Routing
//Push to next page
Navigator.push(context, CupertinoPageRoute(builder: (context) => ClientPhoneNumber()));
//Back to next page
Navigator.pop(context);
@mtayyab010
mtayyab010 / DecoratedBox.dart
Last active April 17, 2020 20:10
DecoratedBox
DecoratedBox(
//Add Color
color: Theme.of(context).primaryColor,
//Add Image
decoration: BoxDecoration(
image: DecorationImage(image: AssetImage('images/backgroundImage.png'), fit: BoxFit.cover),
)
//Add Specific Border
borderRadius: BorderRadius.only(
GridView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: 6,
gridDelegate:
new SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3),
itemBuilder: (BuildContext context, int index) {
return ServicesItem();
});
@mtayyab010
mtayyab010 / AppStateDemo.dart
Last active April 18, 2020 05:51
[Application States] If you are an Android or iOS Developer, you may be familier with these concepts and callbacks. Andrid has onResume, onPause etc callbacks, iOS has viewWillDisappear,viewDidAppear, didFinishLaunchingWithOptions etc callback functions to acheive this. These funtions are useful most of the times when we want to save something w…
import 'package:flutter/material.dart';
class AppStateDemo extends StatefulWidget {
AppStateDemo() : super();
final String title = "AppState Demo";
@override
AppStateDemoState createState() => AppStateDemoState();
}
//Simple AppBar
Widget appBar = AppBar(
title: Text("Title",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontFamily: "Roboto",
fontSize: 25.0),),
//Add Multiple Right Buttons
actions: <Widget>[
//Basic ListView
ListView(
children: <Widget>[
Text('User Name', style: TextStyle(fontSize: 16),),
Text('Gender', style: TextStyle(fontSize: 16),),
Text('Mobile Number', style: TextStyle(fontSize: 16),),
],
)
//ListView With Data Mapping
class DropDownButtonExample extends StatefulWidget {
@override
_DropDownButtonExampleState createState() => _DropDownButtonExampleState();
}
class _DropDownButtonExampleState extends State<DropDownButtonExample> {
var gender = ['Male', 'Female', 'Other'];
var selectedValue = 'Male';
@override
Widget build(BuildContext context) {
@mtayyab010
mtayyab010 / CustomListTile.dart
Last active November 3, 2023 14:28
[Custom Flutter Widgets] My own ListTile remove extra space between leading and title
class CustomListTile extends StatelessWidget {
final Widget leading;
final String title;
final String subTitle;
final Widget trailing;
final VoidCallback onTap;
CustomListTile({this.leading, this.title, this.subTitle, this.trailing, this.onTap});
@override
Widget build(BuildContext context) {
return InkWell(
let <#variable#> = UITapGestureRecognizer(target: self, action: #selector(self.tapGuesture(_:)))
<#variable#> .numberOfTapsRequired = 1;
self.<#objectOutlet#> .addGestureRecognizer(<#variable#> )
self.<#objectOutlet#>.tag = 0
self.<#objectOutlet#>.isUserInteractionEnabled = true
func hideNavigationBar() {
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
// Sets shadow (line below the bar) to a blank image
UINavigationBar.appearance().shadowImage = UIImage()
// Sets the translucent background color
UINavigationBar.appearance().backgroundColor = .clear
// Set translucent. (Default value is already true, so this can be removed if desired.)
UINavigationBar.appearance().isTranslucent = true
}