mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2026-08-24 16:50:47 +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:
106
analytics_integration/lib/example.dart
Normal file
106
analytics_integration/lib/example.dart
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
// Example: Analytics tracking with Firebase Analytics showing a list of items
|
||||||
|
import 'package:analytics_integration/single_item_tile.dart';
|
||||||
|
import 'package:firebase_analytics/firebase_analytics.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class Example extends StatefulWidget {
|
||||||
|
const Example({super.key});
|
||||||
|
|
||||||
|
/// create instance of FirebaseAnalytics as [analytics]
|
||||||
|
static FirebaseAnalytics analytics = FirebaseAnalytics.instance;
|
||||||
|
|
||||||
|
/// create observer for FirebaseAnalytics as [observer]
|
||||||
|
/// this observer sends events to Firebase Analytics when the
|
||||||
|
/// currently active route changes.
|
||||||
|
static FirebaseAnalyticsObserver observer =
|
||||||
|
FirebaseAnalyticsObserver(analytics: analytics);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_ExampleState createState() => _ExampleState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ExampleState extends State<Example> {
|
||||||
|
late FirebaseAnalytics _analytics;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
/// initializing data to local variable [_analytics] for Firebase Analytics
|
||||||
|
/// that we made before for local use
|
||||||
|
_analytics = Example.analytics;
|
||||||
|
//// below three events are related to user which we are
|
||||||
|
//// sending to Firebase Analytics
|
||||||
|
_setUserIdInAnalytics();
|
||||||
|
_setUserPropertyInAnalytics();
|
||||||
|
_currentScreen();
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Center(
|
||||||
|
child: Text('Flutter Analytics'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
body: Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: ListView(
|
||||||
|
shrinkWrap: true,
|
||||||
|
children: <Widget>[
|
||||||
|
SizedBox(
|
||||||
|
height: 16,
|
||||||
|
),
|
||||||
|
SingleItemTile(
|
||||||
|
itemName: 'Carrot',
|
||||||
|
analytics: _analytics,
|
||||||
|
quantity: 1,
|
||||||
|
price: '100Rs',
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: 16,
|
||||||
|
),
|
||||||
|
SingleItemTile(
|
||||||
|
itemName: 'Baby Carrot',
|
||||||
|
analytics: _analytics,
|
||||||
|
quantity: .5,
|
||||||
|
price: '50Rs',
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: 16,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//// to create a unique user identifier for Analytics
|
||||||
|
//// send user id(if you app has)
|
||||||
|
Future<void> _setUserIdInAnalytics() async {
|
||||||
|
await _analytics.setUserId(id: 'alksj39hnfn49skvnghqwp40sm');
|
||||||
|
}
|
||||||
|
|
||||||
|
//// sending user related field to Analytics
|
||||||
|
/// below [name] is the name of the user property to set
|
||||||
|
/// [value] is the values of that property
|
||||||
|
Future<void> _setUserPropertyInAnalytics() async {
|
||||||
|
await _analytics.setUserProperty(
|
||||||
|
name: 'email',
|
||||||
|
value: 'johndoe@gmail.com',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Setting the current Screen of the app in [screenName]
|
||||||
|
/// and sending back to Analytics
|
||||||
|
Future<void> _currentScreen() async {
|
||||||
|
await _analytics.logEvent(
|
||||||
|
name: 'screen_view',
|
||||||
|
parameters: <String, Object>{
|
||||||
|
'screen_name': 'FlutterAnalyticsHome',
|
||||||
|
'screen_class': 'FlutterAnalyticsHome',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import 'package:analytics_integration/single_item_tile.dart';
|
import 'package:analytics_integration/example.dart';
|
||||||
import 'package:firebase_analytics/firebase_analytics.dart';
|
|
||||||
import 'package:firebase_core/firebase_core.dart';
|
import 'package:firebase_core/firebase_core.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
@@ -8,19 +7,10 @@ void main() async {
|
|||||||
|
|
||||||
/// initialize your firebase project
|
/// initialize your firebase project
|
||||||
await Firebase.initializeApp();
|
await Firebase.initializeApp();
|
||||||
runApp(FlutterAnalyticsApp());
|
runApp(const FlutterAnalyticsApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
class FlutterAnalyticsApp extends StatelessWidget {
|
class FlutterAnalyticsApp extends StatelessWidget {
|
||||||
/// create instance of FirebaseAnalytics as [analytics]
|
|
||||||
static FirebaseAnalytics analytics = FirebaseAnalytics.instance;
|
|
||||||
|
|
||||||
/// create observer for FirebaseAnalytics as [observer]
|
|
||||||
/// this observer sends events to Firebase Analytics when the
|
|
||||||
/// currently active route changes.
|
|
||||||
static FirebaseAnalyticsObserver observer =
|
|
||||||
FirebaseAnalyticsObserver(analytics: analytics);
|
|
||||||
|
|
||||||
const FlutterAnalyticsApp({super.key});
|
const FlutterAnalyticsApp({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -35,114 +25,8 @@ class FlutterAnalyticsApp extends StatelessWidget {
|
|||||||
|
|
||||||
/// this is used to observe navigation changes in the app
|
/// this is used to observe navigation changes in the app
|
||||||
/// and sending data back to Firebase Analytics
|
/// and sending data back to Firebase Analytics
|
||||||
navigatorObservers: <NavigatorObserver>[observer],
|
navigatorObservers: <NavigatorObserver>[Example.observer],
|
||||||
home: FlutterAnalyticsHome(
|
home: const Example(),
|
||||||
title: 'Flutter Analytics',
|
|
||||||
analytics: analytics,
|
|
||||||
observer: observer,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class FlutterAnalyticsHome extends StatefulWidget {
|
|
||||||
final String title;
|
|
||||||
final FirebaseAnalytics analytics;
|
|
||||||
final FirebaseAnalyticsObserver observer;
|
|
||||||
|
|
||||||
const FlutterAnalyticsHome({
|
|
||||||
super.key,
|
|
||||||
required this.title,
|
|
||||||
required this.analytics,
|
|
||||||
required this.observer,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
_FlutterAnalyticsHomeState createState() => _FlutterAnalyticsHomeState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _FlutterAnalyticsHomeState extends State<FlutterAnalyticsHome> {
|
|
||||||
late FirebaseAnalytics _analytics;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
/// initializing data to local variable [_analytics] for Firebase Analytics
|
|
||||||
/// that we made before for local use
|
|
||||||
_analytics = widget.analytics;
|
|
||||||
//// below three events are related to user which we are
|
|
||||||
//// sending to Firebase Analytics
|
|
||||||
_setUserIdInAnalytics();
|
|
||||||
_setUserPropertyInAnalytics();
|
|
||||||
_currentScreen();
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: Colors.white,
|
|
||||||
appBar: AppBar(
|
|
||||||
title: Center(
|
|
||||||
child: Text(widget.title),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
body: Padding(
|
|
||||||
padding: const EdgeInsets.all(16.0),
|
|
||||||
child: ListView(
|
|
||||||
shrinkWrap: true,
|
|
||||||
children: <Widget>[
|
|
||||||
SizedBox(
|
|
||||||
height: 16,
|
|
||||||
),
|
|
||||||
SingleItemTile(
|
|
||||||
itemName: 'Carrot',
|
|
||||||
analytics: _analytics,
|
|
||||||
quantity: 1,
|
|
||||||
price: '100Rs',
|
|
||||||
),
|
|
||||||
SizedBox(
|
|
||||||
height: 16,
|
|
||||||
),
|
|
||||||
SingleItemTile(
|
|
||||||
itemName: 'Baby Carrot',
|
|
||||||
analytics: _analytics,
|
|
||||||
quantity: .5,
|
|
||||||
price: '50Rs',
|
|
||||||
),
|
|
||||||
SizedBox(
|
|
||||||
height: 16,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//// to create a unique user identifier for Analytics
|
|
||||||
//// send user id(if you app has)
|
|
||||||
Future<void> _setUserIdInAnalytics() async {
|
|
||||||
await _analytics.setUserId(id: 'alksj39hnfn49skvnghqwp40sm');
|
|
||||||
}
|
|
||||||
|
|
||||||
//// sending user related field to Analytics
|
|
||||||
/// below [name] is the name of the user property to set
|
|
||||||
/// [value] is the values of that property
|
|
||||||
Future<void> _setUserPropertyInAnalytics() async {
|
|
||||||
await _analytics.setUserProperty(
|
|
||||||
name: 'email',
|
|
||||||
value: 'johndoe@gmail.com',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Setting the current Screen of the app in [screenName]
|
|
||||||
/// and sending back to Analytics
|
|
||||||
Future<void> _currentScreen() async {
|
|
||||||
await _analytics.logEvent(
|
|
||||||
name: 'screen_view',
|
|
||||||
parameters: <String, Object>{
|
|
||||||
'screen_name': 'FlutterAnalyticsHome',
|
|
||||||
'screen_class': 'FlutterAnalyticsHome',
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
|
// Example: A compass-like animation demo where tapping rotates a pen image
|
||||||
|
// and points it toward a direction (north/west/south/east).
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class HomePage extends StatefulWidget {
|
class Example extends StatefulWidget {
|
||||||
const HomePage({super.key});
|
const Example({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_HomePageState createState() => _HomePageState();
|
_ExampleState createState() => _ExampleState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _HomePageState extends State<HomePage>
|
class _ExampleState extends State<Example> with SingleTickerProviderStateMixin {
|
||||||
with SingleTickerProviderStateMixin {
|
|
||||||
late AnimationController controller;
|
late AnimationController controller;
|
||||||
var target = 0.0;
|
var target = 0.0;
|
||||||
final Map<double, String> data = {
|
final Map<double, String> data = {
|
||||||
@@ -54,8 +55,7 @@ class _HomePageState extends State<HomePage>
|
|||||||
child: TextButton(
|
child: TextButton(
|
||||||
onPressed: () {},
|
onPressed: () {},
|
||||||
style: ButtonStyle(
|
style: ButtonStyle(
|
||||||
backgroundColor:
|
backgroundColor: WidgetStateProperty.all(Colors.green)),
|
||||||
WidgetStateProperty.all(Colors.green)),
|
|
||||||
child: const Text(
|
child: const Text(
|
||||||
"North",
|
"North",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
@@ -104,8 +104,7 @@ class _HomePageState extends State<HomePage>
|
|||||||
child: TextButton(
|
child: TextButton(
|
||||||
onPressed: () {},
|
onPressed: () {},
|
||||||
style: ButtonStyle(
|
style: ButtonStyle(
|
||||||
backgroundColor:
|
backgroundColor: WidgetStateProperty.all(Colors.green)),
|
||||||
WidgetStateProperty.all(Colors.green)),
|
|
||||||
child: const Text(
|
child: const Text(
|
||||||
"North",
|
"North",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'home_page.dart';
|
import 'example.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
@@ -15,10 +15,9 @@ class MyApp extends StatelessWidget {
|
|||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: 'Pen Assignement',
|
title: 'Pen Assignement',
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
|
|
||||||
primarySwatch: Colors.blue,
|
primarySwatch: Colors.blue,
|
||||||
),
|
),
|
||||||
home:HomePage(),
|
home: const Example(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
88
biometrics/lib/example.dart
Normal file
88
biometrics/lib/example.dart
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
// Example: Biometric verification screen
|
||||||
|
import 'package:biometrics/biometrics_verifier.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class Example extends StatefulWidget {
|
||||||
|
const Example({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<Example> createState() => _ExampleState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ExampleState extends State<Example> {
|
||||||
|
late bool isVerified;
|
||||||
|
|
||||||
|
late BiometricsVerifier verifier;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
isVerified = false;
|
||||||
|
verifier = BiometricsVerifier();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(),
|
||||||
|
body: SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
isVerified ? 'Verification Complete' : 'Unverified',
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
isVerified
|
||||||
|
? TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
isVerified = false;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: const Text('Unverify'),
|
||||||
|
)
|
||||||
|
: TextButton(
|
||||||
|
onPressed: () async {
|
||||||
|
try {
|
||||||
|
await verifier
|
||||||
|
.verifyBiometrics('Please enter your fingerprint');
|
||||||
|
// ---- Add your logic after finger print verification here
|
||||||
|
// ---
|
||||||
|
// ---
|
||||||
|
setState(() {
|
||||||
|
isVerified = true;
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
// ---- Verification Failed
|
||||||
|
if (!context.mounted) return;
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (c) => AlertDialog(
|
||||||
|
title: const Text('Error !'),
|
||||||
|
content: Text(e.toString()),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
child: const Text('Ok'),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: const Text('Verify with Fingerprint'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import 'package:biometrics/biometrics_verifier.dart';
|
import 'package:biometrics/example.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
void main() => runApp(Biometrics());
|
void main() => runApp(const Biometrics());
|
||||||
|
|
||||||
class Biometrics extends StatelessWidget {
|
class Biometrics extends StatelessWidget {
|
||||||
const Biometrics({super.key});
|
const Biometrics({super.key});
|
||||||
@@ -13,92 +13,7 @@ class Biometrics extends StatelessWidget {
|
|||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
appBarTheme: const AppBarTheme(elevation: 0),
|
appBarTheme: const AppBarTheme(elevation: 0),
|
||||||
),
|
),
|
||||||
home: Home(),
|
home: const Example(),
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Home extends StatefulWidget {
|
|
||||||
const Home({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<Home> createState() => _HomeState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _HomeState extends State<Home> {
|
|
||||||
late bool isVerified;
|
|
||||||
|
|
||||||
late BiometricsVerifier verifier;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
isVerified = false;
|
|
||||||
verifier = BiometricsVerifier();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(),
|
|
||||||
body: SizedBox(
|
|
||||||
width: double.infinity,
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
isVerified ? 'Verification Complete' : 'Unverified',
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 10),
|
|
||||||
isVerified
|
|
||||||
? TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
isVerified = false;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
child: const Text('Unverify'),
|
|
||||||
)
|
|
||||||
: TextButton(
|
|
||||||
onPressed: () async {
|
|
||||||
try {
|
|
||||||
await verifier
|
|
||||||
.verifyBiometrics('Please enter your fingerprint');
|
|
||||||
// ---- Add your logic after finger print verification here
|
|
||||||
// ---
|
|
||||||
// ---
|
|
||||||
setState(() {
|
|
||||||
isVerified = true;
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
// ---- Verification Failed
|
|
||||||
if (!context.mounted) return;
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (c) => AlertDialog(
|
|
||||||
title: const Text('Error !'),
|
|
||||||
content: Text(e.toString()),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
},
|
|
||||||
child: const Text('Ok'),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: const Text('Verify with Fingerprint'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
12
bottom_sheet/lib/example.dart
Normal file
12
bottom_sheet/lib/example.dart
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
// Example: Bottom sheet
|
||||||
|
import 'package:bottom_sheet/home.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class Example extends StatelessWidget {
|
||||||
|
const Example({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return const MyHomePage(title: 'Bottom Sheet');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
|
import 'package:bottom_sheet/example.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:bottom_sheet/home.dart';
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(MyApp());
|
runApp(const MyApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
@@ -17,8 +17,7 @@ class MyApp extends StatelessWidget {
|
|||||||
primarySwatch: Colors.red,
|
primarySwatch: Colors.red,
|
||||||
visualDensity: VisualDensity.adaptivePlatformDensity,
|
visualDensity: VisualDensity.adaptivePlatformDensity,
|
||||||
),
|
),
|
||||||
home: MyHomePage(title: 'Bottom Sheet'),
|
home: const Example(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
custom_home_drawer/lib/example.dart
Normal file
12
custom_home_drawer/lib/example.dart
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
// Example: Custom home drawer
|
||||||
|
import 'package:custom_home_drawer/screen/home_screen.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class Example extends StatelessWidget {
|
||||||
|
const Example({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return const HomeScreen();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import 'package:custom_home_drawer/screen/home_screen.dart';
|
import 'package:custom_home_drawer/example.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
@@ -15,7 +15,7 @@ class MyApp extends StatelessWidget {
|
|||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
primarySwatch: Colors.blue,
|
primarySwatch: Colors.blue,
|
||||||
),
|
),
|
||||||
home: const HomeScreen(),
|
home: const Example(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
76
google_signin/lib/example.dart
Normal file
76
google_signin/lib/example.dart
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
// Example: Sign in to Google and display the signed-in user's profile.
|
||||||
|
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';
|
||||||
|
|
||||||
|
class Example extends StatefulWidget {
|
||||||
|
const Example({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
ExampleState createState() => ExampleState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class ExampleState extends State<Example> {
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return userPage;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,81 +1,18 @@
|
|||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:firebase_auth/firebase_auth.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:google_sign_in/google_sign_in.dart';
|
|
||||||
|
|
||||||
import 'home.dart';
|
import 'example.dart';
|
||||||
import 'user.dart';
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const App());
|
runApp(const MyApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
class App extends StatefulWidget {
|
class MyApp extends StatelessWidget {
|
||||||
const App({super.key});
|
const MyApp({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");
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
home: userPage,
|
home: const Example(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
22
grid_layout/lib/example.dart
Normal file
22
grid_layout/lib/example.dart
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
// Example: A grid layout displaying social network icons in a 2-column grid.
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'gridview.dart';
|
||||||
|
|
||||||
|
class Example extends StatelessWidget {
|
||||||
|
Example({super.key});
|
||||||
|
|
||||||
|
final MyGridView myGridView = MyGridView();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
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("GridView Example"),
|
||||||
|
),
|
||||||
|
body: myGridView.build(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,25 +1,17 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:grid_layout/gridview.dart';
|
|
||||||
|
import 'example.dart';
|
||||||
|
|
||||||
void main() => runApp(MyApp());
|
void main() => runApp(MyApp());
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
final MyGridView myGridView = MyGridView();
|
const MyApp({super.key});
|
||||||
|
|
||||||
MyApp({super.key});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
home: Scaffold(
|
home: Example(),
|
||||||
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("GridView Example"),
|
|
||||||
),
|
|
||||||
body: myGridView.build(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
// Example: A home screen with navigation to an About page via named routes.
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class HomePage extends StatelessWidget {
|
class Example extends StatelessWidget {
|
||||||
const HomePage({super.key});
|
const Example({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -26,7 +27,9 @@ class HomePage extends StatelessWidget {
|
|||||||
Text(
|
Text(
|
||||||
"Home Page\nClick on below icon to goto About Page",
|
"Home Page\nClick on below icon to goto About Page",
|
||||||
// Setting the style for the Text
|
// Setting the style for the Text
|
||||||
style: TextStyle(fontSize: 20.0,),
|
style: TextStyle(
|
||||||
|
fontSize: 20.0,
|
||||||
|
),
|
||||||
// Set text alignment to center
|
// Set text alignment to center
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:handling_routes/screens/about.dart';
|
import 'package:handling_routes/screens/about.dart';
|
||||||
import 'package:handling_routes/screens/home.dart';
|
|
||||||
|
import 'example.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(MaterialApp(
|
runApp(MaterialApp(
|
||||||
home: HomePage(), // home has implicit route set at '/'
|
home: const Example(), // home has implicit route set at '/'
|
||||||
// Setup routes
|
// Setup routes
|
||||||
routes: <String, WidgetBuilder>{
|
routes: <String, WidgetBuilder>{
|
||||||
// Set named routes
|
// Set named routes
|
||||||
|
|||||||
129
image_editor/lib/example.dart
Normal file
129
image_editor/lib/example.dart
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
// Example: Image editor screen
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:image_editor/ApplyFilters.dart';
|
||||||
|
import 'package:image_editor/EditImg.dart';
|
||||||
|
import 'package:image_editor/GetImg.dart';
|
||||||
|
import 'package:image_editor/SaveInGallery.dart';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
class Example extends StatefulWidget {
|
||||||
|
const Example({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_ExampleState createState() => _ExampleState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ExampleState extends State<Example> {
|
||||||
|
bool _selected = false; //to check if a image is selected or not
|
||||||
|
late File
|
||||||
|
_image; //here we will store the selected image and apply modifications
|
||||||
|
final double _ImageContainerHeight = 450;
|
||||||
|
final double _ImageContainerWidth = 400;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
backgroundColor: Colors.greenAccent[400],
|
||||||
|
title: Text('Flutter Image Editor'),
|
||||||
|
),
|
||||||
|
body: Container(
|
||||||
|
child: Column(
|
||||||
|
children: <Widget>[
|
||||||
|
SizedBox(
|
||||||
|
height: _ImageContainerHeight,
|
||||||
|
width: _ImageContainerWidth,
|
||||||
|
child: _selected // checks if a image is selected or not
|
||||||
|
? Image.file(_image)
|
||||||
|
: Image.asset('images/cam.png')),
|
||||||
|
Row(
|
||||||
|
children: <Widget>[
|
||||||
|
Spacer(
|
||||||
|
flex: 2,
|
||||||
|
),
|
||||||
|
ElevatedButton(
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: Colors.greenAccent[400]),
|
||||||
|
child: Text(
|
||||||
|
'Get_Image', // to select a image from gallery
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
onPressed: () async {
|
||||||
|
var Ifile = await GetiImg(
|
||||||
|
_image); // function called from GetImg.dart
|
||||||
|
if (Ifile != null) {
|
||||||
|
setState(() {
|
||||||
|
_image = Ifile;
|
||||||
|
_selected = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
Spacer(
|
||||||
|
flex: 1,
|
||||||
|
),
|
||||||
|
ElevatedButton(
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: Colors.greenAccent[400]),
|
||||||
|
child: Text(
|
||||||
|
'Edit Image', //to start editing the shape, size, etc of the selected image
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
onPressed: () async {
|
||||||
|
var Ifile0 = await EditImg(
|
||||||
|
_image); // function called from EditImg.dart
|
||||||
|
if (Ifile0 != null) {
|
||||||
|
setState(() {
|
||||||
|
_image = Ifile0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
Spacer(
|
||||||
|
flex: 2,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
children: <Widget>[
|
||||||
|
Spacer(
|
||||||
|
flex: 2,
|
||||||
|
),
|
||||||
|
ElevatedButton(
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: Colors.greenAccent[400]),
|
||||||
|
child: Text(
|
||||||
|
'Apply Filters', //to start apply various photo filters to the selected image
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
onPressed: () async {
|
||||||
|
var Ifile0 = await ApplyFilters(context,
|
||||||
|
_image); // function called from ApplyFilters.dart
|
||||||
|
if (Ifile0 != null) {
|
||||||
|
setState(() {
|
||||||
|
_image = Ifile0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
Spacer(
|
||||||
|
flex: 1,
|
||||||
|
),
|
||||||
|
ElevatedButton(
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: Colors.greenAccent[400]),
|
||||||
|
child: Text(
|
||||||
|
'Download Editted image', //to save the edited image to gallery
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
onPressed: () async {
|
||||||
|
await SaveImg(
|
||||||
|
_image); // function called from SaveInGallery.dart
|
||||||
|
}),
|
||||||
|
Spacer(
|
||||||
|
flex: 2,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:image_editor/HomePage.dart';
|
import 'package:image_editor/example.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(MyApp());
|
runApp(const MyApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
@@ -11,10 +11,8 @@ class MyApp extends StatelessWidget {
|
|||||||
// This widget is the root of your application.
|
// This widget is the root of your application.
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return const MaterialApp(
|
||||||
home: HomePage()
|
home: Example(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
80
scan_qr_code/lib/example.dart
Normal file
80
scan_qr_code/lib/example.dart
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
// Example: Scan QR code
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:mobile_scanner/mobile_scanner.dart';
|
||||||
|
import 'package:scan_qr_code/utils/qr_code_scanner.dart';
|
||||||
|
import 'package:scan_qr_code/utils/scanner_box_border_painter.dart';
|
||||||
|
|
||||||
|
class Example extends StatefulWidget {
|
||||||
|
const Example({super.key, this.title = 'Code Scanner Demo'});
|
||||||
|
|
||||||
|
final String title;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<Example> createState() => _ExampleState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ExampleState extends State<Example> {
|
||||||
|
final MobileScannerController _mobileScannerController =
|
||||||
|
MobileScannerController();
|
||||||
|
late void Function(BarcodeCapture) _onDetect;
|
||||||
|
bool _isScanning = true;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_onDetect = (BarcodeCapture capture) {
|
||||||
|
_mobileScannerController.stop();
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Code info'),
|
||||||
|
content: Text(
|
||||||
|
capture.barcodes.first.rawValue?.trim() ?? 'No data found',
|
||||||
|
textAlign: TextAlign.center),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
child: const Text('OK'))
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}).then((value) {
|
||||||
|
_mobileScannerController.start();
|
||||||
|
setState(() {
|
||||||
|
_isScanning = true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_isScanning = false;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(title: Text(widget.title)),
|
||||||
|
body: Center(
|
||||||
|
child: SizedBox.square(
|
||||||
|
dimension: MediaQuery.of(context).size.width - 48.0,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(
|
||||||
|
2.5), // Required otherwise side edges hides under outside padding
|
||||||
|
child: CustomPaint(
|
||||||
|
foregroundPainter: ScannerBoxBorderPainter(
|
||||||
|
borderColor: _isScanning ? Colors.black : Colors.green),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(
|
||||||
|
2.5), // Required otherwise scanner hides under side edges
|
||||||
|
child: QRCodeScanner(
|
||||||
|
mobileScannerController: _mobileScannerController,
|
||||||
|
onDetect: _onDetect),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,5 @@
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:mobile_scanner/mobile_scanner.dart';
|
import 'package:scan_qr_code/example.dart';
|
||||||
import 'package:scan_qr_code/utils/qr_code_scanner.dart';
|
|
||||||
import 'package:scan_qr_code/utils/scanner_box_border_painter.dart';
|
|
||||||
|
|
||||||
void main() => runApp(const MyApp());
|
void main() => runApp(const MyApp());
|
||||||
|
|
||||||
@@ -13,82 +10,7 @@ class MyApp extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return const MaterialApp(
|
return const MaterialApp(
|
||||||
title: 'Code Scanner',
|
title: 'Code Scanner',
|
||||||
home: MyHomePage(title: 'Code Scanner Demo'),
|
home: Example(),
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyHomePage extends StatefulWidget {
|
|
||||||
const MyHomePage({super.key, required this.title});
|
|
||||||
|
|
||||||
final String title;
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<MyHomePage> createState() => _MyHomePageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _MyHomePageState extends State<MyHomePage> {
|
|
||||||
final MobileScannerController _mobileScannerController =
|
|
||||||
MobileScannerController();
|
|
||||||
late void Function(BarcodeCapture) _onDetect;
|
|
||||||
bool _isScanning = true;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_onDetect = (BarcodeCapture capture) {
|
|
||||||
_mobileScannerController.stop();
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (BuildContext context) {
|
|
||||||
return AlertDialog(
|
|
||||||
title: const Text('Code info'),
|
|
||||||
content: Text(
|
|
||||||
capture.barcodes.first.rawValue?.trim() ?? 'No data found',
|
|
||||||
textAlign: TextAlign.center),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.pop(context),
|
|
||||||
child: const Text('OK'))
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}).then((value) {
|
|
||||||
_mobileScannerController.start();
|
|
||||||
setState(() {
|
|
||||||
_isScanning = true;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
setState(() {
|
|
||||||
_isScanning = false;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(title: Text(widget.title)),
|
|
||||||
body: Center(
|
|
||||||
child: SizedBox.square(
|
|
||||||
dimension: MediaQuery.of(context).size.width - 48.0,
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(
|
|
||||||
2.5), // Required otherwise side edges hides under outside padding
|
|
||||||
child: CustomPaint(
|
|
||||||
foregroundPainter: ScannerBoxBorderPainter(
|
|
||||||
borderColor: _isScanning ? Colors.black : Colors.green),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(
|
|
||||||
2.5), // Required otherwise scanner hides under side edges
|
|
||||||
child: QRCodeScanner(
|
|
||||||
mobileScannerController: _mobileScannerController,
|
|
||||||
onDetect: _onDetect),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
42
statless_counter_app/lib/example.dart
Normal file
42
statless_counter_app/lib/example.dart
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
// Example: Stateless widget counter using MobX
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||||
|
|
||||||
|
import 'counter.dart'; // Import the Counter
|
||||||
|
|
||||||
|
final counter = Counter(); // Instantiate the store
|
||||||
|
|
||||||
|
class Example extends StatelessWidget {
|
||||||
|
const Example({super.key});
|
||||||
|
|
||||||
|
@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.headlineSmall,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
floatingActionButton: FloatingActionButton(
|
||||||
|
onPressed: counter.increment,
|
||||||
|
tooltip: 'Increment',
|
||||||
|
child: Icon(Icons.add),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,8 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
|
||||||
|
|
||||||
import 'counter.dart'; // Import the Counter
|
import 'example.dart';
|
||||||
|
|
||||||
final counter = Counter(); // Instantiate the store
|
void main() => runApp(const MyApp());
|
||||||
|
|
||||||
void main() => runApp(MyApp());
|
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
const MyApp({super.key});
|
const MyApp({super.key});
|
||||||
@@ -19,42 +16,7 @@ class MyApp extends StatelessWidget {
|
|||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
primarySwatch: Colors.blue,
|
primarySwatch: Colors.blue,
|
||||||
),
|
),
|
||||||
home: const MyHomePage(),
|
home: const Example(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyHomePage extends StatelessWidget {
|
|
||||||
const MyHomePage({super.key});
|
|
||||||
|
|
||||||
@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.headlineSmall,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
floatingActionButton: FloatingActionButton(
|
|
||||||
onPressed: counter.increment,
|
|
||||||
tooltip: 'Increment',
|
|
||||||
child: Icon(Icons.add),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
75
using_bottom_nav_bar/lib/example.dart
Normal file
75
using_bottom_nav_bar/lib/example.dart
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
// Example: Using bottom navigation bar with tabs
|
||||||
|
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';
|
||||||
|
|
||||||
|
class Example extends StatefulWidget {
|
||||||
|
const Example({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
ExampleState createState() => ExampleState();
|
||||||
|
}
|
||||||
|
|
||||||
|
// SingleTickerProviderStateMixin is used for animation
|
||||||
|
class ExampleState extends State<Example> with SingleTickerProviderStateMixin {
|
||||||
|
// Create a tab controller
|
||||||
|
late 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
|
||||||
|
controller: controller,
|
||||||
|
// Add tabs as widgets
|
||||||
|
children: <Widget>[FirstTab(), SecondTab(), ThirdTab()],
|
||||||
|
),
|
||||||
|
// 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,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,82 +1,20 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:using_bottom_nav_bar/tabs/first.dart';
|
import 'package:using_bottom_nav_bar/example.dart';
|
||||||
import 'package:using_bottom_nav_bar/tabs/second.dart';
|
|
||||||
import 'package:using_bottom_nav_bar/tabs/third.dart';
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(MaterialApp(
|
runApp(const MyApp());
|
||||||
// Title
|
|
||||||
title: "Using Tabs",
|
|
||||||
// Home
|
|
||||||
home: MyHome()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyHome extends StatefulWidget {
|
class MyApp extends StatelessWidget {
|
||||||
const MyHome({super.key});
|
const MyApp({super.key});
|
||||||
|
|
||||||
@override
|
|
||||||
MyHomeState createState() => MyHomeState();
|
|
||||||
}
|
|
||||||
|
|
||||||
// SingleTickerProviderStateMixin is used for animation
|
|
||||||
class MyHomeState extends State<MyHome> with SingleTickerProviderStateMixin {
|
|
||||||
// Create a tab controller
|
|
||||||
late 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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return MaterialApp(
|
||||||
// Appbar
|
// Title
|
||||||
appBar: AppBar(
|
title: "Using Tabs",
|
||||||
// Title
|
// Home
|
||||||
title: Text("Using Bottom Navigation Bar"),
|
home: const Example(),
|
||||||
// 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
|
|
||||||
controller: controller,
|
|
||||||
// Add tabs as widgets
|
|
||||||
children: <Widget>[FirstTab(), SecondTab(), ThirdTab()],
|
|
||||||
),
|
|
||||||
// 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,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
31
using_custom_fonts/lib/example.dart
Normal file
31
using_custom_fonts/lib/example.dart
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
// Example: Displays text using a custom font loaded from the app's assets.
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import './utils.dart' as utils;
|
||||||
|
|
||||||
|
class Example extends StatelessWidget {
|
||||||
|
const Example({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
// Appbar
|
||||||
|
appBar: AppBar(
|
||||||
|
// Title
|
||||||
|
title: Text("Using Custom Fonts"),
|
||||||
|
),
|
||||||
|
// Body
|
||||||
|
body: Container(
|
||||||
|
// Center the content
|
||||||
|
child: Center(
|
||||||
|
// Add Text
|
||||||
|
child: Text("The quick brown fox jumps over the lazy dog",
|
||||||
|
// Center align text
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
// set a text style which defines a custom font
|
||||||
|
style: utils.getCustomFontTextStyle()),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,29 +1,12 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import './utils.dart' as utils;
|
import 'example.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(MaterialApp(
|
runApp(MaterialApp(
|
||||||
// Title
|
// Title
|
||||||
title: "Using Custom Fonts",
|
title: "Using Custom Fonts",
|
||||||
// Home
|
// Home
|
||||||
home: Scaffold(
|
home: const Example(),
|
||||||
// Appbar
|
));
|
||||||
appBar: AppBar(
|
|
||||||
// Title
|
|
||||||
title: Text("Using Custom Fonts"),
|
|
||||||
),
|
|
||||||
// Body
|
|
||||||
body: Container(
|
|
||||||
// Center the content
|
|
||||||
child: Center(
|
|
||||||
// Add Text
|
|
||||||
child: Text("The quick brown fox jumps over the lazy dog",
|
|
||||||
// Center align text
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
// set a text style which defines a custom font
|
|
||||||
style: utils.getCustomFontTextStyle()),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|||||||
17
using_listview/lib/example.dart
Normal file
17
using_listview/lib/example.dart
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
// Example: A scrollable list of contacts with avatar, name, and email.
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:using_listview/contact_page.dart';
|
||||||
|
|
||||||
|
class Example extends StatelessWidget {
|
||||||
|
const Example({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text("Using Listview"),
|
||||||
|
),
|
||||||
|
body: const ContactPage(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,10 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:using_listview/contact_page.dart';
|
|
||||||
|
import 'example.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(MaterialApp(
|
runApp(MaterialApp(
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
home: Scaffold(
|
home: const Example(),
|
||||||
appBar: AppBar(
|
|
||||||
title: Text("Using Listview"),
|
|
||||||
),
|
|
||||||
body: ContactPage(),
|
|
||||||
),
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
12
using_listwheelscrollview/lib/example.dart
Normal file
12
using_listwheelscrollview/lib/example.dart
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
// Example: List wheel scroll view
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'listwheel.dart';
|
||||||
|
|
||||||
|
class Example extends StatelessWidget {
|
||||||
|
const Example({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return const Listwheel();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,21 +1,21 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'listwheel.dart';
|
import 'example.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(MyApp());
|
runApp(const MyApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
const MyApp({super.key});
|
const MyApp({super.key});
|
||||||
|
|
||||||
// This widget is the root of your application.
|
// This widget is the root of your application.
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
theme: ThemeData.dark().copyWith(
|
theme: ThemeData.dark().copyWith(
|
||||||
scaffoldBackgroundColor: Color(0XFF0A0E21),
|
scaffoldBackgroundColor: Color(0XFF0A0E21),
|
||||||
),
|
),
|
||||||
home: Listwheel(),
|
home: const Example(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
123
using_platform_adaptive/lib/example.dart
Normal file
123
using_platform_adaptive/lib/example.dart
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
// Example: Platform adaptive widgets
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:using_platform_adaptive/common_widgets/adaptive_button.dart';
|
||||||
|
import 'package:using_platform_adaptive/common_widgets/adaptive_date_picker.dart';
|
||||||
|
import 'package:using_platform_adaptive/common_widgets/adaptive_indicator.dart';
|
||||||
|
|
||||||
|
class Example extends StatefulWidget {
|
||||||
|
const Example({super.key, this.title = 'Using Platform Adaptive'});
|
||||||
|
final String title;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<Example> createState() => _ExampleState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ExampleState extends State<Example> {
|
||||||
|
TargetPlatform? selectedPlatform;
|
||||||
|
final String introText = "Flutter's flagship feature is it's ability to write"
|
||||||
|
" code once and have it run on multiple devices. While this is great, sometimes"
|
||||||
|
" you want the user interface to look more native to its platform. This project"
|
||||||
|
" showcases the Platform Adaptive pattern, a powerful pattern that allows you"
|
||||||
|
" to create widgets that you write once and look natural on any device. The"
|
||||||
|
" demo is just set up to work on android and iOS but can be extended to work"
|
||||||
|
" on web, native and any other platform flutter supports.";
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final platforms = {
|
||||||
|
"Default": null,
|
||||||
|
"Android": TargetPlatform.android,
|
||||||
|
"iOS": TargetPlatform.iOS,
|
||||||
|
};
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text(widget.title),
|
||||||
|
),
|
||||||
|
body: Container(
|
||||||
|
padding: const EdgeInsets.all(30),
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: <Widget>[
|
||||||
|
Text(introText),
|
||||||
|
const SizedBox(height: 30),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
const Text("Force a platform: "),
|
||||||
|
DropdownButton(
|
||||||
|
value: selectedPlatform,
|
||||||
|
items: List<DropdownMenuItem>.from(platforms.entries.map(
|
||||||
|
(e) => DropdownMenuItem(
|
||||||
|
value: e.value, child: Text(e.key)))),
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
selectedPlatform = value;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
const Text("Buttons: "),
|
||||||
|
AdaptiveButton(
|
||||||
|
forcePlatform: selectedPlatform,
|
||||||
|
color: Colors.teal,
|
||||||
|
onPressed: () {},
|
||||||
|
child: const Text("I'm a button"),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
const Text("Dialogs: "),
|
||||||
|
AdaptiveButton(
|
||||||
|
forcePlatform: selectedPlatform,
|
||||||
|
color: Colors.teal,
|
||||||
|
onPressed: () {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return AdaptiveDialog(
|
||||||
|
title: "Test",
|
||||||
|
content: const Text("This is the content area"),
|
||||||
|
actions: [
|
||||||
|
AdaptiveDialogAction(
|
||||||
|
text: "Action 1",
|
||||||
|
forcePlatform: selectedPlatform,
|
||||||
|
onPressed: () {},
|
||||||
|
),
|
||||||
|
AdaptiveDialogAction(
|
||||||
|
text: "Action 2",
|
||||||
|
forcePlatform: selectedPlatform,
|
||||||
|
onPressed: () {},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
forcePlatform: selectedPlatform,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: const Text("Show"),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
const Text("Loading Indicator: "),
|
||||||
|
AdaptiveIndicator(
|
||||||
|
forcePlatform: selectedPlatform,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:using_platform_adaptive/common_widgets/adaptive_button.dart';
|
import 'package:using_platform_adaptive/example.dart';
|
||||||
import 'package:using_platform_adaptive/common_widgets/adaptive_date_picker.dart';
|
|
||||||
import 'package:using_platform_adaptive/common_widgets/adaptive_indicator.dart';
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
@@ -18,125 +16,7 @@ class MyApp extends StatelessWidget {
|
|||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
primarySwatch: Colors.teal,
|
primarySwatch: Colors.teal,
|
||||||
),
|
),
|
||||||
home: const MyHomePage(title: 'Using Platform Adaptive'),
|
home: const Example(),
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyHomePage extends StatefulWidget {
|
|
||||||
const MyHomePage({super.key, required this.title});
|
|
||||||
final String title;
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<MyHomePage> createState() => _MyHomePageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _MyHomePageState extends State<MyHomePage> {
|
|
||||||
TargetPlatform? selectedPlatform;
|
|
||||||
final String introText = "Flutter's flagship feature is it's ability to write"
|
|
||||||
" code once and have it run on multiple devices. While this is great, sometimes"
|
|
||||||
" you want the user interface to look more native to its platform. This project"
|
|
||||||
" showcases the Platform Adaptive pattern, a powerful pattern that allows you"
|
|
||||||
" to create widgets that you write once and look natural on any device. The"
|
|
||||||
" demo is just set up to work on android and iOS but can be extended to work"
|
|
||||||
" on web, native and any other platform flutter supports.";
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final platforms = {
|
|
||||||
"Default": null,
|
|
||||||
"Android": TargetPlatform.android,
|
|
||||||
"iOS": TargetPlatform.iOS,
|
|
||||||
};
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: Colors.white,
|
|
||||||
appBar: AppBar(
|
|
||||||
title: Text(widget.title),
|
|
||||||
),
|
|
||||||
body: Container(
|
|
||||||
padding: const EdgeInsets.all(30),
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
|
||||||
children: <Widget>[
|
|
||||||
Text(introText),
|
|
||||||
const SizedBox(height: 30),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
const Text("Force a platform: "),
|
|
||||||
DropdownButton(
|
|
||||||
value: selectedPlatform,
|
|
||||||
items: List<DropdownMenuItem>.from(platforms.entries.map(
|
|
||||||
(e) => DropdownMenuItem(
|
|
||||||
value: e.value, child: Text(e.key)))),
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() {
|
|
||||||
selectedPlatform = value;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
const Text("Buttons: "),
|
|
||||||
AdaptiveButton(
|
|
||||||
forcePlatform: selectedPlatform,
|
|
||||||
color: Colors.teal,
|
|
||||||
onPressed: () {},
|
|
||||||
child: const Text("I'm a button"),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 10),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
const Text("Dialogs: "),
|
|
||||||
AdaptiveButton(
|
|
||||||
forcePlatform: selectedPlatform,
|
|
||||||
color: Colors.teal,
|
|
||||||
onPressed: () {
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (context) {
|
|
||||||
return AdaptiveDialog(
|
|
||||||
title: "Test",
|
|
||||||
content: const Text("This is the content area"),
|
|
||||||
actions: [
|
|
||||||
AdaptiveDialogAction(
|
|
||||||
text: "Action 1",
|
|
||||||
forcePlatform: selectedPlatform,
|
|
||||||
onPressed: () {},
|
|
||||||
),
|
|
||||||
AdaptiveDialogAction(
|
|
||||||
text: "Action 2",
|
|
||||||
forcePlatform: selectedPlatform,
|
|
||||||
onPressed: () {},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
forcePlatform: selectedPlatform,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
child: const Text("Show"),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 10),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
const Text("Loading Indicator: "),
|
|
||||||
AdaptiveIndicator(
|
|
||||||
forcePlatform: selectedPlatform,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
84
view_pdf_file/lib/example.dart
Normal file
84
view_pdf_file/lib/example.dart
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
// Example: View PDF file
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
|
||||||
|
import 'package:view_pdf_file/constants.dart';
|
||||||
|
import 'package:view_pdf_file/viewPDF.dart';
|
||||||
|
|
||||||
|
class Example extends StatefulWidget {
|
||||||
|
const Example({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
ExampleState createState() => ExampleState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class ExampleState extends State<Example> {
|
||||||
|
bool isLoading = false;
|
||||||
|
late Widget pdfViewer;
|
||||||
|
|
||||||
|
@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: [
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
loadFromAsset();
|
||||||
|
},
|
||||||
|
child: Text("Load local PDF"),
|
||||||
|
),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
loadFromURL();
|
||||||
|
},
|
||||||
|
child: Text("Load PDF via URL"),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> loadFromAsset() async {
|
||||||
|
setState(() {
|
||||||
|
isLoading = true;
|
||||||
|
});
|
||||||
|
pdfViewer = SfPdfViewer.asset('assets/Hello.pdf');
|
||||||
|
setState(() {
|
||||||
|
isLoading = false;
|
||||||
|
});
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (_) => ViewPDF(viewer: pdfViewer),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> loadFromURL() async {
|
||||||
|
setState(() {
|
||||||
|
isLoading = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
pdfViewer = SfPdfViewer.network(Constants.pdfURL);
|
||||||
|
setState(() {
|
||||||
|
isLoading = false;
|
||||||
|
});
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (_) => ViewPDF(viewer: pdfViewer),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
|
import 'package:view_pdf_file/example.dart';
|
||||||
import 'package:view_pdf_file/constants.dart';
|
|
||||||
import 'package:view_pdf_file/viewPDF.dart';
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(MyApp());
|
runApp(const MyApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
@@ -18,85 +16,6 @@ class MyApp extends StatelessWidget {
|
|||||||
primarySwatch: Colors.blue,
|
primarySwatch: Colors.blue,
|
||||||
visualDensity: VisualDensity.adaptivePlatformDensity,
|
visualDensity: VisualDensity.adaptivePlatformDensity,
|
||||||
),
|
),
|
||||||
home: HomePage());
|
home: const Example());
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class HomePage extends StatefulWidget {
|
|
||||||
const HomePage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
_HomePageState createState() => _HomePageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _HomePageState extends State<HomePage> {
|
|
||||||
bool isLoading = false;
|
|
||||||
late Widget pdfViewer;
|
|
||||||
|
|
||||||
@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: [
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () {
|
|
||||||
loadFromAsset();
|
|
||||||
},
|
|
||||||
child: Text("Load local PDF"),
|
|
||||||
),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () {
|
|
||||||
loadFromURL();
|
|
||||||
},
|
|
||||||
child: Text("Load PDF via URL"),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> loadFromAsset() async {
|
|
||||||
setState(() {
|
|
||||||
isLoading = true;
|
|
||||||
});
|
|
||||||
pdfViewer = SfPdfViewer.asset('assets/Hello.pdf');
|
|
||||||
setState(() {
|
|
||||||
isLoading = false;
|
|
||||||
});
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (_) => ViewPDF(viewer: pdfViewer),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> loadFromURL() async {
|
|
||||||
setState(() {
|
|
||||||
isLoading = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
pdfViewer = SfPdfViewer.network(Constants.pdfURL);
|
|
||||||
setState(() {
|
|
||||||
isLoading = false;
|
|
||||||
});
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (_) => ViewPDF(viewer: pdfViewer),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user