repo_id
stringlengths 21
168
| file_path
stringlengths 36
210
| content
stringlengths 1
9.98M
| __index_level_0__
int64 0
0
|
---|---|---|---|
mirrored_repositories/trave_tou_app/lib/application/auth | mirrored_repositories/trave_tou_app/lib/application/auth/bloc/auth_bloc.dart | // ignore_for_file: await_only_futures
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tourist_app/config/constants.dart';
import 'package:tourist_app/core/auth/google_auth/auth.dart';
part 'auth_event.dart';
part 'auth_state.dart';
part 'auth_bloc.freezed.dart';
@injectable
class AuthBloc extends Bloc<AuthEvent, AuthState> {
final Auth _googleSigning;
AuthBloc(this._googleSigning) : super(AuthState.initial()) {
int tapCount = 0;
on<_G_Login>((event, emit) async {
//This Tap count is a lock..
//Even the app is transferred to another people this will only work
//after five taps on the icon.
//An only we knows that
if (tapCount >= 5) {
emit(state.copyWith(isLogging: true));
Either<User?, String> singIn = await _googleSigning.signInWithGoogle();
singIn.fold((l) {
_googleSigning.postLoggedInData(userData: l);
emit(state.copyWith(
isLogging: false,
isLoggedIn: true,
email: l!.email,
profileImage: l.photoURL,
name: l.displayName));
}, (r) {
Fluttertoast.showToast(msg: r);
emit(state.copyWith(
isLogging: false, isLoggedIn: false, isError: true));
});
} else {
tapCount++;
}
});
on<_APP_SESSION>((event, emit) async {
SharedPreferences preferences = await SharedPreferences.getInstance();
bool? session = await preferences.getBool(SESSION_KEY);
var name = await preferences.getString(PROFILE_NAME_KEY);
var profileImage = await preferences.getString(PROFILE_IMAGE_KEY);
var email = await preferences.getString(PROFILE_EMAIL_KEY);
if (session == null) {
emit(state.copyWith(isLoggedIn: false));
} else {
if (session) {
emit(state.copyWith(
isLoggedIn: true,
email: email,
profileImage: profileImage,
name: name));
} else {
emit(state.copyWith(isLoggedIn: false));
}
}
});
on<_APP_Logout>((event, emit) async {
SharedPreferences preferences = await SharedPreferences.getInstance();
preferences.clear();
emit(state.copyWith(logout: true));
});
}
}
| 0 |
mirrored_repositories/trave_tou_app/lib/application/auth | mirrored_repositories/trave_tou_app/lib/application/auth/bloc/auth_event.dart | part of 'auth_bloc.dart';
@freezed
class AuthEvent with _$AuthEvent {
const factory AuthEvent.googleLogin() = _G_Login;
const factory AuthEvent.getSession() = _APP_SESSION;
const factory AuthEvent.logout() = _APP_Logout;
}
| 0 |
mirrored_repositories/trave_tou_app/lib/application/auth | mirrored_repositories/trave_tou_app/lib/application/auth/bloc/auth_bloc.freezed.dart | // coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target
part of 'auth_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods');
/// @nodoc
mixin _$AuthEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() googleLogin,
required TResult Function() getSession,
required TResult Function() logout,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult Function()? googleLogin,
TResult Function()? getSession,
TResult Function()? logout,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? googleLogin,
TResult Function()? getSession,
TResult Function()? logout,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_G_Login value) googleLogin,
required TResult Function(_APP_SESSION value) getSession,
required TResult Function(_APP_Logout value) logout,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult Function(_G_Login value)? googleLogin,
TResult Function(_APP_SESSION value)? getSession,
TResult Function(_APP_Logout value)? logout,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_G_Login value)? googleLogin,
TResult Function(_APP_SESSION value)? getSession,
TResult Function(_APP_Logout value)? logout,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $AuthEventCopyWith<$Res> {
factory $AuthEventCopyWith(AuthEvent value, $Res Function(AuthEvent) then) =
_$AuthEventCopyWithImpl<$Res>;
}
/// @nodoc
class _$AuthEventCopyWithImpl<$Res> implements $AuthEventCopyWith<$Res> {
_$AuthEventCopyWithImpl(this._value, this._then);
final AuthEvent _value;
// ignore: unused_field
final $Res Function(AuthEvent) _then;
}
/// @nodoc
abstract class _$$_G_LoginCopyWith<$Res> {
factory _$$_G_LoginCopyWith(
_$_G_Login value, $Res Function(_$_G_Login) then) =
__$$_G_LoginCopyWithImpl<$Res>;
}
/// @nodoc
class __$$_G_LoginCopyWithImpl<$Res> extends _$AuthEventCopyWithImpl<$Res>
implements _$$_G_LoginCopyWith<$Res> {
__$$_G_LoginCopyWithImpl(_$_G_Login _value, $Res Function(_$_G_Login) _then)
: super(_value, (v) => _then(v as _$_G_Login));
@override
_$_G_Login get _value => super._value as _$_G_Login;
}
/// @nodoc
class _$_G_Login implements _G_Login {
const _$_G_Login();
@override
String toString() {
return 'AuthEvent.googleLogin()';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$_G_Login);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() googleLogin,
required TResult Function() getSession,
required TResult Function() logout,
}) {
return googleLogin();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult Function()? googleLogin,
TResult Function()? getSession,
TResult Function()? logout,
}) {
return googleLogin?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? googleLogin,
TResult Function()? getSession,
TResult Function()? logout,
required TResult orElse(),
}) {
if (googleLogin != null) {
return googleLogin();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_G_Login value) googleLogin,
required TResult Function(_APP_SESSION value) getSession,
required TResult Function(_APP_Logout value) logout,
}) {
return googleLogin(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult Function(_G_Login value)? googleLogin,
TResult Function(_APP_SESSION value)? getSession,
TResult Function(_APP_Logout value)? logout,
}) {
return googleLogin?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_G_Login value)? googleLogin,
TResult Function(_APP_SESSION value)? getSession,
TResult Function(_APP_Logout value)? logout,
required TResult orElse(),
}) {
if (googleLogin != null) {
return googleLogin(this);
}
return orElse();
}
}
abstract class _G_Login implements AuthEvent {
const factory _G_Login() = _$_G_Login;
}
/// @nodoc
abstract class _$$_APP_SESSIONCopyWith<$Res> {
factory _$$_APP_SESSIONCopyWith(
_$_APP_SESSION value, $Res Function(_$_APP_SESSION) then) =
__$$_APP_SESSIONCopyWithImpl<$Res>;
}
/// @nodoc
class __$$_APP_SESSIONCopyWithImpl<$Res> extends _$AuthEventCopyWithImpl<$Res>
implements _$$_APP_SESSIONCopyWith<$Res> {
__$$_APP_SESSIONCopyWithImpl(
_$_APP_SESSION _value, $Res Function(_$_APP_SESSION) _then)
: super(_value, (v) => _then(v as _$_APP_SESSION));
@override
_$_APP_SESSION get _value => super._value as _$_APP_SESSION;
}
/// @nodoc
class _$_APP_SESSION implements _APP_SESSION {
const _$_APP_SESSION();
@override
String toString() {
return 'AuthEvent.getSession()';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$_APP_SESSION);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() googleLogin,
required TResult Function() getSession,
required TResult Function() logout,
}) {
return getSession();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult Function()? googleLogin,
TResult Function()? getSession,
TResult Function()? logout,
}) {
return getSession?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? googleLogin,
TResult Function()? getSession,
TResult Function()? logout,
required TResult orElse(),
}) {
if (getSession != null) {
return getSession();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_G_Login value) googleLogin,
required TResult Function(_APP_SESSION value) getSession,
required TResult Function(_APP_Logout value) logout,
}) {
return getSession(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult Function(_G_Login value)? googleLogin,
TResult Function(_APP_SESSION value)? getSession,
TResult Function(_APP_Logout value)? logout,
}) {
return getSession?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_G_Login value)? googleLogin,
TResult Function(_APP_SESSION value)? getSession,
TResult Function(_APP_Logout value)? logout,
required TResult orElse(),
}) {
if (getSession != null) {
return getSession(this);
}
return orElse();
}
}
abstract class _APP_SESSION implements AuthEvent {
const factory _APP_SESSION() = _$_APP_SESSION;
}
/// @nodoc
abstract class _$$_APP_LogoutCopyWith<$Res> {
factory _$$_APP_LogoutCopyWith(
_$_APP_Logout value, $Res Function(_$_APP_Logout) then) =
__$$_APP_LogoutCopyWithImpl<$Res>;
}
/// @nodoc
class __$$_APP_LogoutCopyWithImpl<$Res> extends _$AuthEventCopyWithImpl<$Res>
implements _$$_APP_LogoutCopyWith<$Res> {
__$$_APP_LogoutCopyWithImpl(
_$_APP_Logout _value, $Res Function(_$_APP_Logout) _then)
: super(_value, (v) => _then(v as _$_APP_Logout));
@override
_$_APP_Logout get _value => super._value as _$_APP_Logout;
}
/// @nodoc
class _$_APP_Logout implements _APP_Logout {
const _$_APP_Logout();
@override
String toString() {
return 'AuthEvent.logout()';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$_APP_Logout);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() googleLogin,
required TResult Function() getSession,
required TResult Function() logout,
}) {
return logout();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult Function()? googleLogin,
TResult Function()? getSession,
TResult Function()? logout,
}) {
return logout?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? googleLogin,
TResult Function()? getSession,
TResult Function()? logout,
required TResult orElse(),
}) {
if (logout != null) {
return logout();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_G_Login value) googleLogin,
required TResult Function(_APP_SESSION value) getSession,
required TResult Function(_APP_Logout value) logout,
}) {
return logout(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult Function(_G_Login value)? googleLogin,
TResult Function(_APP_SESSION value)? getSession,
TResult Function(_APP_Logout value)? logout,
}) {
return logout?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_G_Login value)? googleLogin,
TResult Function(_APP_SESSION value)? getSession,
TResult Function(_APP_Logout value)? logout,
required TResult orElse(),
}) {
if (logout != null) {
return logout(this);
}
return orElse();
}
}
abstract class _APP_Logout implements AuthEvent {
const factory _APP_Logout() = _$_APP_Logout;
}
/// @nodoc
mixin _$AuthState {
bool get isLogging => throw _privateConstructorUsedError;
bool? get isError => throw _privateConstructorUsedError;
bool get isLoggedIn => throw _privateConstructorUsedError;
String? get name => throw _privateConstructorUsedError;
String? get email => throw _privateConstructorUsedError;
String? get profileImage => throw _privateConstructorUsedError;
bool? get logout => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$AuthStateCopyWith<AuthState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $AuthStateCopyWith<$Res> {
factory $AuthStateCopyWith(AuthState value, $Res Function(AuthState) then) =
_$AuthStateCopyWithImpl<$Res>;
$Res call(
{bool isLogging,
bool? isError,
bool isLoggedIn,
String? name,
String? email,
String? profileImage,
bool? logout});
}
/// @nodoc
class _$AuthStateCopyWithImpl<$Res> implements $AuthStateCopyWith<$Res> {
_$AuthStateCopyWithImpl(this._value, this._then);
final AuthState _value;
// ignore: unused_field
final $Res Function(AuthState) _then;
@override
$Res call({
Object? isLogging = freezed,
Object? isError = freezed,
Object? isLoggedIn = freezed,
Object? name = freezed,
Object? email = freezed,
Object? profileImage = freezed,
Object? logout = freezed,
}) {
return _then(_value.copyWith(
isLogging: isLogging == freezed
? _value.isLogging
: isLogging // ignore: cast_nullable_to_non_nullable
as bool,
isError: isError == freezed
? _value.isError
: isError // ignore: cast_nullable_to_non_nullable
as bool?,
isLoggedIn: isLoggedIn == freezed
? _value.isLoggedIn
: isLoggedIn // ignore: cast_nullable_to_non_nullable
as bool,
name: name == freezed
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String?,
email: email == freezed
? _value.email
: email // ignore: cast_nullable_to_non_nullable
as String?,
profileImage: profileImage == freezed
? _value.profileImage
: profileImage // ignore: cast_nullable_to_non_nullable
as String?,
logout: logout == freezed
? _value.logout
: logout // ignore: cast_nullable_to_non_nullable
as bool?,
));
}
}
/// @nodoc
abstract class _$$_AuthStateCopyWith<$Res> implements $AuthStateCopyWith<$Res> {
factory _$$_AuthStateCopyWith(
_$_AuthState value, $Res Function(_$_AuthState) then) =
__$$_AuthStateCopyWithImpl<$Res>;
@override
$Res call(
{bool isLogging,
bool? isError,
bool isLoggedIn,
String? name,
String? email,
String? profileImage,
bool? logout});
}
/// @nodoc
class __$$_AuthStateCopyWithImpl<$Res> extends _$AuthStateCopyWithImpl<$Res>
implements _$$_AuthStateCopyWith<$Res> {
__$$_AuthStateCopyWithImpl(
_$_AuthState _value, $Res Function(_$_AuthState) _then)
: super(_value, (v) => _then(v as _$_AuthState));
@override
_$_AuthState get _value => super._value as _$_AuthState;
@override
$Res call({
Object? isLogging = freezed,
Object? isError = freezed,
Object? isLoggedIn = freezed,
Object? name = freezed,
Object? email = freezed,
Object? profileImage = freezed,
Object? logout = freezed,
}) {
return _then(_$_AuthState(
isLogging: isLogging == freezed
? _value.isLogging
: isLogging // ignore: cast_nullable_to_non_nullable
as bool,
isError: isError == freezed
? _value.isError
: isError // ignore: cast_nullable_to_non_nullable
as bool?,
isLoggedIn: isLoggedIn == freezed
? _value.isLoggedIn
: isLoggedIn // ignore: cast_nullable_to_non_nullable
as bool,
name: name == freezed
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String?,
email: email == freezed
? _value.email
: email // ignore: cast_nullable_to_non_nullable
as String?,
profileImage: profileImage == freezed
? _value.profileImage
: profileImage // ignore: cast_nullable_to_non_nullable
as String?,
logout: logout == freezed
? _value.logout
: logout // ignore: cast_nullable_to_non_nullable
as bool?,
));
}
}
/// @nodoc
class _$_AuthState implements _AuthState {
const _$_AuthState(
{required this.isLogging,
this.isError,
required this.isLoggedIn,
this.name,
this.email,
this.profileImage,
required this.logout});
@override
final bool isLogging;
@override
final bool? isError;
@override
final bool isLoggedIn;
@override
final String? name;
@override
final String? email;
@override
final String? profileImage;
@override
final bool? logout;
@override
String toString() {
return 'AuthState(isLogging: $isLogging, isError: $isError, isLoggedIn: $isLoggedIn, name: $name, email: $email, profileImage: $profileImage, logout: $logout)';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$_AuthState &&
const DeepCollectionEquality().equals(other.isLogging, isLogging) &&
const DeepCollectionEquality().equals(other.isError, isError) &&
const DeepCollectionEquality()
.equals(other.isLoggedIn, isLoggedIn) &&
const DeepCollectionEquality().equals(other.name, name) &&
const DeepCollectionEquality().equals(other.email, email) &&
const DeepCollectionEquality()
.equals(other.profileImage, profileImage) &&
const DeepCollectionEquality().equals(other.logout, logout));
}
@override
int get hashCode => Object.hash(
runtimeType,
const DeepCollectionEquality().hash(isLogging),
const DeepCollectionEquality().hash(isError),
const DeepCollectionEquality().hash(isLoggedIn),
const DeepCollectionEquality().hash(name),
const DeepCollectionEquality().hash(email),
const DeepCollectionEquality().hash(profileImage),
const DeepCollectionEquality().hash(logout));
@JsonKey(ignore: true)
@override
_$$_AuthStateCopyWith<_$_AuthState> get copyWith =>
__$$_AuthStateCopyWithImpl<_$_AuthState>(this, _$identity);
}
abstract class _AuthState implements AuthState {
const factory _AuthState(
{required final bool isLogging,
final bool? isError,
required final bool isLoggedIn,
final String? name,
final String? email,
final String? profileImage,
required final bool? logout}) = _$_AuthState;
@override
bool get isLogging;
@override
bool? get isError;
@override
bool get isLoggedIn;
@override
String? get name;
@override
String? get email;
@override
String? get profileImage;
@override
bool? get logout;
@override
@JsonKey(ignore: true)
_$$_AuthStateCopyWith<_$_AuthState> get copyWith =>
throw _privateConstructorUsedError;
}
| 0 |
mirrored_repositories/trave_tou_app/lib/application/auth | mirrored_repositories/trave_tou_app/lib/application/auth/bloc/auth_state.dart | part of 'auth_bloc.dart';
@freezed
class AuthState with _$AuthState {
const factory AuthState(
{required bool isLogging,
bool? isError,
required bool isLoggedIn,
String? name,
String? email,
String? profileImage,
required bool? logout}) = _AuthState;
factory AuthState.initial() {
return const AuthState(isLogging: false, isLoggedIn: false, logout: false);
}
}
| 0 |
mirrored_repositories/trave_tou_app/lib/application/home | mirrored_repositories/trave_tou_app/lib/application/home/bloc/home_bloc.dart | import 'package:bloc/bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'home_event.dart';
part 'home_state.dart';
part 'home_bloc.freezed.dart';
class HomeBloc extends Bloc<HomeEvent, HomeState> {
HomeBloc() : super(_Initial()) {
on<HomeEvent>((event, emit) {
// TODO: implement event handler
});
}
}
| 0 |
mirrored_repositories/trave_tou_app/lib/application/home | mirrored_repositories/trave_tou_app/lib/application/home/bloc/home_state.dart | part of 'home_bloc.dart';
@freezed
class HomeState with _$HomeState {
const factory HomeState.initial() = _Initial;
}
| 0 |
mirrored_repositories/trave_tou_app/lib/application/home | mirrored_repositories/trave_tou_app/lib/application/home/bloc/home_event.dart | part of 'home_bloc.dart';
@freezed
class HomeEvent with _$HomeEvent {
const factory HomeEvent.getHomeContent() = _GetHomeData;
} | 0 |
mirrored_repositories/trave_tou_app/lib/application/home | mirrored_repositories/trave_tou_app/lib/application/home/bloc/home_bloc.freezed.dart | // coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target
part of 'home_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods');
/// @nodoc
mixin _$HomeEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() getHomeContent,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult Function()? getHomeContent,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? getHomeContent,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_GetHomeData value) getHomeContent,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult Function(_GetHomeData value)? getHomeContent,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_GetHomeData value)? getHomeContent,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $HomeEventCopyWith<$Res> {
factory $HomeEventCopyWith(HomeEvent value, $Res Function(HomeEvent) then) =
_$HomeEventCopyWithImpl<$Res>;
}
/// @nodoc
class _$HomeEventCopyWithImpl<$Res> implements $HomeEventCopyWith<$Res> {
_$HomeEventCopyWithImpl(this._value, this._then);
final HomeEvent _value;
// ignore: unused_field
final $Res Function(HomeEvent) _then;
}
/// @nodoc
abstract class _$$_GetHomeDataCopyWith<$Res> {
factory _$$_GetHomeDataCopyWith(
_$_GetHomeData value, $Res Function(_$_GetHomeData) then) =
__$$_GetHomeDataCopyWithImpl<$Res>;
}
/// @nodoc
class __$$_GetHomeDataCopyWithImpl<$Res> extends _$HomeEventCopyWithImpl<$Res>
implements _$$_GetHomeDataCopyWith<$Res> {
__$$_GetHomeDataCopyWithImpl(
_$_GetHomeData _value, $Res Function(_$_GetHomeData) _then)
: super(_value, (v) => _then(v as _$_GetHomeData));
@override
_$_GetHomeData get _value => super._value as _$_GetHomeData;
}
/// @nodoc
class _$_GetHomeData implements _GetHomeData {
const _$_GetHomeData();
@override
String toString() {
return 'HomeEvent.getHomeContent()';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$_GetHomeData);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() getHomeContent,
}) {
return getHomeContent();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult Function()? getHomeContent,
}) {
return getHomeContent?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? getHomeContent,
required TResult orElse(),
}) {
if (getHomeContent != null) {
return getHomeContent();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_GetHomeData value) getHomeContent,
}) {
return getHomeContent(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult Function(_GetHomeData value)? getHomeContent,
}) {
return getHomeContent?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_GetHomeData value)? getHomeContent,
required TResult orElse(),
}) {
if (getHomeContent != null) {
return getHomeContent(this);
}
return orElse();
}
}
abstract class _GetHomeData implements HomeEvent {
const factory _GetHomeData() = _$_GetHomeData;
}
/// @nodoc
mixin _$HomeState {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult Function()? initial,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult Function(_Initial value)? initial,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $HomeStateCopyWith<$Res> {
factory $HomeStateCopyWith(HomeState value, $Res Function(HomeState) then) =
_$HomeStateCopyWithImpl<$Res>;
}
/// @nodoc
class _$HomeStateCopyWithImpl<$Res> implements $HomeStateCopyWith<$Res> {
_$HomeStateCopyWithImpl(this._value, this._then);
final HomeState _value;
// ignore: unused_field
final $Res Function(HomeState) _then;
}
/// @nodoc
abstract class _$$_InitialCopyWith<$Res> {
factory _$$_InitialCopyWith(
_$_Initial value, $Res Function(_$_Initial) then) =
__$$_InitialCopyWithImpl<$Res>;
}
/// @nodoc
class __$$_InitialCopyWithImpl<$Res> extends _$HomeStateCopyWithImpl<$Res>
implements _$$_InitialCopyWith<$Res> {
__$$_InitialCopyWithImpl(_$_Initial _value, $Res Function(_$_Initial) _then)
: super(_value, (v) => _then(v as _$_Initial));
@override
_$_Initial get _value => super._value as _$_Initial;
}
/// @nodoc
class _$_Initial implements _Initial {
const _$_Initial();
@override
String toString() {
return 'HomeState.initial()';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$_Initial);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
}) {
return initial();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult Function()? initial,
}) {
return initial?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
required TResult orElse(),
}) {
if (initial != null) {
return initial();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
}) {
return initial(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult Function(_Initial value)? initial,
}) {
return initial?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
required TResult orElse(),
}) {
if (initial != null) {
return initial(this);
}
return orElse();
}
}
abstract class _Initial implements HomeState {
const factory _Initial() = _$_Initial;
}
| 0 |
mirrored_repositories/trave_tou_app/lib | mirrored_repositories/trave_tou_app/lib/config/globals.dart | import 'package:flutter/material.dart';
showBottomSheetWithData(BuildContext context, Widget widget,bool IsDismissable) {
return showModalBottomSheet(isDismissible: IsDismissable,
context: context,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(25.0)),
),
builder: (BuildContext context) {
return widget;
});
}
| 0 |
mirrored_repositories/trave_tou_app/lib | mirrored_repositories/trave_tou_app/lib/config/constants.dart | // ignore_for_file: constant_identifier_names
const String SESSION_KEY = 'SESSION';
const String PROFILE_IMAGE_KEY = 'PROFILE_KEY';
const String PROFILE_NAME_KEY = 'NAME_KEY';
const String PROFILE_EMAIL_KEY = 'NAME_EMAIL_KEY';
| 0 |
mirrored_repositories/trave_tou_app/lib | mirrored_repositories/trave_tou_app/lib/config/firestore_collection.dart | // ignore_for_file: non_constant_identifier_names, constant_identifier_names
class Collections {
/// All Firestore collection names should be declared here.
/// The usage of the firesore fucntions which contains firestore should only
/// go with this finals.
static const USERS = 'User_Data';
static const TRIP_DATA = 'Trip_Data';
}
| 0 |
mirrored_repositories/trave_tou_app/lib/infrastructure | mirrored_repositories/trave_tou_app/lib/infrastructure/firestore/firestore.dart | import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:injectable/injectable.dart';
import 'package:tourist_app/core/firestore/I_firestore.dart';
@Injectable()
@LazySingleton(as: Firestore)
class FirestoreFunctions implements Firestore {
@override
Future addDataToCollection(
String collection, Map<String, dynamic> data) async {
var res = await FirebaseFirestore.instance.collection(collection).add(data);
return res.id;
}
// updates an existing entry (missing fields won't be touched on update), document must exist
@override
Future updateEntryWithId(
String collection, String documentId, Map<String, dynamic> data) async {
await FirebaseFirestore.instance
.collection(collection)
.doc(documentId)
.update(data);
}
// adds or updates an existing entry (missing fields will be deleted on update!), document will be created if needed
@override
Future addOrUpdateWithId(
String collection, String documentId, Map<String, dynamic> data) async {
await FirebaseFirestore.instance
.collection(collection)
.doc(documentId)
.set(data);
}
// deletes the entry with the given document id
@override
Future deleteEntry(String collection, String documentId) async {
await FirebaseFirestore.instance
.collection(collection)
.doc(documentId)
.delete();
}
@override
Future getAllDataOfCollection(String collection) async {
await FirebaseFirestore.instance.collection(collection).get();
}
}
| 0 |
mirrored_repositories/trave_tou_app/lib/core | mirrored_repositories/trave_tou_app/lib/core/di/di.dart | import 'package:get_it/get_it.dart';
import 'package:injectable/injectable.dart';
import 'package:tourist_app/application/trip/bloc/trip_bloc.dart';
import 'package:tourist_app/core/auth/google_auth/auth.dart';
import 'package:tourist_app/core/auth/google_auth/google_auth.dart';
import 'package:tourist_app/domain/trip_create/trip_create.dart';
import 'package:tourist_app/infrastructure/firestore/firestore.dart';
import 'di.config.dart';
final getIt = GetIt.instance;
@InjectableInit()
Future<void> configureDependencies() async {
await $initGetIt(getIt, environment: Environment.prod);
getIt.registerSingleton<Auth>(Auth());
getIt.registerSingleton<TripCreateModel>(
const TripCreateModel(expense: '', fromDate: '', name: '', toDate: ''));
}
| 0 |
mirrored_repositories/trave_tou_app/lib/core | mirrored_repositories/trave_tou_app/lib/core/di/di.config.dart | // GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// InjectableConfigGenerator
// **************************************************************************
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'package:get_it/get_it.dart' as _i1;
import 'package:injectable/injectable.dart' as _i2;
import '../../application/auth/bloc/auth_bloc.dart' as _i3;
import '../../application/trip/bloc/trip_bloc.dart' as _i7;
import '../../infrastructure/firestore/firestore.dart' as _i5;
import '../auth/google_auth/auth.dart' as _i4;
import '../auth/google_auth/google_auth.dart'
as _i6; // ignore_for_file: unnecessary_lambdas
// ignore_for_file: lines_longer_than_80_chars
/// initializes the registration of provided dependencies inside of [GetIt]
_i1.GetIt $initGetIt(
_i1.GetIt get, {
String? environment,
_i2.EnvironmentFilter? environmentFilter,
}) {
final gh = _i2.GetItHelper(
get,
environment,
environmentFilter,
);
gh.factory<_i3.AuthBloc>(() => _i3.AuthBloc(get<_i4.Auth>()));
gh.factory<_i5.FirestoreFunctions>(() => _i5.FirestoreFunctions());
gh.lazySingleton<_i6.IGoogleSigning>(() => _i4.Auth());
gh.factory<_i7.TripBloc>(() => _i7.TripBloc(get<_i5.FirestoreFunctions>()));
return get;
}
| 0 |
mirrored_repositories/trave_tou_app/lib/core | mirrored_repositories/trave_tou_app/lib/core/firestore/I_firestore.dart |
abstract class Firestore {
// just a simple get
Future getAllDataOfCollection(String collection);
Future addDataToCollection(String collection, Map<String, dynamic> data);
// updates an existing entry (missing fields won't be touched on update), document must exist
Future updateEntryWithId(
String collection, String documentId, Map<String, dynamic> data);
// adds or updates an existing entry (missing fields will be deleted on update!), document will be created if needed
Future addOrUpdateWithId(
String collection, String documentId, Map<String, dynamic> data);
// deletes the entry with the given document id
Future deleteEntry(String collection, String documentId);
}
| 0 |
mirrored_repositories/trave_tou_app/lib/core/auth | mirrored_repositories/trave_tou_app/lib/core/auth/phone_auth/phone_auth.dart | ////Needed discussion on this, if phone auth need or not. | 0 |
mirrored_repositories/trave_tou_app/lib/core/auth | mirrored_repositories/trave_tou_app/lib/core/auth/google_auth/auth.dart | import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:dartz/dartz.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:injectable/injectable.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tourist_app/config/constants.dart';
import 'package:tourist_app/config/firestore_collection.dart';
import 'package:tourist_app/core/auth/google_auth/google_auth.dart';
import 'package:tourist_app/core/auth/google_auth/logged_in.dart';
import 'package:tourist_app/infrastructure/firestore/firestore.dart';
@LazySingleton(as: IGoogleSigning)
@injectable
class Auth implements IGoogleSigning, ILoggedIn {
@override
Future<Either<User?, String>> signInWithGoogle() async {
FirebaseAuth auth = FirebaseAuth.instance;
User? user;
try {
final GoogleSignIn googleSignIn = GoogleSignIn();
final GoogleSignInAccount? googleSignInAccount =
await googleSignIn.signIn();
if (googleSignInAccount != null) {
final GoogleSignInAuthentication googleSignInAuthentication =
await googleSignInAccount.authentication;
final AuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleSignInAuthentication.accessToken,
idToken: googleSignInAuthentication.idToken);
try {
final UserCredential userCredential =
await auth.signInWithCredential(credential);
user = userCredential.user;
} on FirebaseAuthException catch (e) {
if (e.code == 'account-exists-with-different-credential') {
return const Right('account-exists-with-different-credential');
} else if (e.code == 'invalid-credential') {
return Right(e.code.toString());
}
} catch (e) {
return const Right('Firebase-Error-Occured');
}
}
} catch (e) {
return const Right('Google-SingInError-Occured');
}
if (user != null) {
return Left(user);
} else {
return const Right('Missing-USER_DATA');
}
}
//Need to store shared preference data if logged in bool value
//Need to store google auth data to firestore
@override
Future postLoggedInData({User? userData}) async {
var prefs = await SharedPreferences.getInstance();
await prefs.setBool(SESSION_KEY, true);
await prefs.setString(PROFILE_EMAIL_KEY, userData!.email!);
await prefs.setString(PROFILE_IMAGE_KEY, userData.photoURL!);
await prefs.setString(PROFILE_NAME_KEY, userData.displayName!);
///Checking if the user already exist
var isEsxistEmail = await FirebaseFirestore.instance
.collection(Collections.USERS)
.where('email', isEqualTo: userData.email!)
.get();
if (isEsxistEmail.docs.isEmpty) {
FirestoreFunctions().addDataToCollection(Collections.USERS, {
'USER_NAME': userData.displayName,
'Profile_image': userData.photoURL,
'Phone_Number': userData.phoneNumber,
'uuid': userData.uid,
'email': userData.email,
'role': ''
});
} else {
Fluttertoast.showToast(msg: 'Welcome Back');
}
}
@override
Future clearLoggedInData() async {
var prefs = await SharedPreferences.getInstance();
prefs.setBool(SESSION_KEY, true);
}
@override
Future signOut() async {
final GoogleSignIn googleSignIn = GoogleSignIn();
final GoogleSignInAccount? googleSignInAccount =
await googleSignIn.signOut();
return true;
}
}
| 0 |
mirrored_repositories/trave_tou_app/lib/core/auth | mirrored_repositories/trave_tou_app/lib/core/auth/google_auth/logged_in.dart | import 'package:firebase_auth/firebase_auth.dart';
abstract class ILoggedIn {
Future postLoggedInData({User userData});
Future clearLoggedInData();
}
| 0 |
mirrored_repositories/trave_tou_app/lib/core/auth | mirrored_repositories/trave_tou_app/lib/core/auth/google_auth/google_auth.dart | import 'package:dartz/dartz.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:tourist_app/core/auth/google_auth/logged_in.dart';
abstract class IGoogleSigning {
///SingIn With Google Function
Future<Either<User?, String>> signInWithGoogle();
///SingOut With Google
Future signOut();
}
| 0 |
mirrored_repositories/trave_tou_app/lib/core | mirrored_repositories/trave_tou_app/lib/core/session/session.dart | import 'package:shared_preferences/shared_preferences.dart';
import 'package:tourist_app/config/constants.dart';
class AppSessions {
getSession() async {
final prefs = await SharedPreferences.getInstance();
var value = prefs.getString(SESSION_KEY);
return value;
}
}
| 0 |
mirrored_repositories/trave_tou_app/lib/domain | mirrored_repositories/trave_tou_app/lib/domain/trip_create/trip_create.dart | import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:meta/meta.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'dart:convert';
part 'trip_create.freezed.dart';
part 'trip_create.g.dart';
List<TripCreateModel> tripCreateModelListFromJson(String str) =>
List<TripCreateModel>.from(
json.decode(str).map((x) => TripCreateModel.fromJson(x)));
String tripCreateModelListToJson(List<TripCreateModel> data) =>
json.encode(List<dynamic>.from(data.map((x) => x.toJson())));
@freezed
abstract class TripCreateModel with _$TripCreateModel {
const factory TripCreateModel({
required String name,
required String fromDate,
required String toDate,
required String expense,
}) = _TripCreateModel;
factory TripCreateModel.fromJson(Map<String, dynamic> json) =>
_$TripCreateModelFromJson(json);
}
| 0 |
mirrored_repositories/trave_tou_app/lib/domain | mirrored_repositories/trave_tou_app/lib/domain/trip_create/trip_create.freezed.dart | // coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target
part of 'trip_create.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods');
TripCreateModel _$TripCreateModelFromJson(Map<String, dynamic> json) {
return _TripCreateModel.fromJson(json);
}
/// @nodoc
mixin _$TripCreateModel {
String get name => throw _privateConstructorUsedError;
String get fromDate => throw _privateConstructorUsedError;
String get toDate => throw _privateConstructorUsedError;
String get expense => throw _privateConstructorUsedError;
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$TripCreateModelCopyWith<TripCreateModel> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $TripCreateModelCopyWith<$Res> {
factory $TripCreateModelCopyWith(
TripCreateModel value, $Res Function(TripCreateModel) then) =
_$TripCreateModelCopyWithImpl<$Res>;
$Res call({String name, String fromDate, String toDate, String expense});
}
/// @nodoc
class _$TripCreateModelCopyWithImpl<$Res>
implements $TripCreateModelCopyWith<$Res> {
_$TripCreateModelCopyWithImpl(this._value, this._then);
final TripCreateModel _value;
// ignore: unused_field
final $Res Function(TripCreateModel) _then;
@override
$Res call({
Object? name = freezed,
Object? fromDate = freezed,
Object? toDate = freezed,
Object? expense = freezed,
}) {
return _then(_value.copyWith(
name: name == freezed
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String,
fromDate: fromDate == freezed
? _value.fromDate
: fromDate // ignore: cast_nullable_to_non_nullable
as String,
toDate: toDate == freezed
? _value.toDate
: toDate // ignore: cast_nullable_to_non_nullable
as String,
expense: expense == freezed
? _value.expense
: expense // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
abstract class _$$_TripCreateModelCopyWith<$Res>
implements $TripCreateModelCopyWith<$Res> {
factory _$$_TripCreateModelCopyWith(
_$_TripCreateModel value, $Res Function(_$_TripCreateModel) then) =
__$$_TripCreateModelCopyWithImpl<$Res>;
@override
$Res call({String name, String fromDate, String toDate, String expense});
}
/// @nodoc
class __$$_TripCreateModelCopyWithImpl<$Res>
extends _$TripCreateModelCopyWithImpl<$Res>
implements _$$_TripCreateModelCopyWith<$Res> {
__$$_TripCreateModelCopyWithImpl(
_$_TripCreateModel _value, $Res Function(_$_TripCreateModel) _then)
: super(_value, (v) => _then(v as _$_TripCreateModel));
@override
_$_TripCreateModel get _value => super._value as _$_TripCreateModel;
@override
$Res call({
Object? name = freezed,
Object? fromDate = freezed,
Object? toDate = freezed,
Object? expense = freezed,
}) {
return _then(_$_TripCreateModel(
name: name == freezed
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String,
fromDate: fromDate == freezed
? _value.fromDate
: fromDate // ignore: cast_nullable_to_non_nullable
as String,
toDate: toDate == freezed
? _value.toDate
: toDate // ignore: cast_nullable_to_non_nullable
as String,
expense: expense == freezed
? _value.expense
: expense // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
@JsonSerializable()
class _$_TripCreateModel implements _TripCreateModel {
const _$_TripCreateModel(
{required this.name,
required this.fromDate,
required this.toDate,
required this.expense});
factory _$_TripCreateModel.fromJson(Map<String, dynamic> json) =>
_$$_TripCreateModelFromJson(json);
@override
final String name;
@override
final String fromDate;
@override
final String toDate;
@override
final String expense;
@override
String toString() {
return 'TripCreateModel(name: $name, fromDate: $fromDate, toDate: $toDate, expense: $expense)';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$_TripCreateModel &&
const DeepCollectionEquality().equals(other.name, name) &&
const DeepCollectionEquality().equals(other.fromDate, fromDate) &&
const DeepCollectionEquality().equals(other.toDate, toDate) &&
const DeepCollectionEquality().equals(other.expense, expense));
}
@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(
runtimeType,
const DeepCollectionEquality().hash(name),
const DeepCollectionEquality().hash(fromDate),
const DeepCollectionEquality().hash(toDate),
const DeepCollectionEquality().hash(expense));
@JsonKey(ignore: true)
@override
_$$_TripCreateModelCopyWith<_$_TripCreateModel> get copyWith =>
__$$_TripCreateModelCopyWithImpl<_$_TripCreateModel>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$_TripCreateModelToJson(
this,
);
}
}
abstract class _TripCreateModel implements TripCreateModel {
const factory _TripCreateModel(
{required final String name,
required final String fromDate,
required final String toDate,
required final String expense}) = _$_TripCreateModel;
factory _TripCreateModel.fromJson(Map<String, dynamic> json) =
_$_TripCreateModel.fromJson;
@override
String get name;
@override
String get fromDate;
@override
String get toDate;
@override
String get expense;
@override
@JsonKey(ignore: true)
_$$_TripCreateModelCopyWith<_$_TripCreateModel> get copyWith =>
throw _privateConstructorUsedError;
}
| 0 |
mirrored_repositories/trave_tou_app/lib/domain | mirrored_repositories/trave_tou_app/lib/domain/trip_create/trip_create.g.dart | // GENERATED CODE - DO NOT MODIFY BY HAND
part of 'trip_create.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_$_TripCreateModel _$$_TripCreateModelFromJson(Map<String, dynamic> json) =>
_$_TripCreateModel(
name: json['name'] as String,
fromDate: json['fromDate'] as String,
toDate: json['toDate'] as String,
expense: json['expense'] as String,
);
Map<String, dynamic> _$$_TripCreateModelToJson(_$_TripCreateModel instance) =>
<String, dynamic>{
'name': instance.name,
'fromDate': instance.fromDate,
'toDate': instance.toDate,
'expense': instance.expense,
};
| 0 |
mirrored_repositories/trave_tou_app/lib/screens | mirrored_repositories/trave_tou_app/lib/screens/trip/trip_adding.dart | // Details adding page
import 'package:custom_date_range_picker/custom_date_range_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:image_picker/image_picker.dart';
import 'package:tourist_app/application/trip/bloc/trip_bloc.dart';
import 'package:tourist_app/core/di/di.dart';
import 'package:tourist_app/domain/trip_create/trip_create.dart';
TripCreateModel tripCreateModel = getIt.get<TripCreateModel>();
class TripAdding extends StatelessWidget {
const TripAdding({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return BlocListener<TripBloc, TripState>(
listener: (context, state) {
if (state.isAdded != null) {
if (state.isAdded!) {
Navigator.pop(context);
}
}
},
child: SafeArea(
child: Scaffold(
body: TripAddBody(size: size),
persistentFooterButtons: [
Container(
height: MediaQuery.of(context).size.height * .07,
child: BlocBuilder<TripBloc, TripState>(
builder: (context, state) {
if (state.isLoading) {
return const ElevatedButton(
onPressed: null,
child: Center(
child: CircularProgressIndicator(
strokeWidth: 2.0, color: Colors.white)));
}
return ElevatedButton(
onPressed: () {
context.read<TripBloc>().add(
TripEvent.createTrip(model: tripCreateModel));
},
child: const Center(child: Text('Add Trip')));
},
))
],
),
),
);
}
}
class TripAddBody extends StatelessWidget {
const TripAddBody({
Key? key,
required this.size,
}) : super(key: key);
final Size size;
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Column(
children: [
Container(
// ignore: prefer_const_constructors
// ignore: sort_child_properties_last
child: const Center(
child: Text("Add Trip",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 25))),
height: size.height * .10,
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(15),
bottomRight: Radius.circular(15)))),
SizedBox(height: size.height * .04),
Center(
child: GestureDetector(
onTap: (){
ImagePicker().pickImage(source: ImageSource.gallery);
},
child: Container(
height: size.height * .20,
width: size.width * .90,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
border: Border.all(
width: 4,
)),
child: const Center(
child: Text("Tap to choose image",
),
),
),
)),
SizedBox(height: size.height * .04),
Padding(
padding: const EdgeInsets.all(8.0),
child: Card(
elevation: 8,
child: TextField(
onChanged: (value) {
tripCreateModel = tripCreateModel.copyWith(name: value);
},
textAlign: TextAlign.center,
decoration: InputDecoration(
hintText: "Trip Name",
hintStyle: const TextStyle(color: Colors.grey),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(15)),
filled: true,
// fillColor: Colors.white
),
),
),
),
SizedBox(
height: size.height * .02,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Padding(
padding: const EdgeInsets.all(16.0),
child: Card(
elevation: 8,
child: InkWell(
onTap: () {
showCustomDateRangePicker(context,
dismissible: true,
minimumDate: DateTime.now(),
maximumDate: DateTime(2030),
onApplyClick: (start, end) {
tripCreateModel = tripCreateModel.copyWith(
fromDate: start.toString(),
toDate: end.toString());
}, onCancelClick: () {
Fluttertoast.showToast(
msg: 'Please select a Valid Date');
});
},
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.grey,
border: Border.all(
color: Colors.white,
width: 2,
)),
width: size.width * .35,
height: size.height * .05,
child: const Center(
child: Text("select a date")))))),
Padding(
padding: const EdgeInsets.all(16.0),
child: Container(
decoration: BoxDecoration(
border: Border.all(width: 2, color: Colors.white),
borderRadius: BorderRadius.circular(10)),
width: size.width * .35,
height: size.height * .05,
child: TextField(
onChanged: (value) {
tripCreateModel =
tripCreateModel.copyWith(expense: value);
},
maxLines: 1,
textAlign: TextAlign.center,
decoration: const InputDecoration(
// labelText: "Expense",
labelStyle: TextStyle(color: Colors.white),
prefix:
Padding(padding: EdgeInsets.only(top: 16.0)),
filled: true,
fillColor: Colors.grey,
border: InputBorder.none))))
],
),
],
),
);
}
}
| 0 |
mirrored_repositories/trave_tou_app/lib/screens | mirrored_repositories/trave_tou_app/lib/screens/profile/profile.dart | import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tourist_app/application/auth/bloc/auth_bloc.dart';
import 'package:tourist_app/screens/auth/login.dart';
class ProfilePage extends StatelessWidget {
const ProfilePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Me?')),
body: BlocListener<AuthBloc, AuthState>(
listener: (context, state) {
if (state.logout!) {
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(builder: (context) => const LoginScreen()),
(Route<dynamic> route) => false);
}
},
child: BlocBuilder<AuthBloc, AuthState>(
builder: (context, state) {
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircleAvatar(
backgroundImage: NetworkImage(state.profileImage!)),
ElevatedButton(
onPressed: () {
context.read<AuthBloc>().add(const AuthEvent.logout());
},
child: const Text('Logout'))
],
);
},
),
),
);
}
}
| 0 |
mirrored_repositories/trave_tou_app/lib/screens | mirrored_repositories/trave_tou_app/lib/screens/auth/login.dart | import 'dart:developer';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:auth_buttons/auth_buttons.dart'
show GoogleAuthButton, AuthButtonStyle, AuthButtonType, AuthIconType;
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:tourist_app/application/auth/bloc/auth_bloc.dart';
import 'package:tourist_app/config/globals.dart';
import 'package:tourist_app/screens/home/home.dart';
import 'package:tourist_app/screens/splash/splash.dart';
class LoginScreen extends StatelessWidget {
const LoginScreen({super.key});
@override
Widget build(BuildContext context) {
return BlocListener<AuthBloc, AuthState>(
listener: (context, state) {
log("$state");
if (state.isLoggedIn) {
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context) => const HomePage()));
} else if (state.isLogging) {
showBottomSheetWithData(
context,
SizedBox(
height: MediaQuery.of(context).size.height * 0.15,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const CircularProgressIndicator(strokeWidth: 2),
Text('Logging In..',
style: GoogleFonts.ptSans(color: Colors.grey))
],
),
),
),
false);
} else {
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context) => const HomePage()));
}
},
child: Scaffold(
body: Center(
child: GestureDetector(
child: GoogleAuthButton(
onPressed: () {
context.read<AuthBloc>().add(const AuthEvent.googleLogin());
},
style: const AuthButtonStyle(buttonType: AuthButtonType.icon),
),
),
),
),
);
}
}
| 0 |
mirrored_repositories/trave_tou_app/lib/screens | mirrored_repositories/trave_tou_app/lib/screens/home/home.dart | import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:tourist_app/application/auth/bloc/auth_bloc.dart';
import 'package:tourist_app/config/firestore_collection.dart';
import 'package:tourist_app/screens/profile/profile.dart';
import 'package:tourist_app/screens/trip/trip_adding.dart';
import 'package:tourist_app/screens/users/user.dart';
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Your Upcoming Trips')),
body: StreamBuilder(
stream: FirebaseFirestore.instance
.collection(Collections.TRIP_DATA)
.snapshots(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
} else if (!snapshot.hasData) {
return const Text('No Data...');
} else {
return ListView.builder(
itemCount: snapshot.data!.docs.length,
itemBuilder: (context, index) {
DocumentSnapshot data = snapshot.data!.docs[index];
return ListTile(
leading: CircleAvatar(
child: Center(
child: Text(data['Trip_name']
.toString()
.characters
.take(1)
.toString()),
),
),
onTap: () {},
title: Text(
data['Trip_name'],
),
trailing: Text('\u{20B9}${data['Expense']}'),
subtitle: Row(
children: [
Text(
'${data['TripFromDate'].toString().characters.take(10)} -'),
Text(
' ${data['TripToDate'].toString().characters.take(10)}')
],
),
);
});
}
}),
drawer: BlocBuilder<AuthBloc, AuthState>(
builder: (context, state) {
return Drawer(
child: Drawer(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(children: [
DrawerHeader(
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage('${state.profileImage}'),
fit: BoxFit.cover)),
child: Align(
alignment: Alignment.bottomLeft,
child: Text('${state.name}')),
),
ListTile(
title: const Text('Profile'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const ProfilePage()));
}),
ListTile(
title: const Text('Friends'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const UsersList()));
}),
]),
Container(
alignment: Alignment.bottomCenter,
child: const Text('All rights reserved',
style: TextStyle(color: Colors.grey, fontSize: 9)))
],
)));
},
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => const TripAdding()));
},
child: const Icon(Icons.add)),
);
}
}
| 0 |
mirrored_repositories/trave_tou_app/lib/screens | mirrored_repositories/trave_tou_app/lib/screens/splash/splash.dart | import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:tourist_app/application/auth/bloc/auth_bloc.dart';
import 'package:tourist_app/screens/auth/login.dart';
import 'package:tourist_app/screens/home/home.dart';
class SplashScreen extends StatelessWidget {
const SplashScreen({super.key});
@override
Widget build(BuildContext context) {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
context.read<AuthBloc>().add(const AuthEvent.getSession());
});
///Added a dummy image to show how the app theme shuld look like
///Please open asset folder to see the preview of the color theme of the app should be
return BlocListener<AuthBloc, AuthState>(
listener: (context, state) {
if (state.isLoggedIn) {
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context) => const HomePage()));
} else {
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context) => const LoginScreen()));
}
},
child: Image.asset('assets/images/splash.png', fit: BoxFit.fill));
}
}
| 0 |
mirrored_repositories/trave_tou_app/lib/screens | mirrored_repositories/trave_tou_app/lib/screens/users/user.dart | import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:tourist_app/application/auth/bloc/auth_bloc.dart';
import '../../config/firestore_collection.dart';
class UsersList extends StatelessWidget {
const UsersList({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Your Briends')),
body: StreamBuilder(
stream: FirebaseFirestore.instance
.collection(Collections.USERS)
.snapshots(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
} else if (!snapshot.hasData) {
return const Text('No Data...');
} else {
return ListView.builder(
itemCount: snapshot.data!.docs.length,
itemBuilder: (context, index) {
DocumentSnapshot data = snapshot.data!.docs[index];
return ListTile(
leading: CircleAvatar(
backgroundImage:
NetworkImage(data['Profile_image'])),
onTap: () {},
title: BlocBuilder<AuthBloc, AuthState>(
builder: (context, state) {
if (data['USER_NAME'] == state.name) {
return const Text('Me');
}
return Text(data['USER_NAME']);
},
),
trailing: BlocBuilder<AuthBloc, AuthState>(
builder: (context, state) {
if (data['USER_NAME'] != state.name) {
return data['role'] == null || data['role'] == ''
? IconButton(
onPressed: () {},
icon: const Icon(Icons.message))
: Text(data['role']);
}
return const SizedBox();
},
));
});
}
}),
);
}
}
| 0 |
mirrored_repositories/trave_tou_app | mirrored_repositories/trave_tou_app/test/widget_test.dart | // This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility in the flutter_test package. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:tourist_app/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}
| 0 |
mirrored_repositories/nike_store | mirrored_repositories/nike_store/lib/main.dart | import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:nike_store/screens/home/screen.dart';
import 'package:nike_store/src/res/theme.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return ScreenUtilInit(
minTextAdapt: true,
designSize: const Size(375,812),
builder: (context,_) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Nike Store',
theme: appTheme,
home: const HomeScreen(),
);
}
);
}
}
| 0 |
mirrored_repositories/nike_store/lib/app | mirrored_repositories/nike_store/lib/app/models/shoe.dart | class Shoe {
final String name;
final double price;
final String imageUrl;
Shoe({required this.name, required this.price, required this.imageUrl});
}
| 0 |
mirrored_repositories/nike_store/lib | mirrored_repositories/nike_store/lib/src/constants.dart | //All image assets
import 'package:nike_store/app/models/shoe.dart';
import 'package:nike_store/src/widgets/nav_icons.dart';
const String logo = 'assets/images/nike_logo.png';
const String greenShoe = 'assets/images/shoe1.png';
const String yellowShoe = 'assets/images/shoe2.png';
const String redBlueShoe = 'assets/images/shoe3.png';
const String blueShoe = 'assets/images/shoe4.png';
const String redShoe = 'assets/images/shoe5.png';
const String fullRedShoe = 'assets/images/shoe6.png';
const String whiteRedShoe = 'assets/images/shoe7.png';
const String nikeBox = 'assets/images/nike_box.png';
//All svg assets
const String cartIcon = 'assets/svg/cart.svg';
const String drawerIcon = 'assets/svg/drawer.svg';
const String backIcon = 'assets/svg/back.svg';
const String addToCart = 'assets/svg/add_to_cart.svg';
//all shoes
List<Shoe> allShoes = [
Shoe(name: 'Air Max 97', price: 20.99, imageUrl: yellowShoe),
Shoe(name: 'React Presto', price: 25.99, imageUrl: redBlueShoe),
Shoe(name: 'React Presto', price: 25.99, imageUrl: blueShoe),
Shoe(name: 'Air Max 270', price: 25.99, imageUrl: whiteRedShoe),
];
List navIcons = [
BottomNavIcons.home,
BottomNavIcons.bookmark,
BottomNavIcons.notification,
BottomNavIcons.user,
];
| 0 |
mirrored_repositories/nike_store/lib/src | mirrored_repositories/nike_store/lib/src/widgets/text.dart | import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:nike_store/src/res/colors.dart';
class KText extends StatelessWidget {
final String text;
final double? fontSize;
final FontWeight? fontWeight;
final Color? color;
final double? lineHeight;
final TextAlign? textAlign;
final FontStyle? fontStyle;
final TextDecoration? decoration;
final TextOverflow? overflow;
const KText(this.text,
{Key? key,
this.fontSize,
this.fontWeight,
this.color,
this.fontStyle,
this.lineHeight,
this.textAlign,
this.decoration,
this.overflow})
: super(key: key);
@override
Widget build(BuildContext context) {
return Text(
text,
textAlign: textAlign,
overflow: overflow,
style: GoogleFonts.workSans().copyWith(
decoration: decoration,
fontSize: fontSize ?? 14.sp,
fontStyle: fontStyle,
fontWeight: fontWeight ?? FontWeight.w300,
color: color ?? CustomColors.textColor,
height: lineHeight),
);
}
}
| 0 |
mirrored_repositories/nike_store/lib/src | mirrored_repositories/nike_store/lib/src/widgets/button.dart | import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:nike_store/src/res/colors.dart';
import 'package:nike_store/src/widgets/text.dart';
Widget kTextButton(
{required onTap,
required title,
buttonColor,
width,
height,
fontSize,
fontWeight,
textColor,
context}) {
return SizedBox(
height: height ?? 50.h,
width: width ?? 382.w,
child: TextButton(
onPressed: onTap,
style:
ButtonStyle(backgroundColor: MaterialStateProperty.all(buttonColor?? CustomColors.black)),
child: KText(
title,
color: textColor ?? CustomColors.white,
fontSize: fontSize ?? 14.sp,
fontWeight: fontWeight ?? FontWeight.w400,
),
),
);
}
Widget kOutlinedButton(
{required onTap,
required title,
textColor,
buttonColor,
borderColor,
fontSize,
fontWeight,
height,
width}) {
return SizedBox(
height: height ?? 50.h,
width: width ?? 382.w,
child: OutlinedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(buttonColor),
side: MaterialStateProperty.all(BorderSide(
width: 0.5, color: borderColor ?? CustomColors.black)),
),
onPressed: onTap,
child: KText(
title,
color: textColor ?? CustomColors.black,
fontSize: fontSize ?? 19.sp,
fontWeight: fontWeight ?? FontWeight.w400,
)),
);
}
Widget kElevatedButton({
required onTap,
required title,
textColor,
fontSize,
fontWeight,
buttonColor,
}) {
return SizedBox(
height: 50.h,
width: 382.w,
child: ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(buttonColor)),
onPressed: onTap,
child: KText(
title,
color: textColor ?? CustomColors.white,
fontSize: fontSize ?? 19.sp,
fontWeight: fontWeight ?? FontWeight.w400,
)),
);
}
| 0 |
mirrored_repositories/nike_store/lib/src | mirrored_repositories/nike_store/lib/src/widgets/nav_icons.dart | import 'package:flutter/widgets.dart';
class BottomNavIcons {
BottomNavIcons._();
static const _kFontFam = 'BottomNavIcons';
static const String? _kFontPkg = null;
static const IconData home = IconData(0xe800, fontFamily: _kFontFam, fontPackage: _kFontPkg);
static const IconData notification = IconData(0xe801, fontFamily: _kFontFam, fontPackage: _kFontPkg);
static const IconData user = IconData(0xe802, fontFamily: _kFontFam, fontPackage: _kFontPkg);
static const IconData bookmark = IconData(0xe803, fontFamily: _kFontFam, fontPackage: _kFontPkg);
}
| 0 |
mirrored_repositories/nike_store/lib/src | mirrored_repositories/nike_store/lib/src/widgets/nav_indicator.dart |
import 'package:flutter/material.dart';
class RPSCustomPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
Path path_0 = Path();
path_0.moveTo(34, 16.9988);
path_0.cubicTo(18.1863, 16.8383, 0, 0, 0, 0);
path_0.lineTo(69, 0);
path_0.cubicTo(69, 0, 50.1429, 17.1628, 34, 16.9988);
path_0.close();
Paint paint0Fill = Paint()..style = PaintingStyle.fill;
paint0Fill.color = Colors.black.withOpacity(1.0);
canvas.drawPath(path_0, paint0Fill);
Paint paint1Fill = Paint()..style = PaintingStyle.fill;
paint1Fill.color = Colors.white.withOpacity(1.0);
canvas.drawCircle(Offset(size.width * 0.5000000, size.height * 0.6176471),
size.width * 0.03623188, paint1Fill);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return true;
}
}
| 0 |
mirrored_repositories/nike_store/lib/src | mirrored_repositories/nike_store/lib/src/res/colors.dart | import 'package:flutter/material.dart';
class CustomColors {
static const Color textColor = Color(0xff202727);
static const Color containerColor = Color(0xffEFEFEF);
static const Color white = Colors.white;
static const Color black = Colors.black;
static const Color transparent = Colors.transparent;
static const Color unselectedTab = Color(0xff9C9C9C);
} | 0 |
mirrored_repositories/nike_store/lib/src | mirrored_repositories/nike_store/lib/src/res/theme.dart | import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
ThemeData appTheme = ThemeData(
fontFamily: GoogleFonts.workSans().fontFamily,
appBarTheme:
const AppBarTheme(backgroundColor: Colors.transparent, elevation: 0,));
| 0 |
mirrored_repositories/nike_store/lib/screens | mirrored_repositories/nike_store/lib/screens/details/screen.dart | import 'package:badges/badges.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/svg.dart';
import 'package:nike_store/screens/details/components/option_button.dart';
import 'package:nike_store/screens/details/components/shoe_size.dart';
import 'package:nike_store/src/constants.dart';
import 'package:nike_store/src/res/colors.dart';
import 'package:nike_store/src/widgets/nav_icons.dart';
import 'package:nike_store/src/widgets/text.dart';
class DetailsScreen extends StatelessWidget {
const DetailsScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
ValueNotifier<int> shoeColor = ValueNotifier(0);
Size size = MediaQuery.of(context).size;
return SafeArea(
child: Scaffold(
body: Stack(
children: [
Padding(
padding: EdgeInsets.fromLTRB(22.w, 16.h, 22.w, 0),
child: Column(
//padding: EdgeInsets.fromLTRB(22.w, 16.h, 22.w, 0),
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: SvgPicture.asset(
backIcon,
width: 36.w,
height: 36.w,
fit: BoxFit.none,
),
),
],
),
KText(
'Air Max 200 SE',
fontSize: 20.sp,
fontWeight: FontWeight.w700,
),
Badge(
badgeContent: KText(
'2',
fontSize: 10.sp,
color: CustomColors.white,
),
position: BadgePosition.topStart(),
badgeColor: CustomColors.black,
child: SvgPicture.asset(
cartIcon,
width: 36.w,
height: 36.w,
fit: BoxFit.scaleDown,
),
)
],
),
SizedBox(
height: 485.h,
width: size.width,
child: Stack(
children: [
Align(
alignment: Alignment.center,
child: Transform.rotate(
angle: 1.5708,
child: KText(
'NIKE',
fontSize: 160.sp,
fontWeight: FontWeight.w900,
color: CustomColors.black.withOpacity(0.1),
fontStyle: FontStyle.italic,
),
)),
Align(
alignment: Alignment.center,
child: Padding(
padding: const EdgeInsets.only(top: 20.0),
child: Image.asset(
fullRedShoe,
width: 300,
),
),
),
Positioned(
top: 117.h,
right: 0,
child: optionButton(
value: 1,
index: 1,
child: const Icon(
BottomNavIcons.bookmark,
size: 14,
)),
),
ValueListenableBuilder(
valueListenable: shoeColor,
builder: (context, colorState, _) {
return Positioned(
top: 245.h,
right: 0,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
KText(
'Colour',
fontSize: 14.sp,
fontWeight: FontWeight.w600,
),
Padding(
padding: EdgeInsets.only(
top: 14.h, bottom: 17.h),
child: GestureDetector(
onTap: () {
shoeColor.value = 0;
},
child: optionButton(
index: 0,
value: colorState,
child: Container(
width: 14.w,
height: 14.w,
decoration: BoxDecoration(
color: const Color(0xffCD2626),
borderRadius:
BorderRadius.circular(2.r)),
),
),
),
),
GestureDetector(
onTap: () {
shoeColor.value = 1;
},
child: optionButton(
index: 1,
value: colorState,
child: Container(
width: 14.w,
height: 14.w,
decoration: BoxDecoration(
color: const Color(0xff394376),
borderRadius:
BorderRadius.circular(2.r)),
)),
),
],
),
);
}),
Positioned(
top: 90.h,
left: 0,
child: const ShoeSize(),
),
Positioned(
top: 423.h,
left: 0,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
KText(
'\$30.99',
fontSize: 18.sp,
fontWeight: FontWeight.w600,
),
KText(
'10% OFF',
fontSize: 12.sp,
color: const Color(0xffBE3032),
)
],
),
),
],
),
),
const Spacer(),
Image.asset(
nikeBox,
filterQuality: FilterQuality.high,
)
],
),
),
Positioned(
bottom: 128.h,
left: 135.w,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.only(bottom: 8.h),
child: KText(
'Swipe down to add',
fontSize: 12.sp,
fontWeight: FontWeight.w600,
),
),
SvgPicture.asset(
addToCart,
width: 42.w,
fit: BoxFit.scaleDown,
),
],
),
)
],
),
));
}
}
| 0 |
mirrored_repositories/nike_store/lib/screens/details | mirrored_repositories/nike_store/lib/screens/details/components/option_button.dart | import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:nike_store/src/res/colors.dart';
Widget optionButton({
required Widget child,
double? contentPadding,
required int index,
required int value,
double? width,
double? height,
}) {
return AnimatedContainer(
duration: const Duration(milliseconds: 500),
padding: EdgeInsets.all(contentPadding ?? 5),
width: width ?? 32.w,
height: height ?? 32.w,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.r),
border: Border.all(
color: value == index ? CustomColors.black : const Color(0xffE0E0E1),
width: 0.82)),
child: child);
}
| 0 |
mirrored_repositories/nike_store/lib/screens/details | mirrored_repositories/nike_store/lib/screens/details/components/shoe_size.dart | import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:nike_store/src/widgets/text.dart';
import 'option_button.dart';
class ShoeSize extends StatelessWidget {
const ShoeSize({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
ValueNotifier<int> shoeSize = ValueNotifier(6);
return ValueListenableBuilder(
valueListenable: shoeSize,
builder: (context, shoeState, _) {
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.only(bottom: 11.h),
child: KText(
'Size',
fontSize: 14.sp,
fontWeight: FontWeight.w600,
),
),
...List.generate(
4,
(index) => GestureDetector(onTap: (){
shoeSize.value = 6+index;
},
child: Padding(
padding: EdgeInsets.only(bottom: 16.h),
child: optionButton(
width: 56.w,
child: KText('UK ${6 + index}'),
index: 6 + index,value: shoeState),
),
))
],
);
});
}
}
| 0 |
mirrored_repositories/nike_store/lib/screens | mirrored_repositories/nike_store/lib/screens/home/screen.dart | import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:nike_store/screens/home/components/bottom_nav_icon.dart';
import 'package:nike_store/screens/home/components/carousel.dart';
import 'package:nike_store/screens/home/components/shoe_card.dart';
import 'package:nike_store/src/constants.dart';
import 'package:nike_store/src/res/colors.dart';
class HomeScreen extends StatelessWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
ValueNotifier<int> selectedNav = ValueNotifier(0);
return DefaultTabController(
length: 5,
child: SafeArea(
child: Scaffold(
body: ListView(
padding: EdgeInsets.fromLTRB(22.w, 16.h, 22.w, 0),
children: [
//APP BAR
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
SvgPicture.asset(
drawerIcon,
width: 36.w,
height: 36.w,
fit: BoxFit.none,
),
Padding(
padding: EdgeInsets.only(left: 16.w),
child: Image.asset(
logo,
filterQuality: FilterQuality.high,
),
)
],
),
SvgPicture.asset(
cartIcon,
width: 36.w,
height: 36.w,
fit: BoxFit.scaleDown,
)
],
),
//CAROUSEL
Padding(
padding: EdgeInsets.only(top: 30.h, bottom: 21.h),
child: const HeaderCarousel(),
),
Padding(
padding: EdgeInsets.only(bottom: 30.h),
child: TabBar(
labelPadding:
EdgeInsets.symmetric(horizontal: 20.w, vertical: 0),
indicatorSize: TabBarIndicatorSize.tab,
unselectedLabelColor: CustomColors.unselectedTab,
isScrollable: true,
indicator: const ShapeDecoration(
shape: StadiumBorder(), color: CustomColors.black),
tabs: const [
Tab(text: 'All'),
Tab(text: 'Running'),
Tab(text: 'Sneaker'),
Tab(text: 'Formal'),
Tab(text: 'Casual'),
]),
),
/*GridView.count(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
crossAxisCount: 2,
crossAxisSpacing: 16.w,
mainAxisSpacing: 26.h,
children: List.generate(4, (index) => shoeCard()),
)*/
//Shoe cards
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [shoeCard(allShoes[0],context), shoeCard(allShoes[1],context)],
),
SizedBox(height: 26.h),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [shoeCard(allShoes[2],context), shoeCard(allShoes[3],context)],
)
],
),
bottomSheet: SizedBox(
height: 85.h,
width: size.width,
child: Container(
decoration:
BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(24.r),
topRight: Radius.circular(24.r)),
color: CustomColors.white, boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.4),
blurRadius: 30,
offset:const Offset(0, -10), // Shadow position
),
]),
child: ValueListenableBuilder(
valueListenable: selectedNav,
builder: (context, navState, _) {
return Padding(
padding: EdgeInsets.symmetric(horizontal: 8.w),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
...List.generate(
4,
(index) => InkWell(
onTap: () {
selectedNav.value = index;
},
child: bottomNavIcon(
icon: navIcons[index],
value: navState,
index: index),
)),
],
),
);
}),
),
),
)),
);
}
}
| 0 |
mirrored_repositories/nike_store/lib/screens/home | mirrored_repositories/nike_store/lib/screens/home/components/shoe_card.dart | import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:nike_store/app/models/shoe.dart';
import 'package:nike_store/screens/details/screen.dart';
import 'package:nike_store/src/res/colors.dart';
import 'package:nike_store/src/widgets/text.dart';
Widget shoeCard(Shoe shoe,context) {
return GestureDetector(
onTap: (){
Navigator.push(context, MaterialPageRoute(builder: (context)=>const DetailsScreen()));
},
child: Container(
width: 160.w,
height: 237.h,
padding: EdgeInsets.all(16.w),
decoration: BoxDecoration(
color: CustomColors.containerColor,
borderRadius: BorderRadius.circular(18.r),
),
child: Column(
children: [
Image.asset(
shoe.imageUrl,
width: 140.w,
),
const Spacer(),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
KText(
shoe.name,
fontSize: 16.sp,
fontWeight: FontWeight.bold,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
KText(
'\$${shoe.price}',
fontSize: 16.sp,
fontWeight: FontWeight.w500,
),
Container(
decoration: BoxDecoration(
color: CustomColors.white,
borderRadius: BorderRadius.circular(8.r),
border: Border.all(
width: 1,
color: const Color(0xff374957).withOpacity(0.2),
),
),
child: const Icon(
Icons.arrow_forward_sharp,
size: 20,
color: CustomColors.black,
),
),
],
),
],
),
],
),
),
);
}
| 0 |
mirrored_repositories/nike_store/lib/screens/home | mirrored_repositories/nike_store/lib/screens/home/components/carousel.dart | import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:nike_store/screens/details/screen.dart';
import 'package:nike_store/src/constants.dart';
import 'package:nike_store/src/res/colors.dart';
import 'package:nike_store/src/widgets/text.dart';
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
class HeaderCarousel extends StatelessWidget {
const HeaderCarousel({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: (){
Navigator.push(context, MaterialPageRoute(builder: (context)=>const DetailsScreen()));
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Stack(
children: [
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: Container(
width: 334.w,
height: 150.h,
decoration: BoxDecoration(
color: CustomColors.containerColor,
borderRadius: BorderRadius.circular(18.r)),
child: Padding(
padding: EdgeInsets.only(left: 26.w),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text.rich(TextSpan(
children: [
const TextSpan(
text: '20% ',
),
TextSpan(
text: 'Discount',
style: TextStyle(fontSize: 19.sp)),
],
style: TextStyle(
fontWeight: FontWeight.w600, fontSize: 24.sp))),
const KText('on your first purchase'),
Padding(
padding: EdgeInsets.only(
top: 22.h,
),
child: InkWell(
onTap: () {},
child: Container(
width: 96.w,
height: 29.h,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.r),
color: CustomColors.black),
alignment: Alignment.center,
child: KText(
'Shop now',
fontSize: 10.sp,
fontWeight: FontWeight.w500,
color: CustomColors.white,
),
),
),
),
],
),
),
),
),
Positioned(
right: 0,
child: Image.asset(
greenShoe,
width: 160.w,
))
],
),
Padding(
padding: EdgeInsets.only(top: 16.h),
child: AnimatedSmoothIndicator(
activeIndex: 1,
count: 4,
effect: JumpingDotEffect(
dotColor: const Color(0xffC4C4C4),
activeDotColor: CustomColors.black,
dotHeight: 8.w,
dotWidth: 8.w),
),
)
],
),
);
}
}
| 0 |
mirrored_repositories/nike_store/lib/screens/home | mirrored_repositories/nike_store/lib/screens/home/components/bottom_nav_icon.dart | import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:nike_store/src/res/colors.dart';
import 'package:nike_store/src/widgets/nav_indicator.dart';
Widget bottomNavIcon(
{required IconData icon, required int value, required int index}) {
return Column(
crossAxisAlignment: CrossAxisAlignment.center,mainAxisAlignment: MainAxisAlignment.start,
children: [
value == index?
CustomPaint(
size: Size(69.w, 17.h),
painter: RPSCustomPainter(),
): SizedBox(height: 17.h,width: 69.w,),
Padding(
padding: EdgeInsets.only(top: 8.h),
child: Icon(icon,color: value == index? CustomColors.black:const Color(0xff838383),),
),
],
);
}
| 0 |
mirrored_repositories/nike_store | mirrored_repositories/nike_store/test/widget_test.dart | // This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility in the flutter_test package. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:nike_store/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}
| 0 |
mirrored_repositories/flutter-examples/statless_counter_app | mirrored_repositories/flutter-examples/statless_counter_app/lib/counter.dart | import 'package:mobx/mobx.dart';
// Include generated file
part 'counter.g.dart';
// This is the class used by rest of your codebase
class Counter = _Counter with _$Counter;
// The store-class
abstract class _Counter with Store {
@observable
int value = 0;
@action
void increment() {
value++;
}
} | 0 |
mirrored_repositories/flutter-examples/statless_counter_app | mirrored_repositories/flutter-examples/statless_counter_app/lib/main.dart | import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'counter.dart'; // Import the Counter
final counter = Counter(); // Instantiate the store
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'MobX',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('MobX Stateless Widget Counter'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
// Wrapping in the Observer will automatically re-render on changes to counter.value
Observer(
builder: (_) => Text(
'${counter.value}',
style: Theme.of(context).textTheme.headline4,
),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: counter.increment,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
} | 0 |
mirrored_repositories/flutter-examples/statless_counter_app | mirrored_repositories/flutter-examples/statless_counter_app/lib/counter.g.dart | // GENERATED CODE - DO NOT MODIFY BY HAND
part of 'counter.dart';
// **************************************************************************
// StoreGenerator
// **************************************************************************
// ignore_for_file: non_constant_identifier_names, unnecessary_brace_in_string_interps, unnecessary_lambdas, prefer_expression_function_bodies, lines_longer_than_80_chars, avoid_as, avoid_annotating_with_dynamic
mixin _$Counter on _Counter, Store {
final _$valueAtom = Atom(name: '_Counter.value');
@override
int get value {
_$valueAtom.reportRead();
return super.value;
}
@override
set value(int value) {
_$valueAtom.reportWrite(value, super.value, () {
super.value = value;
});
}
final _$_CounterActionController = ActionController(name: '_Counter');
@override
void increment() {
final _$actionInfo =
_$_CounterActionController.startAction(name: '_Counter.increment');
try {
return super.increment();
} finally {
_$_CounterActionController.endAction(_$actionInfo);
}
}
@override
String toString() {
return '''
value: ${value}
''';
}
}
| 0 |
mirrored_repositories/flutter-examples/statless_counter_app | mirrored_repositories/flutter-examples/statless_counter_app/test/widget_test.dart | // This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:statless_counter_app/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(MyApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}
| 0 |
mirrored_repositories/flutter-examples/bottom_sheet | mirrored_repositories/flutter-examples/bottom_sheet/lib/main.dart | import 'package:flutter/material.dart';
import 'package:project/home.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Bottom Sheet',
theme: ThemeData(
primarySwatch: Colors.red,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Bottom Sheet'),
);
}
}
| 0 |
mirrored_repositories/flutter-examples/bottom_sheet | mirrored_repositories/flutter-examples/bottom_sheet/lib/home.dart | import 'package:flutter/material.dart';
import 'package:project/models/ListTileModel.dart';
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
backgroundColor: Colors.redAccent,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new RaisedButton(
child: Text(
"Bottom Sheet",
style: TextStyle(fontSize: 20),
),
onPressed: () {
_openBottomSheet(context);
},
)
],
),
),
);
}
}
void _openBottomSheet(context) {
showModalBottomSheet(
context: context,
builder: (builder) {
return new Container(
padding: EdgeInsets.all(5.0),
child: new Wrap(
children: <Widget>[
getListTile(Icons.more, Colors.black45, "More", context),
getListTile(Icons.favorite, Colors.pink, "Favourites", context),
getListTile(Icons.account_box, Colors.blue, "Profile", context),
new Divider(
thickness: 2.0,
height: 10.0,
),
getListTile(Icons.exit_to_app, null, "Logout", context),
],
),
);
},
);
}
| 0 |
mirrored_repositories/flutter-examples/bottom_sheet/lib | mirrored_repositories/flutter-examples/bottom_sheet/lib/models/ListTileModel.dart | import 'package:flutter/material.dart';
ListTile getListTile(icon, iconColor, titleText, context) {
return new ListTile(
leading: new Container(
width: 4.0,
child: Icon(
icon,
color: iconColor,
size: 24.0,
),
),
title: new Text(
titleText,
style: TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.w700,
),
),
onTap: () => Navigator.of(context).pop(),
);
}
| 0 |
mirrored_repositories/flutter-examples/bottom_sheet | mirrored_repositories/flutter-examples/bottom_sheet/test/widget_test.dart | // This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter_test/flutter_test.dart';
import 'package:project/main.dart';
void main() {
testWidgets('Checks on tap dismissal of bottom sheet', (WidgetTester tester) async {
// Build the app and trigger a frame.
await tester.pumpWidget(MyApp());
expect(find.text('BottomSheet'), findsNothing);
await tester.tap(find.text('BottomSheet'));
await tester.pump();
await tester.pump(const Duration(seconds: 1));
await tester.pump(const Duration(seconds: 1));
expect(find.text('BottomSheet'), findsNothing);
});
}
| 0 |
mirrored_repositories/flutter-examples/google_signin | mirrored_repositories/flutter-examples/google_signin/lib/main.dart | import 'dart:async';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'home.dart';
import 'user.dart';
void main() {
runApp(App());
}
class App extends StatefulWidget {
AppState createState() => AppState();
}
class AppState extends State<App> {
String _username = "";
Widget currentPage;
GoogleSignIn googleSignIn;
Widget userPage;
@override
void initState() {
super.initState();
userPage = Home(
onSignin: () {
_signin();
print("Sign");
},
onLogout: _logout,
showLoading: false,
);
}
Future<FirebaseUser> _signin() async {
setState(() {
userPage = Home(onSignin: null, onLogout: _logout, showLoading: true);
});
FirebaseAuth _auth = FirebaseAuth.instance;
try {
googleSignIn = GoogleSignIn();
GoogleSignInAccount googleSignInAccount = await googleSignIn.signIn();
final GoogleSignInAuthentication gauth = await googleSignInAccount.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: gauth.accessToken,
idToken: gauth.idToken,
);
final AuthResult authRes = await _auth.signInWithCredential(credential);
final FirebaseUser user = authRes.user;
setState(() {
_username = user.displayName;
userPage = User(
onLogout: _logout,
user: user,
);
});
return user;
} catch (e) {
print(e.toString());
}
return null;
}
void _logout() async {
await googleSignIn.signOut();
setState(() {
userPage = Home(
onSignin: () {
_signin();
print("Sign");
},
onLogout: _logout,
showLoading: false,
);
});
print("Logged Out");
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: userPage,
);
}
}
| 0 |
mirrored_repositories/flutter-examples/google_signin | mirrored_repositories/flutter-examples/google_signin/lib/user.dart | import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:meta/meta.dart';
class User extends StatelessWidget {
User({Key key, @required this.onLogout, @required this.user})
: super(key: key);
VoidCallback onLogout;
String username;
FirebaseUser user;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Welcome"),
actions: <Widget>[
IconButton(
icon: Icon(Icons.exit_to_app), onPressed: this.onLogout)
],
),
body: Container(
padding: const EdgeInsets.all(20.0),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.network(user.photoUrl),
Text(
user.displayName,
textScaleFactor: 1.5,
),
],
))),
);
}
}
| 0 |
mirrored_repositories/flutter-examples/google_signin | mirrored_repositories/flutter-examples/google_signin/lib/home.dart | import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:meta/meta.dart';
class Home extends StatelessWidget {
Home(
{Key key,
@required this.onSignin,
@required this.onLogout,
@required this.showLoading})
: super(key: key);
final VoidCallback onSignin;
final VoidCallback onLogout;
bool showLoading = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Sign In")),
body: Container(
padding: const EdgeInsets.all(20.0),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
showLoading
? CircularProgressIndicator()
: RaisedButton(
onPressed: this.onSignin,
child: Text("Sign In"),
color: Colors.lightBlueAccent,
),
//RaisedButton(onPressed: this.onLogout, child: Text("Logout"), color: Colors.amberAccent),
],
),
)),
);
}
}
| 0 |
mirrored_repositories/flutter-examples/google_signin/android | mirrored_repositories/flutter-examples/google_signin/android/lib/main.dart | import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
// This makes the visual density adapt to the platform that you run
// the app on. For desktop platforms, the controls will be smaller and
// closer together (more dense) than on mobile platforms.
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
| 0 |
mirrored_repositories/flutter-examples/google_signin/android | mirrored_repositories/flutter-examples/google_signin/android/test/widget_test.dart | // This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:android/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(MyApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}
| 0 |
mirrored_repositories/flutter-examples/tip_calculator | mirrored_repositories/flutter-examples/tip_calculator/lib/main.dart | import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(title: 'Tip Calculator', home: TipCalculator()));
}
class TipCalculator extends StatelessWidget {
double billAmount = 0.0;
double tipPercentage = 0.0;
@override
Widget build(BuildContext context) {
// Create first input field
TextField billAmountField = TextField(
keyboardType: TextInputType.number,
onChanged: (String value) {
try {
billAmount = double.parse(value);
} catch (exception) {
billAmount = 0.0;
}
},
decoration: InputDecoration(labelText: "Bill amount(\$)"),
);
// Create another input field
TextField tipPercentageField = TextField(
decoration: InputDecoration(labelText: "Tip %", hintText: "15"),
keyboardType: TextInputType.number,
onChanged: (String value) {
try {
tipPercentage = double.parse(value);
} catch (exception) {
tipPercentage = 0.0;
}
});
// Create button
RaisedButton calculateButton = RaisedButton(
child: Text("Calculate"),
onPressed: () {
// Calculate tip and total
double calculatedTip = billAmount * tipPercentage / 100.0;
double total = billAmount + calculatedTip;
// Generate dialog
AlertDialog dialog = AlertDialog(
content: Text("Tip: \$$calculatedTip \n"
"Total: \$$total"));
// Show dialog
showDialog(context: context, builder: (BuildContext context) => dialog);
});
Container container = Container(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [billAmountField, tipPercentageField, calculateButton]));
AppBar appBar = AppBar(title: Text("Tip Calculator"));
Scaffold scaffold = Scaffold(appBar: appBar, body: container);
return scaffold;
}
}
| 0 |
mirrored_repositories/flutter-examples/tip_calculator/android | mirrored_repositories/flutter-examples/tip_calculator/android/lib/main.dart | import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
// This makes the visual density adapt to the platform that you run
// the app on. For desktop platforms, the controls will be smaller and
// closer together (more dense) than on mobile platforms.
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
| 0 |
mirrored_repositories/flutter-examples/tip_calculator/android | mirrored_repositories/flutter-examples/tip_calculator/android/test/widget_test.dart | // This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:android/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(MyApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}
| 0 |
mirrored_repositories/flutter-examples/view_pdf_file | mirrored_repositories/flutter-examples/view_pdf_file/lib/viewPDF.dart | import 'package:advance_pdf_viewer/advance_pdf_viewer.dart';
import 'package:flutter/material.dart';
class ViewPDF extends StatelessWidget {
final PDFDocument doc;
ViewPDF({
@required this.doc,
});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Example'),
),
body: Center(child: PDFViewer(document: doc)),
);
}
}
| 0 |
mirrored_repositories/flutter-examples/view_pdf_file | mirrored_repositories/flutter-examples/view_pdf_file/lib/constants.dart | class Constants {
static final String pdfURL =
"https://raw.githubusercontent.com/nisrulz/flutter-examples/master/view_pdf_file/assets/Hello.pdf";
}
| 0 |
mirrored_repositories/flutter-examples/view_pdf_file | mirrored_repositories/flutter-examples/view_pdf_file/lib/main.dart | import 'package:advance_pdf_viewer/advance_pdf_viewer.dart';
import 'package:flutter/material.dart';
import 'package:view_pdf_file/constants.dart';
import 'package:view_pdf_file/viewPDF.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'View PDF File',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: HomePage());
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
bool isLoading = false;
PDFDocument doc;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("View PDF File"),
),
body: Container(
child: Center(
child: isLoading
? CircularProgressIndicator()
: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
RaisedButton(
onPressed: () {
loadFromAsset();
},
child: Text("Load local PDF"),
),
RaisedButton(
onPressed: () {
loadFromURL();
},
child: Text("Load PDF via URL"),
),
],
),
),
),
);
}
loadFromAsset() async {
setState(() {
isLoading = true;
});
doc = await PDFDocument.fromAsset('assets/Hello.pdf');
setState(() {
isLoading = false;
});
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => ViewPDF(doc: doc),
),
);
}
loadFromURL() async {
setState(() {
isLoading = true;
});
doc = await PDFDocument.fromURL(Constants.pdfURL);
setState(() {
isLoading = false;
});
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => ViewPDF(doc: doc),
),
);
}
}
| 0 |
mirrored_repositories/flutter-examples/view_pdf_file | mirrored_repositories/flutter-examples/view_pdf_file/test/widget_test.dart | // This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:view_pdf_file/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(MyApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}
| 0 |
mirrored_repositories/flutter-examples/using_bottom_nav_bar | mirrored_repositories/flutter-examples/using_bottom_nav_bar/lib/main.dart | import 'package:flutter/material.dart';
import 'package:using_bottom_nav_bar/tabs/first.dart';
import 'package:using_bottom_nav_bar/tabs/second.dart';
import 'package:using_bottom_nav_bar/tabs/third.dart';
void main() {
runApp(MaterialApp(
// Title
title: "Using Tabs",
// Home
home: MyHome()));
}
class MyHome extends StatefulWidget {
@override
MyHomeState createState() => MyHomeState();
}
// SingleTickerProviderStateMixin is used for animation
class MyHomeState extends State<MyHome> with SingleTickerProviderStateMixin {
// Create a tab controller
TabController controller;
@override
void initState() {
super.initState();
// Initialize the Tab Controller
controller = TabController(length: 3, vsync: this);
}
@override
void dispose() {
// Dispose of the Tab Controller
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
// Appbar
appBar: AppBar(
// Title
title: Text("Using Bottom Navigation Bar"),
// Set the background color of the App Bar
backgroundColor: Colors.blue,
),
// Set the TabBar view as the body of the Scaffold
body: TabBarView(
// Add tabs as widgets
children: <Widget>[FirstTab(), SecondTab(), ThirdTab()],
// set the controller
controller: controller,
),
// Set the bottom navigation bar
bottomNavigationBar: Material(
// set the color of the bottom navigation bar
color: Colors.blue,
// set the tab bar as the child of bottom navigation bar
child: TabBar(
tabs: <Tab>[
Tab(
// set icon to the tab
icon: Icon(Icons.favorite),
),
Tab(
icon: Icon(Icons.adb),
),
Tab(
icon: Icon(Icons.airport_shuttle),
),
],
// setup the controller
controller: controller,
),
),
);
}
}
| 0 |
mirrored_repositories/flutter-examples/using_bottom_nav_bar/lib | mirrored_repositories/flutter-examples/using_bottom_nav_bar/lib/tabs/third.dart | import 'package:flutter/material.dart';
class ThirdTab extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.orange,
body: Container(
child: Center(
child: Column(
// center the children
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
Icons.airport_shuttle,
size: 160.0,
color: Colors.white,
),
Text(
"Third Tab",
style: TextStyle(color: Colors.white),
)
],
),
),
),
);
}
}
| 0 |
mirrored_repositories/flutter-examples/using_bottom_nav_bar/lib | mirrored_repositories/flutter-examples/using_bottom_nav_bar/lib/tabs/second.dart | import 'package:flutter/material.dart';
class SecondTab extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.green,
body: Container(
child: Center(
child: Column(
// center the children
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
Icons.adb,
size: 160.0,
color: Colors.white,
),
Text(
"Second Tab",
style: TextStyle(color: Colors.white),
)
],
),
),
),
);
}
}
| 0 |
mirrored_repositories/flutter-examples/using_bottom_nav_bar/lib | mirrored_repositories/flutter-examples/using_bottom_nav_bar/lib/tabs/first.dart | import 'package:flutter/material.dart';
class FirstTab extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.red,
body: Container(
child: Center(
child: Column(
// center the children
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
Icons.favorite,
size: 160.0,
color: Colors.white,
),
Text(
"First Tab",
style: TextStyle(color: Colors.white),
)
],
),
),
),
);
}
}
| 0 |
mirrored_repositories/flutter-examples/using_bottom_nav_bar/android | mirrored_repositories/flutter-examples/using_bottom_nav_bar/android/lib/main.dart | import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
// This makes the visual density adapt to the platform that you run
// the app on. For desktop platforms, the controls will be smaller and
// closer together (more dense) than on mobile platforms.
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
| 0 |
mirrored_repositories/flutter-examples/using_bottom_nav_bar/android | mirrored_repositories/flutter-examples/using_bottom_nav_bar/android/test/widget_test.dart | // This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:android/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(MyApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}
| 0 |
mirrored_repositories/flutter-examples/handling_routes | mirrored_repositories/flutter-examples/handling_routes/lib/main.dart | import 'package:flutter/material.dart';
import 'package:handling_routes/screens/about.dart';
import 'package:handling_routes/screens/home.dart';
void main() {
runApp(MaterialApp(
home: HomePage(), // home has implicit route set at '/'
// Setup routes
routes: <String, WidgetBuilder>{
// Set named routes
AboutPage.routeName: (BuildContext context) => AboutPage(),
},
));
}
| 0 |
mirrored_repositories/flutter-examples/handling_routes/lib | mirrored_repositories/flutter-examples/handling_routes/lib/screens/about.dart | import 'package:flutter/material.dart';
class AboutPage extends StatelessWidget {
static const String routeName = "/about";
@override
Widget build(BuildContext context) {
return Scaffold(
// AppBar
appBar: AppBar(
// Title
title: Text("About Page"),
// App Bar background color
backgroundColor: Colors.blue,
),
// Body
body: Container(
// Center the content
child: Center(
child: Column(
// Center content in the column
mainAxisAlignment: MainAxisAlignment.center,
// add children to the column
children: <Widget>[
// Text
Text(
"About Page\nClick on below icon to goto Home Page",
// Setting the style for the Text
style: TextStyle(fontSize: 20.0),
// Set text alignment to center
textAlign: TextAlign.center,
),
// Icon Button
IconButton(
icon: Icon(
Icons.home,
color: Colors.red,
),
// Execute when pressed
onPressed: () {
// use the navigator to goto a named route
Navigator.of(context).pushNamed('/');
},
// Setting the size of icon
iconSize: 80.0,
)
],
),
),
),
);
}
}
| 0 |
mirrored_repositories/flutter-examples/handling_routes/lib | mirrored_repositories/flutter-examples/handling_routes/lib/screens/home.dart | import 'package:flutter/material.dart';
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
// AppBar
appBar: AppBar(
// Title
title: Text("Home Page"),
// App Bar background color
backgroundColor: Colors.red,
),
// Body
body: Container(
// Center the content
child: Center(
child: Column(
// Center content in the column
mainAxisAlignment: MainAxisAlignment.center,
// add children to the column
children: <Widget>[
// Text
Text(
"Home Page\nClick on below icon to goto About Page",
// Setting the style for the Text
style: TextStyle(fontSize: 20.0,),
// Set text alignment to center
textAlign: TextAlign.center,
),
// Icon Button
IconButton(
icon: Icon(
Icons.info,
color: Colors.blue,
),
// Execute when pressed
onPressed: () {
// use the navigator to goto a named route
Navigator.of(context).pushNamed('/about');
},
// Setting the size of icon
iconSize: 80.0,
)
],
),
),
),
);
}
}
| 0 |
mirrored_repositories/flutter-examples/handling_routes/android | mirrored_repositories/flutter-examples/handling_routes/android/lib/main.dart | import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
// This makes the visual density adapt to the platform that you run
// the app on. For desktop platforms, the controls will be smaller and
// closer together (more dense) than on mobile platforms.
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
| 0 |
mirrored_repositories/flutter-examples/handling_routes/android | mirrored_repositories/flutter-examples/handling_routes/android/test/widget_test.dart | // This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:android/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(MyApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}
| 0 |
mirrored_repositories/flutter-examples/tic_tac_toe | mirrored_repositories/flutter-examples/tic_tac_toe/lib/main.dart | import 'package:flutter/material.dart';
import 'package:sizer/sizer.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return Sizer(builder: (context, orientation, deviceType) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
home: HomePage(),
);
});
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
// declarations
bool oTurn = true;
// 1st player is O
List<String> displayElement = ['', '', '', '', '', '', '', '', ''];
int oScore = 0;
int xScore = 0;
int filledBoxes = 0;
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
backgroundColor: Colors.indigo[900],
body: Column(
children: <Widget>[
SingleChildScrollView(
child: SizedBox(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(30.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Player X',
style: TextStyle(
fontSize: 20.sp,
fontWeight: FontWeight.bold,
color: Colors.white),
),
SizedBox(height: 5.h),
Text(
xScore.toString(),
style:
TextStyle(fontSize: 20.sp, color: Colors.white),
),
],
),
),
Padding(
padding: const EdgeInsets.all(30.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Player 0',
style: TextStyle(
fontSize: 20.sp,
fontWeight: FontWeight.bold,
color: Colors.white),
),
SizedBox(height: 5.h),
Text(
oScore.toString(),
style:
TextStyle(fontSize: 20.sp, color: Colors.white),
),
],
),
),
],
),
),
),
const Spacer(),
/////////////////////////////////
Expanded(
flex: 4,
child: GridView.builder(
itemCount: 9,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3),
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onTap: () {
_tapped(index);
},
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.white),
boxShadow: const [
BoxShadow(
blurRadius: 25.0,
),
],
),
child: Container(
color: Colors.white,
child: Center(
child: Text(
displayElement[index],
style: TextStyle(
color: displayElement[index] == 'O'
? Colors.red
: Colors.green,
fontSize: 35.sp,
),
),
),
),
),
),
);
},
),
),
Expanded(
// Button for Clearing the Enter board
// as well as Scoreboard to start allover again
child: SizedBox(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.redAccent,
foregroundColor: Colors.white,
),
onPressed: _clearScoreBoard,
child: const Text("Clear Score Board"),
),
],
),
),
),
],
),
),
);
}
/////////////////////////////functions
// filling the boxes when tapped with X
// or O respectively and then checking the winner function
void _tapped(int index) {
setState(() {
if (oTurn && displayElement[index] == '') {
displayElement[index] = 'O';
filledBoxes++;
} else if (!oTurn && displayElement[index] == '') {
displayElement[index] = 'X';
filledBoxes++;
}
oTurn = !oTurn;
_checkWinner();
});
}
void _checkWinner() {
// Checking rows
if (displayElement[0] == displayElement[1] &&
displayElement[0] == displayElement[2] &&
displayElement[0] != '') {
// _showWinDialog(displayElement[0]);
showWinSnackBar(displayElement[0]);
}
if (displayElement[3] == displayElement[4] &&
displayElement[3] == displayElement[5] &&
displayElement[3] != '') {
showWinSnackBar(displayElement[3]);
}
if (displayElement[6] == displayElement[7] &&
displayElement[6] == displayElement[8] &&
displayElement[6] != '') {
showWinSnackBar(displayElement[6]);
}
// Checking Column
if (displayElement[0] == displayElement[3] &&
displayElement[0] == displayElement[6] &&
displayElement[0] != '') {
showWinSnackBar(displayElement[0]);
}
if (displayElement[1] == displayElement[4] &&
displayElement[1] == displayElement[7] &&
displayElement[1] != '') {
showWinSnackBar(displayElement[1]);
}
if (displayElement[2] == displayElement[5] &&
displayElement[2] == displayElement[8] &&
displayElement[2] != '') {
showWinSnackBar(displayElement[2]);
}
// Checking Diagonal
if (displayElement[0] == displayElement[4] &&
displayElement[0] == displayElement[8] &&
displayElement[0] != '') {
showWinSnackBar(displayElement[0]);
}
if (displayElement[2] == displayElement[4] &&
displayElement[2] == displayElement[6] &&
displayElement[2] != '') {
showWinSnackBar(displayElement[2]);
} else if (filledBoxes == 9) {
showDrawSnackBar();
}
}
void showWinSnackBar(String winner) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
duration: const Duration(seconds: 20),
content: Container(
margin: const EdgeInsets.fromLTRB(0, 0, 0, 75),
decoration: BoxDecoration(
border: Border.all(width: 2.0, color: Colors.black),
borderRadius: BorderRadius.circular(20)),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"\" $winner \" is Winner!!!",
style: const TextStyle(fontSize: 25),
),
),
),
backgroundColor: Colors.black,
elevation: 1000,
behavior: SnackBarBehavior.floating,
action: SnackBarAction(
label: 'Play again',
onPressed: () {
_clearBoard();
},
),
),
);
if (winner == 'O') {
oScore++;
} else if (winner == 'X') {
xScore++;
}
}
void showDrawSnackBar() {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
duration: const Duration(seconds: 20),
content: Container(
margin: const EdgeInsets.fromLTRB(0, 0, 0, 75),
decoration: BoxDecoration(
border: Border.all(width: 2.0, color: Colors.black),
borderRadius: BorderRadius.circular(20)),
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
"Draw",
style: TextStyle(fontSize: 25),
),
),
),
backgroundColor: Colors.black,
elevation: 1000,
behavior: SnackBarBehavior.floating,
action: SnackBarAction(
label: 'Play again',
onPressed: () {
_clearBoard();
},
),
),
);
}
void _clearBoard() {
setState(() {
for (int i = 0; i < 9; i++) {
displayElement[i] = '';
}
});
filledBoxes = 0;
}
void _clearScoreBoard() {
setState(() {
xScore = 0;
oScore = 0;
for (int i = 0; i < 9; i++) {
displayElement[i] = '';
}
});
filledBoxes = 0;
}
}
| 0 |
mirrored_repositories/flutter-examples/using_interactiveviewer | mirrored_repositories/flutter-examples/using_interactiveviewer/lib/main.dart | import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: Text("Using InteractiveViewer"),
),
body: InteractiveViewer(
boundaryMargin: EdgeInsets.all(100.0),
minScale: 0.1,
maxScale: 1.6,
child: Center(
child: FlutterLogo(
size: 90,
),
),
),
),
);
}
}
| 0 |
mirrored_repositories/flutter-examples/using_interactiveviewer | mirrored_repositories/flutter-examples/using_interactiveviewer/test/widget_test.dart | // This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:using_interactiveviewer/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(MyApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}
| 0 |
mirrored_repositories/flutter-examples/using_gradient | mirrored_repositories/flutter-examples/using_gradient/lib/utils.dart | import 'package:flutter/material.dart';
LinearGradient getCustomGradient() {
// Define a Linear Gradient
return LinearGradient(
colors: [Colors.pink, Colors.blueAccent],
begin: const FractionalOffset(0.0, 0.0),
end: const FractionalOffset(0.6, 0.0),
stops: [0.0, 0.6],
tileMode: TileMode.clamp);
}
| 0 |
mirrored_repositories/flutter-examples/using_gradient | mirrored_repositories/flutter-examples/using_gradient/lib/main.dart | import 'package:flutter/material.dart';
import './utils.dart' as utils;
void main() {
runApp(MaterialApp(
// Title
title: "Using Gradient",
// Home
home: Scaffold(
// Appbar
appBar: AppBar(
// Title
title: Text("Using Gradient"),
),
// Body
body: Container(
// Center the content
child: Center(
// Add Text
child: Text(
"Hello World!",
style: TextStyle(color: Colors.white),
),
),
// Set background
decoration: BoxDecoration(
// Add Gradient
gradient: utils.getCustomGradient())))));
}
| 0 |
mirrored_repositories/flutter-examples/using_gradient/android | mirrored_repositories/flutter-examples/using_gradient/android/lib/main.dart | import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
// This makes the visual density adapt to the platform that you run
// the app on. For desktop platforms, the controls will be smaller and
// closer together (more dense) than on mobile platforms.
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
| 0 |
mirrored_repositories/flutter-examples/using_gradient/android | mirrored_repositories/flutter-examples/using_gradient/android/test/widget_test.dart | // This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:android/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(MyApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}
| 0 |
mirrored_repositories/flutter-examples/push_notifcations | mirrored_repositories/flutter-examples/push_notifcations/lib/main.dart | import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Push Notification demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String title = "Title will appear here";
String messageData = "Message text will appear here";
FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
@override
void initState() {
super.initState();
/*
Message that we are getting from firebase will be of form:-
{
notification:{
title:'Custom Title that we send from firebase cloud messaging',
body:'Text of the message will appear here'
},
data:{
Here the extra data like if we include image,etc optional data from firebase cloud messaging
}
}
For sending Push notification go to Grow and then cloud messaging, from there send new message by adding title
and other fields as per requirement
*/
// In Ios we need to request permission for sending Push notifcations but not in Android
_firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(
sound: true, badge: true, alert: true, provisional: true));
_firebaseMessaging.configure(onMessage: (message) async {
setState(() {
print(message);
title = message["notification"]["title"];
messageData = message["notification"]["body"];
notification(context, title, messageData);
});
}, onResume: (message) async {
setState(() {
print(message);
title = message["notification"]["title"];
messageData = message["notification"]["body"];
notification(context, title, messageData);
});
}, onLaunch: (message) async {
setState(() {
print(message);
title = message["notification"]["title"];
messageData = message["notification"]["body"];
notification(context, title, messageData);
});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Push Notification Demo'),
backgroundColor: Colors.green,
centerTitle: true,
),
body: Center(
child: Padding(
padding: const EdgeInsets.only(top: 30.0),
child: Column(
children: <Widget>[
Text(
'$title',
style: Theme.of(context).textTheme.headline4,
),
SizedBox(height: 20.0,),
Text(
messageData,
style: Theme.of(context).textTheme.headline6,
),
],
),
),
),
);
}
// this function will be called when a push notification is recieved and show as alert dialog along with
// title and message body
Future notification(
BuildContext context, String title, String messageText) async {
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
buttonPadding: EdgeInsets.all(10.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0)),
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20.0),
),
SizedBox(
height: 15.0,
),
Text(
messageText,
style: TextStyle(fontSize: 16.0),
)
],
),
actions: [
FlatButton(
onPressed: () => Navigator.pop(context), child: Text('Ok'))
],
);
});
}
}
| 0 |
mirrored_repositories/flutter-examples/push_notifcations | mirrored_repositories/flutter-examples/push_notifcations/test/widget_test.dart | // This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:push_notifcations/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(MyApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}
| 0 |
mirrored_repositories/flutter-examples/firebase_google_authentication | mirrored_repositories/flutter-examples/firebase_google_authentication/lib/main.dart | import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_google_authentication/Screens/HomePage.dart';
import 'package:firebase_google_authentication/Services/google_auth.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
void main() async{
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (context) => GoogleSignInProvider(),
child: MaterialApp(
debugShowCheckedModeBanner: false,
home: HomePage(),
),
);
}
}
| 0 |
mirrored_repositories/flutter-examples/firebase_google_authentication/lib | mirrored_repositories/flutter-examples/firebase_google_authentication/lib/Screens/InfoPage.dart | import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_google_authentication/Services/google_auth.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class InfoPage extends StatefulWidget {
const InfoPage({Key? key}) : super(key: key);
@override
_InfoPageState createState() => _InfoPageState();
}
class _InfoPageState extends State<InfoPage> {
@override
Widget build(BuildContext context) {
User? user = FirebaseAuth.instance.currentUser;
return SafeArea(
child: Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
FlatButton(onPressed: (){
final provider = Provider.of<GoogleSignInProvider>(
context,
listen: false);
provider.googleLogout();
},
child: Text('Logout',
style: TextStyle(
color: Colors.blue,
fontSize: 16,
),
)),
],
),
SizedBox(height: 200,),
Column(
mainAxisAlignment: MainAxisAlignment.center,
//crossAxisAlignment: CrossAxisAlignment.center,
children: [
CircleAvatar(
radius: 40,
backgroundImage: NetworkImage(
user!.photoURL??'https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_1280.png'
),
),
SizedBox(height: 15,),
Text(user!.email??'',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500
),
),
],
)
],
),
),
);
}
}
| 0 |
mirrored_repositories/flutter-examples/firebase_google_authentication/lib | mirrored_repositories/flutter-examples/firebase_google_authentication/lib/Screens/HomePage.dart |
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_google_authentication/Screens/InfoPage.dart';
import 'package:firebase_google_authentication/Screens/SignUpPage.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:google_fonts/google_fonts.dart';
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
final Size size = MediaQuery.of(context).size;
return Scaffold(
body: StreamBuilder(
stream: FirebaseAuth.instance.authStateChanges(),
builder: (context, snapshot) {
if(snapshot.connectionState ==ConnectionState.waiting){
return Center(child: CircularProgressIndicator(),);
}
else if(snapshot.hasError){
return Center(child: Text('An error Occured!!'),);
}else if(snapshot.hasData){
return InfoPage();
}else {
return home(size, context);
}
}
),
);
}
Column home(Size size, BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Welcome!',
style: GoogleFonts.lora(
fontSize: 36,
fontWeight: FontWeight.w500,
),
),
SizedBox(height: 30,),
SvgPicture.asset(
'assets/login.svg',
width: size.width*0.8,
height: size.height*0.3,
),
SizedBox(height: 60,),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: size.width*0.8,
child: ClipRRect(
borderRadius: BorderRadius.circular(29),
child: FlatButton(
padding: EdgeInsets.symmetric(vertical: 15,horizontal: 40),
onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context)=>SignUpPage(true)));
},
child: Text('Login',
style: GoogleFonts.alice(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 20
),
),
color: Color(0xFF6F35A5),
),
),
),
],
),
SizedBox(height: 15,),
Container(
width: size.width*0.8,
child: ClipRRect(
borderRadius: BorderRadius.circular(29),
child: FlatButton(
padding: EdgeInsets.symmetric(vertical: 15,horizontal: 40),
onPressed: (){
Navigator.push(context,
MaterialPageRoute(builder: (context)=> SignUpPage(false))
);
},
child: Text('SignUp',
style: GoogleFonts.alice(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 20
),
),
color: Color(0xFFF1E6FF),
),
),
),
],
);
}
}
| 0 |
mirrored_repositories/flutter-examples/firebase_google_authentication/lib | mirrored_repositories/flutter-examples/firebase_google_authentication/lib/Screens/SignUpPage.dart | import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_google_authentication/Services/google_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:provider/provider.dart';
class SignUpPage extends StatefulWidget {
//const SignUpPage({Key? key}) : super(key: key);
bool isLogin;
SignUpPage(this.isLogin);
@override
_SignUpPageState createState() => _SignUpPageState(isLogin);
}
class _SignUpPageState extends State<SignUpPage> {
bool isLogin;
_SignUpPageState(this.isLogin);
bool loggingIn = false;
TextEditingController email = new TextEditingController();
TextEditingController password = new TextEditingController();
bool showPassword = false;
void showSnackBar() {
final snackBar = new SnackBar(
content: Text('Invalid Credentials!'),
backgroundColor: Colors.red,
padding: EdgeInsets.symmetric(horizontal: 10),
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(14),
),
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
@override
Widget build(BuildContext context) {
final Size size = MediaQuery.of(context).size;
return Scaffold(
body: SingleChildScrollView(
child: Container(
height: size.height,
width: double.infinity,
child: Stack(
alignment: Alignment.center,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
(isLogin)?'Login':'SignUp',
style: GoogleFonts.alice(
fontWeight: FontWeight.bold,
fontSize: 29,
),
),
SizedBox(
height: 20,
),
SvgPicture.asset(
(isLogin)?'assets/signup.svg':'assets/signup.svg',
width: size.width * 0.5,
height: size.height * 0.3,
),
SizedBox(
height: 25,
),
Padding(
padding: const EdgeInsets.only(left: 30, right: 30),
child: TextField(
controller: email,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(29),
),
hintText: 'Your Email',
filled: true,
fillColor: Color(0xFFF1E6FF),
prefixIcon: Icon(
Icons.person,
color: Color(0xFF6F35A5),
),
),
),
),
SizedBox(
height: 15,
),
Padding(
padding: const EdgeInsets.only(left: 30, right: 30),
child: TextField(
controller: password,
obscureText: !showPassword,
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(29),
),
hintText: 'Password',
filled: true,
fillColor: Color(0xFFF1E6FF),
prefixIcon: Icon(
Icons.lock,
color: Color(0xFF6F35A5),
),
suffixIcon: showPassword
? IconButton(
icon: Icon(
Icons.visibility_off,
color: Color(0xFF6F35A5),
),
onPressed: () {
setState(() {
showPassword = !showPassword;
});
},
)
: IconButton(
icon: Icon(
Icons.visibility,
color: Color(0xFF6F35A5),
),
onPressed: () {
setState(() {
showPassword = !showPassword;
});
},
)),
),
),
SizedBox(
height: 30,
),
Container(
width: size.width * 0.8,
child: ClipRRect(
borderRadius: BorderRadius.circular(29),
child: FlatButton(
padding:
EdgeInsets.symmetric(vertical: 15, horizontal: 40),
onPressed: () {
String _email = email.text;
String _password = password.text;
!(isLogin)?
signUpClicked(_email, _password, context):
loginClicked(_email, _password, context);
},
child: Text(
(isLogin)?'Login':'SignUp',
style: GoogleFonts.alata(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 20),
),
color: Color(0xFF6F35A5),
),
),
),
SizedBox(
height: 18,
),
Container(
width: size.width * 0.81,
child: ClipRRect(
borderRadius: BorderRadius.circular(29),
child: FlatButton.icon(
padding:
EdgeInsets.symmetric(vertical: 15, horizontal: 40),
onPressed: () {
final provider = Provider.of<GoogleSignInProvider>(
context,
listen: false);
provider.googleLogin().then((value) {
Navigator.popUntil(
context, (route) => route.isFirst);
}).catchError((onError) {
showSnackBar();
});
},
icon: FaIcon(
FontAwesomeIcons.google,
color: Colors.white,
),
label: Text(
(isLogin)?'Login with Google':'SignUp with Google',
style: GoogleFonts.alata(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 20),
),
color: Color(0xFF6F35A5),
),
),
),
SizedBox(
height: 20,
),
GestureDetector(
onTap: (){
setState(() {
isLogin = !isLogin;
});
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
(isLogin)?'Don\'t have an account?':'Already have an account?',
style: GoogleFonts.lato(
color: Color(0xFF6F35A5),
),
),
Text(
(isLogin)?'SignUp':'SignIn',
style: GoogleFonts.lato(
fontWeight: FontWeight.bold,
color: Color(0xFF6F35A5),
),
),
],
),
)
],
)
],
),
),
),
);
}
signUpClicked(String _email, String _password, BuildContext context) {
FirebaseAuth.instance
.createUserWithEmailAndPassword(
email: _email, password: _password)
.then((value) {
setState(() {
loggingIn = true;
});
Future.delayed(
Duration(seconds: 1, milliseconds: 50), (){
Navigator.popUntil(
context, (route) => route.isFirst);
});
}).catchError((e) {
showSnackBar();
});
}
bool loginClicked(String _email, String _password, BuildContext context) {
FirebaseAuth.instance.signInWithEmailAndPassword(
email: _email, password: _password).then((value){
setState(() {
loggingIn = true;
});
Future.delayed(Duration(seconds: 1,milliseconds: 50),(){
Navigator.pop(context);
});
}).catchError((e){
showSnackBar();
});
return loggingIn;
}
}
| 0 |
mirrored_repositories/flutter-examples/firebase_google_authentication/lib | mirrored_repositories/flutter-examples/firebase_google_authentication/lib/Services/google_auth.dart | import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart';
import 'package:google_sign_in/google_sign_in.dart';
class GoogleSignInProvider extends ChangeNotifier{
final googleSignIn = GoogleSignIn();
GoogleSignInAccount? _user;
User? user1;
GoogleSignInAccount get user => _user!;
String? userId;
FirebaseAuth auth = FirebaseAuth.instance;
Future googleLogin()async{
try{
final googleUser = await googleSignIn.signIn();
if(googleUser == null) return;
_user = googleUser;
final googleAuth = await googleUser.authentication;
final credentials = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
final UserCredential authresult= await FirebaseAuth.instance.signInWithCredential(credentials);
notifyListeners();
}catch(e){
print(e.toString());
}
}
Future googleLogout()async{
try{
print('Logging Out');
await googleSignIn.disconnect();
FirebaseAuth.instance.signOut();
}catch(e){
FirebaseAuth.instance.signOut();
}
notifyListeners();
}
} | 0 |
mirrored_repositories/flutter-examples/dropdown_button | mirrored_repositories/flutter-examples/dropdown_button/lib/main.dart | import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return MyAppState();
}
}
class MyAppState extends State<MyApp> {
List _fruits = ["Apple", "Banana", "Pineapple", "Mango", "Grapes"];
List<DropdownMenuItem<String>> _dropDownMenuItems;
String _selectedFruit;
@override
void initState() {
_dropDownMenuItems = buildAndGetDropDownMenuItems(_fruits);
_selectedFruit = _dropDownMenuItems[0].value;
super.initState();
}
List<DropdownMenuItem<String>> buildAndGetDropDownMenuItems(List fruits) {
List<DropdownMenuItem<String>> items = List();
for (String fruit in fruits) {
items.add(DropdownMenuItem(value: fruit, child: Text(fruit)));
}
return items;
}
void changedDropDownItem(String selectedFruit) {
setState(() {
_selectedFruit = selectedFruit;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: Text("DropDown Button Example"),
),
body: Container(
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("Please choose a fruit: "),
DropdownButton(
value: _selectedFruit,
items: _dropDownMenuItems,
onChanged: changedDropDownItem,
)
],
)),
),
),
);
}
}
| 0 |
mirrored_repositories/flutter-examples/dropdown_button/android | mirrored_repositories/flutter-examples/dropdown_button/android/lib/main.dart | import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
// This makes the visual density adapt to the platform that you run
// the app on. For desktop platforms, the controls will be smaller and
// closer together (more dense) than on mobile platforms.
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
| 0 |
mirrored_repositories/flutter-examples/dropdown_button/android | mirrored_repositories/flutter-examples/dropdown_button/android/test/widget_test.dart | // This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:android/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(MyApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}
| 0 |
mirrored_repositories/flutter-examples/using_theme | mirrored_repositories/flutter-examples/using_theme/lib/main.dart | import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: MyHome(),
// Set the theme's primary color, accent color,
theme: ThemeData(
primarySwatch: Colors.green,
accentColor: Colors.lightGreenAccent,
// Set background color
backgroundColor: Colors.black12,
),
));
}
class MyHome extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
// AppBar
appBar: AppBar(
// AppBar Title
title: Text("Using Theme"),
),
body: Container(
// Another way to set the background color
decoration: BoxDecoration(color: Colors.black87),
child: Center(
child: Container(
// use the theme accent color as background color for this widget
color: Theme.of(context).accentColor,
child: Text(
'Hello World!',
// Set text style as per theme
style: Theme.of(context).textTheme.title,
),
),
),
),
floatingActionButton: Theme(
// override the accent color of theme for this widget only
data: Theme.of(context).copyWith(
colorScheme:
Theme.of(context).colorScheme.copyWith(secondary: Colors.pinkAccent),
),
child: FloatingActionButton(
onPressed: null,
child: Icon(Icons.add),
),
),
);
}
}
| 0 |
mirrored_repositories/flutter-examples/using_theme/android | mirrored_repositories/flutter-examples/using_theme/android/lib/main.dart | import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
// This makes the visual density adapt to the platform that you run
// the app on. For desktop platforms, the controls will be smaller and
// closer together (more dense) than on mobile platforms.
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
| 0 |
mirrored_repositories/flutter-examples/using_theme/android | mirrored_repositories/flutter-examples/using_theme/android/test/widget_test.dart | // This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:android/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(MyApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}
| 0 |
mirrored_repositories/flutter-examples/todo_list_using_provider | mirrored_repositories/flutter-examples/todo_list_using_provider/lib/main.dart | import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'notifiers/todo_list.dart';
import 'views/home.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: ChangeNotifierProvider<TodoList>(
create: (context) => TodoList(),
child: MyHomePage(title: 'Flutter Demo Home Page'),
),
);
}
} | 0 |
mirrored_repositories/flutter-examples/todo_list_using_provider/lib | mirrored_repositories/flutter-examples/todo_list_using_provider/lib/views/home.dart | import 'package:flutter/material.dart';
import '../widgets/todo_list_wdt.dart';
import '../widgets/add_button.dart';
class MyHomePage extends StatelessWidget {
final String title;
const MyHomePage({Key key, this.title}) : super(key: key);
@override
Widget build(BuildContext context) {
print('rebuilding Home View');
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Center(
child: TodoListWdt(),
),
floatingActionButton: AddButton(),
);
}
} | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.