From b843ea49d6b5f2adf5da8a72888d449e4f3c5990 Mon Sep 17 00:00:00 2001 From: munna7407 Date: Wed, 30 Jul 2025 21:15:53 +0600 Subject: [PATCH] Create free income MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit free income করুন --- free income | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 free income diff --git a/free income b/free income new file mode 100644 index 0000000..9dff821 --- /dev/null +++ b/free income @@ -0,0 +1,192 @@ +import 'package:flutter/material.dart'; +import 'package:firebase_core/firebase_core.dart'; +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:firebase_auth/firebase_auth.dart'; + +void main() async { + WidgetsFlutterBinding.ensureInitialized(); + await Firebase.initializeApp(); + runApp(VideoIncomeApp()); +} + +class VideoIncomeApp extends StatelessWidget { + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Video Income', + theme: ThemeData(primarySwatch: Colors.green), + home: AuthWrapper(), + ); + } +} + +class AuthWrapper extends StatelessWidget { + @override + Widget build(BuildContext context) { + return StreamBuilder( + stream: FirebaseAuth.instance.authStateChanges(), + builder: (context, snapshot) { + if (snapshot.hasData) return HomePage(); + return LoginPage(); + }, + ); + } +} + +class LoginPage extends StatefulWidget { + @override + State createState() => _LoginPageState(); +} + +class _LoginPageState extends State { + final phoneController = TextEditingController(); + String verificationId = ''; + bool codeSent = false; + final otpController = TextEditingController(); + + void sendOtp() async { + await FirebaseAuth.instance.verifyPhoneNumber( + phoneNumber: '+88${phoneController.text}', + verificationCompleted: (cred) async { + await FirebaseAuth.instance.signInWithCredential(cred); + }, + verificationFailed: (e) { + ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Failed: ${e.message}'))); + }, + codeSent: (id, resendToken) { + setState(() { + verificationId = id; + codeSent = true; + }); + }, + codeAutoRetrievalTimeout: (id) {}, + ); + } + + void verifyOtp() async { + final credential = PhoneAuthProvider.credential( + verificationId: verificationId, + smsCode: otpController.text, + ); + try { + await FirebaseAuth.instance.signInWithCredential(credential); + } catch (e) { + ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Invalid OTP'))); + } + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(title: Text('Login')), + body: Padding( + padding: EdgeInsets.all(16), + child: Column( + children: [ + if (!codeSent) + TextField( + controller: phoneController, + keyboardType: TextInputType.phone, + decoration: InputDecoration(labelText: 'Phone Number (without +88)'), + ), + if (codeSent) + TextField( + controller: otpController, + keyboardType: TextInputType.number, + decoration: InputDecoration(labelText: 'OTP'), + ), + SizedBox(height: 20), + ElevatedButton( + onPressed: codeSent ? verifyOtp : sendOtp, + child: Text(codeSent ? 'Verify OTP' : 'Send OTP'), + ) + ], + ), + ), + ); + } +} + +class HomePage extends StatefulWidget { + @override + State createState() => _HomePageState(); +} + +class _HomePageState extends State { + int points = 0; + String userId = FirebaseAuth.instance.currentUser!.uid; + + @override + void initState() { + super.initState(); + loadPoints(); + } + + void loadPoints() async { + final doc = await FirebaseFirestore.instance.collection('users').doc(userId).get(); + if (doc.exists) { + setState(() { + points = doc.data()?['points'] ?? 0; + }); + } else { + await FirebaseFirestore.instance.collection('users').doc(userId).set({'points': 0}); + } + } + + void watchVideo() async { + setState(() { + points += 2; + }); + await FirebaseFirestore.instance.collection('users').doc(userId).update({'points': points}); + } + + void withdraw() async { + if (points >= 20) { + // Create a withdraw request + await FirebaseFirestore.instance.collection('withdraws').add({ + 'userId': userId, + 'points': 20, + 'status': 'pending', + 'timestamp': DateTime.now(), + 'phone': FirebaseAuth.instance.currentUser!.phoneNumber, + }); + + setState(() { + points -= 20; + }); + await FirebaseFirestore.instance.collection('users').doc(userId).update({'points': points}); + + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Withdraw request sent! Admin will process it soon.')), + ); + } else { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('You need at least 20 points to withdraw.')), + ); + } + } + + void logout() async { + await FirebaseAuth.instance.signOut(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text('Video Income'), + actions: [ + IconButton(onPressed: logout, icon: Icon(Icons.logout)), + ], + ), + body: Center( + child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [ + Text('Your points: $points', style: TextStyle(fontSize: 24)), + SizedBox(height: 20), + ElevatedButton(onPressed: watchVideo, child: Text('Watch Video (+2 points)')), + ElevatedButton(onPressed: withdraw, child: Text('Withdraw (20 points = 20 BDT)')), + ]), + ), + ); + } +}