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

siteslave commented Sep 28, 2022

import 'package:dio/dio.dart';
import 'package:pretty_dio_logger/pretty_dio_logger.dart';

class Api {

  String imageEndpoint = 'https://apis.moph.go.th/kyc';

  Dio dio = new Dio(new BaseOptions(
      baseUrl: endPoint,
      receiveDataWhenStatusError: true,
      connectTimeout: 60 * 1000,
      receiveTimeout: 60 * 1000));

  Api() {
    dio.interceptors.add(PrettyDioLogger(
      requestHeader: true,
      requestBody: true,
      responseBody: true,
      responseHeader: false,
      compact: false,
    ));
  }

  Future<Response> login(String username, String password) async {
    String path = '/login';

    return await dio.post(path, data: {
      "username": username,
      "password": password,
    });
  }


  Future<Response> getTruckLoads(String closeStatus, String token) async {
    String path = '/info';

    return await dio.get(path,
        options: Options(
            headers: {HttpHeaders.authorizationHeader: 'Bearer $token'}));
  }
}
Future<String> uploadImage(File file) async {
    String fileName = file.path.split('/').last;
    FormData formData = FormData.fromMap({
        "file":
            await MultipartFile.fromFile(file.path, filename:fileName),
    });
    response = await dio.post("/info", data: formData);
    return response.data['id'];
}

@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