Skip to content

Instantly share code, notes, and snippets.

@siteslave
Created September 27, 2022 02:36
Show Gist options
  • Save siteslave/82a8a095208112612ac03076a7e498a5 to your computer and use it in GitHub Desktop.
Save siteslave/82a8a095208112612ac03076a7e498a5 to your computer and use it in GitHub Desktop.

ElevatedButton

ElevatedButton(
  style: ElevatedButton.styleFrom(
      padding: EdgeInsets.all(20),
      shape:
          RoundedRectangleBorder(
              borderRadius:
                  BorderRadius
                      .circular(
                          30))),
  child: Text('Login'),
  onPressed: () {},
)

DatePicker

  DateTime? pickedDate =
  await showDatePicker(
      context: context,
      locale:
          Locale('th', 'TH'),
      initialDate: DateTime
          .now(), //get today's date
      firstDate: DateTime(
          2000), //DateTime.now() - not to allow to choose before today.
      lastDate:
          DateTime(2101));

Localization

pubspec.yaml

  flutter_localizations:
    sdk: flutter
localizationsDelegates: [
  GlobalMaterialLocalizations.delegate,
  GlobalWidgetsLocalizations.delegate,
  DefaultCupertinoLocalizations.delegate,
  GlobalCupertinoLocalizations.delegate,
],
locale: Locale('en', 'US'),
supportedLocales: [
  const Locale('en', 'US'), // English
  const Locale('th', 'TH'), // Thai
],
theme: ThemeData(
    primarySwatch: Colors.indigo,
    fontFamily: "NotoSansThai",
    textTheme: TextTheme(
      bodyText1: TextStyle(fontSize: 16.0),
      bodyText2: TextStyle(fontSize: 16.0),
      button: TextStyle(fontSize: 16),
    )),

Routing

initialRoute: '/',
routes: {
  '/': (context) => const HomePage(),
  AuthenCodePage.routeName: (context) => const AuthenCodePage(),
}

Get params

import 'package:flutter/material.dart';

class AuthenCodePage extends StatefulWidget {
  static const routeName = '/authen';
  const AuthenCodePage({Key? key}) : super(key: key);

  @override
  State<AuthenCodePage> createState() => _AuthenCodePageState();
}

class _AuthenCodePageState extends State<AuthenCodePage> {
  @override
  Widget build(BuildContext context) {
    final args = ModalRoute.of(context)!.settings.arguments as ScreenArguments;

    return Scaffold(
      appBar: AppBar(
        title: Text('Authen'),
      ),
      body: Center(
        child: Text(args.message),
      ),
    );
  }
}

class ScreenArguments {
  final String title;
  final String message;

  ScreenArguments(this.title, this.message);
}

@siteslave
Copy link
Author

 <uses-permission android:name="android.permission.CAMERA"/>
getPermissionStatus() async {
  await Permission.camera.request();
  var status = await Permission.camera.status;
  if (status.isGranted) {
    log('Camera Permission: GRANTED');
    setState(() {
      _isCameraPermissionGranted = true;
    });
    // Set and initialize the new camera
  } else {
    log('Camera Permission: DENIED');
  }
}
final ImagePicker _picker = ImagePicker();

final XFile? pickedFile = await _picker.pickImage(
            source: source,
            maxWidth: maxWidth,
            maxHeight: maxHeight,
            imageQuality: quality,
          );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment