1
0
mirror of https://github.com/nisrulz/flutter-examples.git synced 2026-08-25 01:05:36 +00:00

refactor: split app wrapper from focused example code (multi-file apps)

Convert 17 multi-file apps to the validated pattern: lib/main.dart keeps
only the MaterialApp bootstrap; a new lib/example.dart holds the full entry
screen and focused example code, importing existing supporting files
(screens/, tabs/, services/, models/, widgets/, utils/).

Apps: analytics_integration, animation_example, biometrics, bottom_sheet,
custom_home_drawer, google_signin, grid_layout, handling_routes,
image_editor, scan_qr_code, statless_counter_app, using_bottom_nav_bar,
using_custom_fonts, using_listview, using_listwheelscrollview,
using_platform_adaptive, view_pdf_file
This commit is contained in:
Nishant Srivastava
2026-08-18 00:48:50 +02:00
parent 780c0f1dbb
commit 6e3ff94bfe
34 changed files with 1002 additions and 766 deletions

View File

@@ -1,81 +1,18 @@
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';
import 'example.dart';
void main() {
runApp(const App());
runApp(const MyApp());
}
class App extends StatefulWidget {
const App({super.key});
@override
AppState createState() => AppState();
}
class AppState extends State<App> {
final GoogleSignIn googleSignIn = GoogleSignIn.instance;
late Widget userPage;
@override
void initState() {
super.initState();
userPage = Home(
onSignin: _signin,
onLogout: _logout,
showLoading: false,
);
}
Future<User?> _signin() async {
setState(() {
userPage = Home(onSignin: null, onLogout: _logout, showLoading: true);
});
try {
await googleSignIn.initialize();
final GoogleSignInAccount account = await googleSignIn.authenticate();
final GoogleSignInAuthentication auth = account.authentication;
final AuthCredential credential = GoogleAuthProvider.credential(
idToken: auth.idToken,
);
final UserCredential authRes =
await FirebaseAuth.instance.signInWithCredential(credential);
final User? user = authRes.user;
if (user == null) return null;
setState(() {
userPage = UserProfile(onLogout: _logout, user: user);
});
return user;
} catch (e) {
print(e.toString());
return null;
}
}
Future<void> _logout() async {
await googleSignIn.signOut();
setState(() {
userPage = Home(
onSignin: _signin,
onLogout: _logout,
showLoading: false,
);
});
print("Logged Out");
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: userPage,
home: const Example(),
);
}
}